Esri / raster-deep-learning

ArcGIS built-in python raster functions for deep learning to get you started fast.
Apache License 2.0
186 stars 87 forks source link

Keras example - AttributeError: module 'utils' has no attribute 'batch_slice' #15

Open tim-mcg opened 5 years ago

tim-mcg commented 5 years ago

Trying to run the Keras example. When choosing the provided mask_rcnn.emd file in the geoprocessing tool in ArcGIS Pro the below error is shown:

ERROR 002667 Unable to initialize python raster function with scalar arguments. [c:\program files\arcgis\pro\Resources\Raster\Functions\System\DeepLearning\ObjectDetector.py] Using TensorFlow backend. WARNING:tensorflow:From C:\Program Files\ArcGIS\Pro\bin\Python\envs\DeepLearningEnvTest\Lib\site-packages\tensorflow\python\framework\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version. Instructions for updating: Colocations handled automatically by placer. Traceback (most recent call last): File "c:\program files\arcgis\pro\Resources\Raster\Functions\System\DeepLearning\ObjectDetector.py", line 48, in initialize self.child_object_detector.initialize(model, model_as_file) File "c:\program files\arcgis\pro\Resources\Raster\Functions\System\DeepLearning\Keras\MaskRCNN.py", line 32, in initialize self.config = getattr(importlib.import_module(config_module_name), 'config') File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\DeepLearningEnvTest\Lib\importlib__init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 994, in _gcd_import File "", line 971, in _find_and_load File "", line 955, in _find_and_load_unlocked File "", line 665, in _load_unlocked File "", line 678, in exec_module File "", line 219, in _call_with_frames_removed File "T:\tim\esri_deep_learning\raster-deep-learning-master\examples\keras\mask_rcnn\mrcnn\spacenet.py", line 27, in model = modellib.MaskRCNN(mode='inference', config=config, model_dir='./') File "T:\tim\esri_deep_learning\raster-deep-learning-master\examples\keras\mask_rcnn\mrcnn\model.py", line 1849, in init__ self.keras_model = self.build(mode=mode, config=config) File "T:\tim\esri_deep_learning\raster-deep-learning-master\examples\keras\mask_rcnn\mrcnn\model.py", line 1978, in build config=config)([rpn_class, rpn_bbox, anchors]) File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\DeepLearningEnvTest\Lib\site-packages\keras\engine\base_layer.py", line 457, in call output = self.call(inputs, **kwargs) File "T:\tim\esri_deep_learning\raster-deep-learning-master\examples\keras\mask_rcnn\mrcnn\model.py", line 293, in call scores = utils.batch_slice([scores, ix], lambda x, y: tf.gather(x, y), AttributeError: module 'utils' has no attribute 'batch_slice'

Unable to initialize python raster function with scalar arguments.

I think whats happening is that model.py is trying to import utils.py but is finding a different utils module somewhere else in the system.

The only way I could get around this was to rename utils.py to mrcnn_utils.py and then modify model.py.

From:

import utils

To:

import mrcnn_utils

And then search and replace all the utils.Function statements to be _mrcnnutils.Function. Be careful when doing this as there are are references to utils such as distutils and keras.utils which should not be changed.

When doing all these changes I could successfully run the keras example.

hanhu7 commented 5 years ago

Hi @tim-mcg thanks for your post. yes, if you already have a 'utils.py' module in your PYTHONPATH that would cause a name conflict hence this python module would first load the utils in your PYTHONPATH. We will try to resolve this by using relative import.