Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretrained model: TypeError: 'NoneType' object is not subscriptable #705

Closed
AmitMY opened this issue Mar 5, 2019 · 4 comments
Closed

Pretrained model: TypeError: 'NoneType' object is not subscriptable #705

AmitMY opened this issue Mar 5, 2019 · 4 comments

Comments

@AmitMY
Copy link

AmitMY commented Mar 5, 2019

I tried the most basic experiment, with the latest docker version:

FROM quay.io/azavea/raster-vision:cpu-0.8.1
RUN mkdir packages
RUN wget -O packages/xView_Vehicle.zip https://s3.amazonaws.com/azavea-research-public-data/raster-vision/examples/model-zoo/xview-vehicle-od/predict_package.zip

And ran:

wget https://content.satimagingcorp.com/static/galleryimages/vatican-city-satellite-image-ikonos-high-resolution.jpg -O example.jpg

as an example image for quick testing:
image

And: (I tried multiple models)

rastervision predict /app/packages/xView_Vehicle.zip example.jpg output.json

I get:

/usr/local/lib/python3.5/dist-packages/pluginbase.py:439: FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type.
fromlist, level)
2019-03-05 17:11:37.542566: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-03-05 17:11:37:rastervision.data.raster_source.geotiff_source: INFO - Loading GeoTiff files...
/usr/local/lib/python3.5/dist-packages/rasterio/init.py:217: NotGeoreferencedWarning: Dataset has no geotransform set. The identity matrix may be returned.
s = DatasetReader(path, driver=driver, **kwargs)
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/opt/src/rastervision/main.py", line 17, in
rv.main()
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/opt/src/rastervision/cli/main.py", line 240, in predict
predictor.predict(image_uri, output_uri, export_config)
File "/opt/src/rastervision/predictor.py", line 130, in predict
scene = scene_config.create_scene(self.task_config, self.tmp_dir)
File "/opt/src/rastervision/data/scene_config.py", line 39, in create_scene
crs_transformer = raster_source.get_crs_transformer()
File "/opt/src/rastervision/data/raster_source/geotiff_source.py", line 44, in get_crs_transformer
return RasterioCRSTransformer(self.image_dataset)
File "/opt/src/rastervision/data/crs_transformer/rasterio_crs_transformer.py", line 18, in init
image_crs = image_dataset.crs['init']
TypeError: 'NoneType' object is not subscriptable

Why? How can I fix this?

@lewfish
Copy link
Contributor

lewfish commented Mar 5, 2019

You'll need to use the develop branch or quay.io/azavea/raster-vision:cpu-latest which has that bug fix. (We're long overdue for a bug fix release.) Also, that test image you're using is too low resolution to detect the cars, and models tend to not generalize too well on different datasets which are too different from the training set. I would use the provided sample image at https://s3.amazonaws.com/azavea-research-public-data/raster-vision/examples/model-zoo/xview-vehicle-od/1677.tif

Here is the output I got in QGIS:
screen shot 2019-03-05 at 5 42 13 pm

@AmitMY
Copy link
Author

AmitMY commented Mar 6, 2019

Thanks, that works.
I wanted to verify this works on JPEGs as well, it does! :)

@AmitMY AmitMY closed this as completed Mar 6, 2019
@AmitMY
Copy link
Author

AmitMY commented Mar 6, 2019

Correction, now the xView and COWC models work, but not others.

I tried running all models on the same JPEG and I get:

rastervision predict /app/packages/ISPRS_Potsdam.zip example.jpg output.json

/usr/local/lib/python3.5/dist-packages/pluginbase.py:439: FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type.
fromlist, level)
2019-03-06 09:19:14.059121: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
/usr/local/lib/python3.5/dist-packages/rasterio/init.py:217: NotGeoreferencedWarning: Dataset has no geotransform set. The identity matrix may be returned.
s = DatasetReader(path, driver=driver, **kwargs)
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/opt/src/rastervision/main.py", line 17, in
rv.main()
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/opt/src/rastervision/cli/main.py", line 240, in predict
predictor.predict(image_uri, output_uri, export_config)
File "/opt/src/rastervision/predictor.py", line 131, in predict
scene = scene_config.create_scene(self.task_config, self.tmp_dir)
File "/opt/src/rastervision/data/scene_config.py", line 36, in create_scene
raster_source = self.raster_source.create_source(tmp_dir)
File "/opt/src/rastervision/data/raster_source/geotiff_source_config.py", line 70, in create_source
y_shift_meters=y_shift_meters)
File "/opt/src/rastervision/data/raster_source/geotiff_source.py", line 46, in init
super().init(raster_transformers, temp_dir, channel_order)
File "/opt/src/rastervision/data/raster_source/rasterio_source.py", line 69, in init
test_chip = test_chip[:, :, self.channel_order]
IndexError: index 3 is out of bounds for axis 2 with size 3

rastervision predict /app/packages/Spacenet_Vegas_Roads.zip example.jpg output.json
or
rastervision predict /app/packages/Spacenet_Vegas_Buildings.zip example.jpg output.json

/usr/local/lib/python3.5/dist-packages/pluginbase.py:439: FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type.
fromlist, level)
2019-03-06 09:15:57.030828: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
/usr/local/lib/python3.5/dist-packages/rasterio/init.py:217: NotGeoreferencedWarning: Dataset has no geotransform set. The identity matrix may be returned.
s = DatasetReader(path, driver=driver, **kwargs)
2019-03-06 09:15:57:rastervision.task.semantic_segmentation: INFO - Making predictions for scene
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/opt/src/rastervision/main.py", line 17, in
rv.main()
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/opt/src/rastervision/cli/main.py", line 240, in predict
predictor.predict(image_uri, output_uri, export_config)
File "/opt/src/rastervision/predictor.py", line 144, in predict
scene.prediction_label_store.save(labels)
File "/opt/src/rastervision/data/label_store/semantic_segmentation_raster_store.py", line 90, in save
transform = self.crs_transformer.transform
AttributeError: 'IdentityCRSTransformer' object has no attribute 'transform'

@AmitMY AmitMY reopened this Mar 6, 2019
@lewfish
Copy link
Contributor

lewfish commented Mar 6, 2019

The reason it crashed using the Potsdam package was because that was trained using a channel_order of [3, 0, 1] (to use the infrared band) but the image you used only has 3 bands. The solution is to pass --channel-order "0 1 2" to the predict command. But this didn't work as expected as documented here #706. There's a workaround mentioned at the bottom of that issue that you can use to set the channel order. Also, I made an issue to improve the error message for the case : #709

A separate issue is that saving predictions for semantic segmentation with non-georeferenced imagery (like a JPG file) is broken. This PR #708 should fix that issue.

Thanks for hitting some edge cases that we normally don't run up against!

@lewfish lewfish closed this as completed Mar 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants