Issue with MultiTaskRoadExtractor and Automatic Road Extraction using Deep Learning

281
0
08-26-2021 10:11 AM
ZacharyNeumann1
New Contributor III

I am following the automatic road extraction using deep learning sample notebook. My code is mostly the same (instead of pointing to data path in arcgis online I am pointing to folder that holds training data). I have created my own training data that I am using.

 

When I run:

data = prepare_data(datapath, chip_size=512, batch_size=10)

 

I get the error:

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\learn\models\_arcgis_model.py:366: UserWarning: Cuda is not available
  warnings.warn("Cuda is not available")

 

But I still get results for:

data.show_batch(alpha=1)

 

Then when I run:

model = MultiTaskRoadExtractor(data, mtl_model="hourglass")

 

I get the following AttributeError:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\PIL\Image.py in open(fp, mode)
   2846     try:
-> 2847         fp.seek(0)
   2848     except (AttributeError, io.UnsupportedOperation):

AttributeError: 'numpy.ndarray' object has no attribute 'seek'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
<ipython-input-5-f5e8368fe40d> in <module>
----> 1 model = MultiTaskRoadExtractor(data, mtl_model="hourglass")

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\learn\models\_multi_task_road_extractor.py in __init__(self, data, backbone, pretrained_path, *args, **kwargs)
    176 
    177 
--> 178             self._orient_data=self._get_road_orient_data(data,**kwargs)
    179             if len(data.classes) > 2:
    180                 raise Exception(

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\learn\models\_multi_task_road_extractor.py in _get_road_orient_data(self, data, **kwargs)
    378             dataset_type=self._data.dataset_type, resize_to=self._data.resize_to, **kwargs)
    379         road_orient_obj = RoadOrientation(self._data,road_data_obj, **kwargs)
--> 380         orient_data = road_orient_obj.get_databunch(data,**kwargs)
    381         return orient_data
    382 

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\learn\_data_utils\_road_orient_data.py in get_databunch(self, orig_data, **kwargs)
    262 
    263 
--> 264         data.chip_size = data.train_ds[0][0].shape[-1]
    265         data.c = len(self.class_mapping) if self.class_mapping else 2
    266 

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\learn\_data_utils\_road_orient_data.py in __getitem__(self, index)
    344 
    345     def __getitem__(self, index):
--> 346         image, label = self._getRoadData(index)
    347 
    348         seed = np.random.randint(2147483647)  # make a seed with numpy generator

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\learn\_data_utils\_road_orient_data.py in _getRoadData(self, index)
    407             #
    408             #image = PILImage.fromarray(np.asarray(ArcGISMSImage.open_gdal(image_dict["image"]))).astype(np.uint8)
--> 409         label = self._get_mask(np.asarray(PILImage.open(image_dict["label"])))
    410 
    411         return image, PILImage.fromarray(label).convert("L")

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\PIL\Image.py in open(fp, mode)
   2847         fp.seek(0)
   2848     except (AttributeError, io.UnsupportedOperation):
-> 2849         fp = io.BytesIO(fp.read())
   2850         exclusive_fp = True
   2851 

AttributeError: 'numpy.ndarray' object has no attribute 'read'

 

I am running ArcGIS Pro 2.8.0, I have image analyst and spatial analyst turned on and have installed the ArcGIS Pro 2.8 deep learning libraries from github.

 

Photos:

ZacharyNeumann1_0-1629997652868.png

ZacharyNeumann1_1-1629997663651.png

 

0 Kudos
0 Replies