nutonomy / nuscenes-devkit

The devkit of the nuScenes dataset.
https://www.nuScenes.org
Other
2.3k stars 631 forks source link

Problem running prediction_tutorial #852

Closed MahirGulzar closed 1 year ago

MahirGulzar commented 1 year ago

Hello, I am trying to run the prediction tutorial given with the devkit. I get following error when I get to InputRepresentation section. I am currently using devkit version 1.1.9.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_12287/300740985.py in <module>
     13 instance_token_img, sample_token_img = 'bc38961ca0ac4b14ab90e547ba79fbb6', '7626dde27d604ac28a0240bdd54eba7a'
     14 anns = [ann for ann in nuscenes.sample_annotation if ann['instance_token'] == instance_token_img]
---> 15 img = mtp_input_representation.make_input_representation(instance_token_img, sample_token_img)
     16 
     17 plt.imshow(img)

~/miniconda3/envs/pgp_test/lib/python3.7/site-packages/nuscenes/prediction/input_representation/interface.py in make_input_representation(self, instance_token, sample_token)
     48     def make_input_representation(self, instance_token: str, sample_token: str) -> np.ndarray:
     49 
---> 50         static_layers = self.static_layer_rasterizer.make_representation(instance_token, sample_token)
     51         agents = self.agent_rasterizer.make_representation(instance_token, sample_token)
     52 

~/miniconda3/envs/pgp_test/lib/python3.7/site-packages/nuscenes/prediction/input_representation/static_layers.py in make_representation(self, instance_token, sample_token)
    270         canvas_size = (image_side_length_pixels, image_side_length_pixels)
    271 
--> 272         masks = self.maps[map_name].get_map_mask(patchbox, angle_in_degrees, self.layer_names, canvas_size=canvas_size)
    273 
    274         images = []

~/miniconda3/envs/pgp_test/lib/python3.7/site-packages/nuscenes/map_expansion/map_api.py in get_map_mask(self, patch_box, patch_angle, layer_names, canvas_size)
    390         :return: Stacked numpy array of size [c x h x w] with c channels and the same width/height as the canvas.
    391         """
--> 392         return self.explorer.get_map_mask(patch_box, patch_angle, layer_names=layer_names, canvas_size=canvas_size)
    393 
    394     def get_map_geom(self,

~/miniconda3/envs/pgp_test/lib/python3.7/site-packages/nuscenes/map_expansion/map_api.py in get_map_mask(self, patch_box, patch_angle, layer_names, canvas_size)
    868         # Convert the patch box from global coordinates to local coordinates by setting the center to (0, 0).
    869         local_box = (0.0, 0.0, patch_box[2], patch_box[3])
--> 870         map_mask = self.map_geom_to_mask(map_geom, local_box, canvas_size)
    871         assert np.all(map_mask.shape[1:] == canvas_size)
    872 

~/miniconda3/envs/pgp_test/lib/python3.7/site-packages/nuscenes/map_expansion/map_api.py in map_geom_to_mask(self, map_geom, local_box, canvas_size)
    817         map_mask = []
    818         for layer_name, layer_geom in map_geom:
--> 819             layer_mask = self._layer_geom_to_mask(layer_name, layer_geom, local_box, canvas_size)
    820             if layer_mask is not None:
    821                 map_mask.append(layer_mask)

~/miniconda3/envs/pgp_test/lib/python3.7/site-packages/nuscenes/map_expansion/map_api.py in _layer_geom_to_mask(self, layer_name, layer_geom, local_box, canvas_size)
   1801         """
   1802         if layer_name in self.map_api.non_geometric_polygon_layers:
-> 1803             return self._polygon_geom_to_mask(layer_geom, local_box, layer_name, canvas_size)
   1804         elif layer_name in self.map_api.non_geometric_line_layers:
   1805             return self._line_geom_to_mask(layer_geom, local_box, layer_name, canvas_size)

~/miniconda3/envs/pgp_test/lib/python3.7/site-packages/nuscenes/map_expansion/map_api.py in _polygon_geom_to_mask(self, layer_geom, local_box, layer_name, canvas_size)
   1888                 if new_polygon.geom_type is 'Polygon':
   1889                     new_polygon = MultiPolygon([new_polygon])
-> 1890                 map_mask = self.mask_for_polygons(new_polygon, map_mask)
   1891 
   1892         return map_mask

~/miniconda3/envs/pgp_test/lib/python3.7/site-packages/nuscenes/map_expansion/map_api.py in mask_for_polygons(polygons, mask)
   1821             # function to round and convert to int
   1822             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]
   1825         cv2.fillPoly(mask, exteriors, 1)

TypeError: 'MultiPolygon' object is not iterable`
GilgameshD commented 1 year ago

I have the same problem when I use shapely-2.0.0 and solve it by downgrading to shapely-1.8.5.