@@ -68,7 +68,7 @@ def test_opencv_conversion(self):
68
68
return correct projections of random 3D points. The check is done
69
69
against a set of results precomuted using `cv2.projectPoints` function.
70
70
"""
71
-
71
+ device = torch . device ( "cuda:0" )
72
72
image_size = [[480 , 640 ]] * 4
73
73
R = [
74
74
[
@@ -116,17 +116,19 @@ def test_opencv_conversion(self):
116
116
]
117
117
118
118
principal_point , focal_length , R , tvec , image_size = [
119
- torch .FloatTensor ( x )
119
+ torch .tensor ( x , device = device )
120
120
for x in (principal_point , focal_length , R , tvec , image_size )
121
121
]
122
- camera_matrix = eyes (dim = 3 , N = 4 )
122
+ camera_matrix = eyes (dim = 3 , N = 4 , device = device )
123
123
camera_matrix [:, 0 , 0 ], camera_matrix [:, 1 , 1 ] = (
124
124
focal_length [:, 0 ],
125
125
focal_length [:, 1 ],
126
126
)
127
127
camera_matrix [:, :2 , 2 ] = principal_point
128
128
129
- pts = torch .nn .functional .normalize (torch .randn (4 , 1000 , 3 ), dim = - 1 )
129
+ pts = torch .nn .functional .normalize (
130
+ torch .randn (4 , 1000 , 3 , device = device ), dim = - 1
131
+ )
130
132
131
133
# project the 3D points with the opencv projection function
132
134
rvec = so3_log_map (R )
@@ -136,6 +138,7 @@ def test_opencv_conversion(self):
136
138
cameras_opencv_to_pytorch3d = cameras_from_opencv_projection (
137
139
R , tvec , camera_matrix , image_size
138
140
)
141
+ self .assertEqual (cameras_opencv_to_pytorch3d .device , device )
139
142
140
143
# project the 3D points with converted cameras to screen space.
141
144
pts_proj_pytorch3d_screen = cameras_opencv_to_pytorch3d .transform_points_screen (
0 commit comments