Esri / arcgis-python-api

Documentation and samples for ArcGIS API for Python
https://developers.arcgis.com/python/
Apache License 2.0
1.9k stars 1.1k forks source link

building_reconstruction_using_mask_rcnn.ipynb un-reproducable output #733

Closed cdflint closed 4 years ago

cdflint commented 4 years ago

Part 1 - Data Preparation

In the step to export training data with arcpy using the Image Analyst extension.

The output directory is listed as \Documents\PCNN\Only_nDSM

And the class_value_field="None".

When using the export training data geoprocessing tool in arcgis pro (v2.5.2) having no class value selected returns.

image

When selecting a class value for an integer representing the unique ROOFFORMS the tool exports the training data as expected with labels nested into their own unique folders in the labels directory.

Part 2 - Model Training

The path specified is not the same root path used to export the training data listed above. The new path is Documents\PCNN\Only_nDSM\Data_AOI2 indicating that it is one folder deeper than the original output.

When trying to pass the original root folder to the prepare_data function it returns.

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-4-259893bd5a1a> in <module>
     14             batch_size=batch_size,
     15             dataset_type='RCNN_Masks',
---> 16             imager_type='ms'
     17 )
     18 # ??prepare_data

C:\tools\miniconda3\envs\sky-net\lib\site-packages\arcgis\learn\_data.py in prepare_data(path, class_mapping, chip_size, val_split_pct, batch_size, transforms, collate_fn, seed, dataset_type, resize_to, **kwargs)
    978                     batch_stats[s] = torch.tensor(batch_stats[s])
    979         else:
--> 980             batch_stats = _get_batch_stats(data.x, norm_pct)
    981             normstats[norm_pct_search] = dict(batch_stats)
    982             for s in normstats[norm_pct_search]:

C:\tools\miniconda3\envs\sky-net\lib\site-packages\arcgis\learn\_data.py in _get_batch_stats(image_list, norm_pct, _band_std_values)
    205     mean_values_store = []
    206 
--> 207     data_shape = image_list[0].data.shape
    208     n_bands = data_shape[0]
    209     feasible_chunk = round(512*4*400/(n_bands*data_shape[1])) # ~3gb footprint

C:\tools\miniconda3\envs\sky-net\lib\site-packages\fastai\data_block.py in __getitem__(self, idxs)
    118         "returns a single item based if `idxs` is an integer or a new `ItemList` object if `idxs` is a range."
    119         idxs = try_int(idxs)
--> 120         if isinstance(idxs, Integral): return self.get(idxs)
    121         else: return self.new(self.items[idxs], inner_df=index_row(self.inner_df, idxs))
    122 

C:\tools\miniconda3\envs\sky-net\lib\site-packages\fastai\vision\data.py in get(self, i)
    268 
    269     def get(self, i):
--> 270         fn = super().get(i)
    271         res = self.open(fn)
    272         self.sizes[i] = res.size

C:\tools\miniconda3\envs\sky-net\lib\site-packages\fastai\data_block.py in get(self, i)
     73     def get(self, i)->Any:
     74         "Subclass if you want to customize how to create item `i` from `self.items`."
---> 75         return self.items[i]
     76     def __repr__(self)->str:
     77         items = [self[i] for i in range(min(5,len(self.items)))]

IndexError: index 0 is out of bounds for axis 0 with size 0

I brought the exported TIFF tiles into Pro and they appear valid single band rasters as used in the example still showing elevation as expected and still spatially correct. Same with the label masks they are in the correct spatially, appropriate cell size and binary (class_value and 0) rasters.

This environment is using arcgis v1.8.1 with all necessary deep learning modules and can train on Unet and PSPnet successfully. If there is some data manipulation that is needed in between the export and prepare_data function or specific parameter flags needed; that being outlined better would be fantastic.

It would also be very helpful if when new versions of the ArcGIS Python API drop to include full conda env requirements exported from the dev/test env's used.

conda env export > env.yml or conda list -e > requirements.txt

Either of those methods would ensure that all packages needed could be acquired at their specific version to not cause breaking changes. Things like the latest libtiff version being used versus 4.0.10 would be easier to troubleshoot etc.

Platform (please complete the following information):

guneetmutreja commented 4 years ago

Thank you @cdflint, I will resolve the bugs.

cdflint commented 4 years ago

It appears the export training data tool pushed out image chips without any accompanying labels. There were around 10 in my dateset without labels, removing those seems to have rectified the issue.