Skip to content

Commit fff495f

Browse files
committed
Modifications to support Python 3.12
1 parent e1db722 commit fff495f

File tree

9 files changed

+27
-27
lines changed

9 files changed

+27
-27
lines changed

python-sdk/nuscenes/map_expansion/map_api.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from nuscenes.utils.geometry_utils import view_points
3030

3131
# Recommended style to use as the plots will show grids.
32-
plt.style.use('seaborn-whitegrid')
32+
plt.style.use('seaborn-v0_8-whitegrid')
3333

3434
# Define a map geometry type for polygons and lines.
3535
Geometry = Union[Polygon, LineString]
@@ -1820,8 +1820,8 @@ def mask_for_polygons(polygons: MultiPolygon, mask: np.ndarray) -> np.ndarray:
18201820
def int_coords(x):
18211821
# function to round and convert to int
18221822
return np.array(x).round().astype(np.int32)
1823-
exteriors = [int_coords(poly.exterior.coords) for poly in polygons]
1824-
interiors = [int_coords(pi.coords) for poly in polygons for pi in poly.interiors]
1823+
exteriors = [int_coords(poly.exterior.coords) for poly in polygons.geoms]
1824+
interiors = [int_coords(pi.coords) for poly in polygons.geoms for pi in poly.interiors]
18251825
cv2.fillPoly(mask, exteriors, 1)
18261826
cv2.fillPoly(mask, interiors, 0)
18271827
return mask
@@ -1885,7 +1885,7 @@ def _polygon_geom_to_mask(self,
18851885
[1.0, 0.0, 0.0, 1.0, trans_x, trans_y])
18861886
new_polygon = affinity.scale(new_polygon, xfact=scale_width, yfact=scale_height, origin=(0, 0))
18871887

1888-
if new_polygon.geom_type is 'Polygon':
1888+
if new_polygon.geom_type == 'Polygon':
18891889
new_polygon = MultiPolygon([new_polygon])
18901890
map_mask = self.mask_for_polygons(new_polygon, map_mask)
18911891

