Repository: azavea/raster-vision

Issue:
Allow Map Tiles to be evaluated
I am trying to make rastervision work for a tiled map, so I run it on each tile I have, for example:
![image](https://user-images.githubusercontent.com/5757359/55006587-a45ad780-4fe6-11e9-8f6c-86e2ffedc23d.png)

When I do, I get the error:

> rastervision_1  | Executing rastervision predict /app/packages/xView_Vehicle.zip /images/674915186.png output/xView_Vehicle_674915186.png.json
> rastervision_1  | (node:7) UnhandledPromiseRejectionWarning: Error: Command failed: rastervision predict /app/packages/xView_Vehicle.zip /images/674915186.png output/xView_Vehicle_674915186.png.json
> rastervision_1  | 2019-03-26 14:44:13.975033: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
> rastervision_1  | /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`.
> rastervision_1  |   fromlist, level)
> rastervision_1  | /usr/local/lib/python3.5/dist-packages/rasterio/__init__.py:217: NotGeoreferencedWarning: Dataset has no geotransform set. The identity matrix may be returned.
> rastervision_1  |   s = DatasetReader(path, driver=driver, **kwargs)
> rastervision_1  | 2019-03-26 14:44:13:rastervision.task.task: INFO - Making predictions for scene
> rastervision_1  | Traceback (most recent call last):
> rastervision_1  |   File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
> rastervision_1  |     "__main__", mod_spec)
> rastervision_1  |   File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
> rastervision_1  |     exec(code, run_globals)
> rastervision_1  |   File "/opt/src/rastervision/__main__.py", line 17, in <module>
> rastervision_1  |     rv.main()
> rastervision_1  |   File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in __call__
> rastervision_1  |     return self.main(*args, **kwargs)
> rastervision_1  |   File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
> rastervision_1  |     rv = self.invoke(ctx)
> rastervision_1  |   File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
> rastervision_1  |     return _process_result(sub_ctx.command.invoke(sub_ctx))
> rastervision_1  |   File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
> rastervision_1  |     return ctx.invoke(self.callback, **ctx.params)
> rastervision_1  |   File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
> rastervision_1  |     return callback(*args, **kwargs)
> rastervision_1  |   File "/opt/src/rastervision/cli/main.py", line 240, in predict
> rastervision_1  |     predictor.predict(image_uri, output_uri, export_config)
> rastervision_1  |   File "/opt/src/rastervision/predictor.py", line 142, in predict
> rastervision_1  |     labels = self.task.predict_scene(scene, self.tmp_dir)
> rastervision_1  |   File "/opt/src/rastervision/task/task.py", line 192, in predict_scene
> rastervision_1  |     predict_batch(batch_chips, batch_windows)
> rastervision_1  |   File "/opt/src/rastervision/task/task.py", line 173, in predict_batch
> rastervision_1  |     np.array(predict_chips), predict_windows, tmp_dir)
> rastervision_1  |   File "/opt/src/rastervision/backend/tf_object_detection.py", line 736, in predict
> rastervision_1  |     self.session)
> rastervision_1  |   File "/opt/src/rastervision/backend/tf_object_detection.py", line 573, in compute_prediction
> rastervision_1  |     [boxes, scores, class_ids], feed_dict={image_tensor: image_nps})
> rastervision_1  |   File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 877, in run
> rastervision_1  |     run_metadata_ptr)
> rastervision_1  |   File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1076, in _run
> rastervision_1  |     str(subfeed_t.get_shape())))
> rastervision_1  | ValueError: Cannot feed value of shape (2, 300, 300, 1) for Tensor 'image_tensor:0', which has shape '(?, ?, ?, 3)'
> rastervision_1  | 
> rastervision_1  |     at ChildProcess.exithandler (child_process.js:294:12)
> rastervision_1  |     at ChildProcess.emit (events.js:189:13)
> rastervision_1  |     at maybeClose (internal/child_process.js:970:16)
> rastervision_1  |     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
> rastervision_1  | (node:7) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
> rastervision_1  | (node:7) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I am successfull at running the same code on TIF files, and JPEG.


Discussion:
I was not able to replicate this on the `master` branch. Could you please tell me the command you ran, the prediction package, the input image, and the branch/version you were using?
I ran:
> rastervision predict /app/packages/xView_Vehicle.zip /images/674915186.png output/xView_Vehicle_674915186.png.json

(so xVIew_Vehicle package)

With that PNG image I put in the body of the issue,
and  on cpu-latest docker image.

Resolving patch:
diff --git a/rastervision/data/raster_source/raster_source_config.py b/rastervision/data/raster_source/raster_source_config.py
--- a/rastervision/data/raster_source/raster_source_config.py
+++ b/rastervision/data/raster_source/raster_source_config.py
@@ -119,7 +119,10 @@ def from_proto(self, msg):
             map(lambda m: RasterTransformerConfig.from_proto(m),
                 msg.transformers))
 
-        return self.with_channel_order(list(msg.channel_order)) \
+        channel_order = list(msg.channel_order)
+        if len(channel_order) == 0:
+            channel_order = None
+        return self.with_channel_order(channel_order) \
                    .with_transformers(transformers)
 
     def with_channel_order(self, channel_order):


Test patch:
diff --git a/tests/data/raster_source/test_rasterio_source.py b/tests/data/raster_source/test_rasterio_source.py
--- a/tests/data/raster_source/test_rasterio_source.py
+++ b/tests/data/raster_source/test_rasterio_source.py
@@ -252,6 +252,14 @@ def test_detects_alpha(self):
                 expected_out_chip[:, :, :] *= np.array([1, 2]).astype(np.uint8)
                 np.testing.assert_equal(out_chip, expected_out_chip)
 
+    def test_empty_channel_order(self):
+        config = rv.RasterSourceConfig.builder(rv.RASTERIO_SOURCE) \
+                                      .with_uri('a.tif') \
+                                      .build()
+        msg = config.to_proto()
+        config = rv.RasterSourceConfig.from_proto(msg)
+        self.assertEqual(config.channel_order, None)
+
     def test_non_geo(self):
         # Check if non-georeferenced image files can be read and CRSTransformer
         # implements the identity function.