@@ -1922,7 +1922,7 @@ def _line_geom_to_mask(self,
19221922

19231923
map_mask = np.zeros(canvas_size, np.uint8)
19241924

1925-
if layer_name is 'traffic_light':
1925+
if layer_name == 'traffic_light':
19261926
return None
19271927

19281928
for line in layer_geom:
@@ -1968,7 +1968,7 @@ def _get_layer_polygon(self,
19681968
origin=(patch_x, patch_y), use_radians=False)
19691969
new_polygon = affinity.affine_transform(new_polygon,
19701970
[1.0, 0.0, 0.0, 1.0, -patch_x, -patch_y])
1971-
if new_polygon.geom_type is 'Polygon':
1971+
if new_polygon.geom_type == 'Polygon':
19721972
new_polygon = MultiPolygon([new_polygon])
19731973
polygon_list.append(new_polygon)
19741974

@@ -1983,7 +1983,7 @@ def _get_layer_polygon(self,
19831983
origin=(patch_x, patch_y), use_radians=False)
19841984
new_polygon = affinity.affine_transform(new_polygon,
19851985
[1.0, 0.0, 0.0, 1.0, -patch_x, -patch_y])
1986-
if new_polygon.geom_type is 'Polygon':
1986+
if new_polygon.geom_type == 'Polygon':
19871987
new_polygon = MultiPolygon([new_polygon])
19881988
polygon_list.append(new_polygon)
19891989

@@ -2003,7 +2003,7 @@ def _get_layer_line(self,
20032003
if layer_name not in self.map_api.non_geometric_line_layers:
20042004
raise ValueError("{} is not a line layer".format(layer_name))
20052005

2006-
if layer_name is 'traffic_light':
2006+
if layer_name == 'traffic_light':
20072007
return None
20082008

20092009
patch_x = patch_box[0]

python-sdk/nuscenes/prediction/input_representation/agents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def draw_agent_boxes(center_agent_annotation: Dict[str, Any],
193193
if num_points > 1:
194194
color = fade_color(color, i, num_points - 1)
195195

196-
cv2.fillPoly(base_image, pts=[np.int0(box)], color=color)
196+
cv2.fillPoly(base_image, pts=[np.intp(box)], color=color)
197197

198198

199199
class AgentBoxesWithFadedHistory(AgentRepresentation):

python-sdk/nuscenes/prediction/input_representation/tests/test_agents.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ def get_colors(name):
153153
agent_1_ts_0 = cv2.boxPoints(((300, 350), (30, 30), -90))
154154
agent_1_ts_1 = cv2.boxPoints(((300, 300), (30, 30), -90))
155155

156-
answer = cv2.fillPoly(answer, pts=[np.int0(agent_0_ts_0)], color=(102, 0, 0))
157-
answer = cv2.fillPoly(answer, pts=[np.int0(angent_0_ts_1)], color=(255, 0, 0))
158-
answer = cv2.fillPoly(answer, pts=[np.int0(agent_1_ts_0)], color=(102, 102, 0))
159-
answer = cv2.fillPoly(answer, pts=[np.int0(agent_1_ts_1)], color=(255, 255, 0))
156+
answer = cv2.fillPoly(answer, pts=[np.intp(agent_0_ts_0)], color=(102, 0, 0))
157+
answer = cv2.fillPoly(answer, pts=[np.intp(angent_0_ts_1)], color=(255, 0, 0))
158+
answer = cv2.fillPoly(answer, pts=[np.intp(agent_1_ts_0)], color=(102, 102, 0))
159+
answer = cv2.fillPoly(answer, pts=[np.intp(agent_1_ts_1)], color=(255, 255, 0))
160160

161161
np.testing.assert_allclose(answer, img)

python-sdk/nuscenes/prediction/input_representation/tests/test_combinators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ def test(self):
1515

1616
layer_1 = np.zeros((100, 100, 3))
1717
box_1 = cv2.boxPoints(((50, 50), (20, 20), 0))
18-
layer_1 = cv2.fillPoly(layer_1, pts=[np.int0(box_1)], color=(255, 255, 255))
18+
layer_1 = cv2.fillPoly(layer_1, pts=[np.intp(box_1)], color=(255, 255, 255))
1919

2020
layer_2 = np.zeros((100, 100, 3))
2121
box_2 = cv2.boxPoints(((70, 30), (10, 10), 0))
22-
layer_2 = cv2.fillPoly(layer_2, pts=[np.int0(box_2)], color=(0, 0, 255))
22+
layer_2 = cv2.fillPoly(layer_2, pts=[np.intp(box_2)], color=(0, 0, 255))
2323

2424
rasterizer = Rasterizer()
2525
image = rasterizer.combine([layer_1.astype('uint8'), layer_2.astype('uint8')])
2626

2727
answer = np.zeros((100, 100, 3))
28-
answer = cv2.fillPoly(answer, pts=[np.int0(box_1)], color=(255, 255, 255))
29-
answer = cv2.fillPoly(answer, pts=[np.int0(box_2)], color=(0, 0, 255))
28+
answer = cv2.fillPoly(answer, pts=[np.intp(box_1)], color=(255, 255, 255))
29+
answer = cv2.fillPoly(answer, pts=[np.intp(box_2)], color=(0, 0, 255))
3030
answer = answer.astype('uint8')
3131

3232
np.testing.assert_allclose(answer, image)

python-sdk/nuscenes/prediction/input_representation/tests/test_static_layers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get_layer_mocks():
2020

2121
layer_1 = np.zeros((100, 100, 3))
2222
box = cv2.boxPoints(((50, 50), (20, 10), -90))
23-
layer_1 = cv2.fillPoly(layer_1, pts=[np.int0(box)], color=(1, 1, 1))
23+
layer_1 = cv2.fillPoly(layer_1, pts=[np.intp(box)], color=(1, 1, 1))
2424
layer_1 = layer_1[::-1, :, 0]
2525

2626
layer_2 = np.zeros((100, 100, 3))
@@ -56,7 +56,7 @@ def test_make_rasterization(self, mock_draw_lanes, mock_load_maps):
5656

5757
lanes = np.zeros((100, 100, 3)).astype('uint8')
5858
lane_box = cv2.boxPoints(((25, 75), (5, 5), -90))
59-
lanes = cv2.fillPoly(lanes, pts=[np.int0(lane_box)], color=(255, 0, 0))
59+
lanes = cv2.fillPoly(lanes, pts=[np.intp(lane_box)], color=(255, 0, 0))
6060
mock_draw_lanes.return_value = lanes
6161

6262
layers = self.get_layer_mocks()
@@ -81,8 +81,8 @@ def test_make_rasterization(self, mock_draw_lanes, mock_load_maps):
8181

8282
answer = np.zeros((100, 100, 3))
8383
box = cv2.boxPoints(((50, 50), (20, 10), -90))
84-
answer = cv2.fillPoly(answer, pts=[np.int0(box)], color=(255, 255, 255))
84+
answer = cv2.fillPoly(answer, pts=[np.intp(box)], color=(255, 255, 255))
8585
answer = cv2.line(answer, (50, 50), (50, 40), color=(255, 0, 0), thickness=2)
86-
answer = cv2.fillPoly(answer, pts=[np.int0(lane_box)], color=(255, 0, 0))
86+
answer = cv2.fillPoly(answer, pts=[np.intp(lane_box)], color=(255, 0, 0))
8787

8888
np.testing.assert_allclose(answer, image)

python-sdk/nuscenes/scripts/export_pointclouds_as_obj.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def pointcloud_color_from_image(nusc: NuScenes,
119119
:param nusc: NuScenes instance.
120120
:param pointsensor_token: Lidar/radar sample_data token.
121121
:param camera_token: Camera sample data token.
122-
:return (coloring <np.float: 3, n>, mask <np.bool: m>). Returns the colors for n points that reproject into the
122+
:return (coloring <np.float: 3, n>, mask <bool: m>). Returns the colors for n points that reproject into the
123123
image out of m total points. The mask indicates which points are selected.
124124
"""
125125

python-sdk/nuscenes/utils/geometry_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def points_in_box(box: 'Box', points: np.ndarray, wlh_factor: float = 1.0):
118118
:param box: <Box>.
119119
:param points: <np.float: 3, n>.
120120
:param wlh_factor: Inflates or deflates the box.
121-
:return: <np.bool: n, >.
121+
:return: <bool: n, >.
122122
"""
123123
corners = box.corners(wlh_factor=wlh_factor)
124124

python-sdk/nuscenes/utils/map_mask.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ def is_on_mask(self, x: Any, y: Any, dilation: float = 0) -> np.array:
5757
:param x: Global x coordinates. Can be a scalar, list or a numpy array of x coordinates.
5858
:param y: Global y coordinates. Can be a scalar, list or a numpy array of x coordinates.
5959
:param dilation: Optional dilation of map mask.
60-
:return: <np.bool: x.shape>. Whether the points are on the mask.
60+
:return: <bool: x.shape>. Whether the points are on the mask.
6161
"""
6262
px, py = self.to_pixel_coords(x, y)
6363

64-
on_mask = np.ones(px.size, dtype=np.bool)
64+
on_mask = np.ones(px.size, dtype=bool)
6565
this_mask = self.mask(dilation)
6666

6767
on_mask[px < 0] = False

python-sdk/tutorials/map_expansion_tutorial.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
"source": [
198198
"# Init nuScenes. Requires the dataset to be stored on disk.\n",
199199
"from nuscenes.nuscenes import NuScenes\n",
200-
"nusc = NuScenes(version='v1.0-mini', verbose=False)\n",
200+
"nusc = NuScenes(version='v1.0-mini', dataroot='/data/sets/nuscenes', verbose=False)\n",
201201
"\n",
202202
"# Pick a sample and render the front camera image.\n",
203203
"sample_token = nusc.sample[9]['token']\n",
@@ -222,7 +222,7 @@
222222
"source": [
223223
"# Init NuScenes. Requires the dataset to be stored on disk.\n",
224224
"from nuscenes.nuscenes import NuScenes\n",
225-
"nusc = NuScenes(version='v1.0-mini', verbose=False)\n",
225+
"nusc = NuScenes(version='v1.0-mini', dataroot='/data/sets/nuscenes', verbose=False)\n",
226226
"\n",
227227
"# Render ego poses.\n",
228228
"nusc_map_bos = NuScenesMap(dataroot='/data/sets/nuscenes', map_name='boston-seaport')\n",

0 commit comments

Comments
 (0)