Esri / Esri/raster-deep-learning
Keras example - AttributeError: module 'utils' has no attribute 'batch_slice'
- Dominant language
- Python
- Stars
- 203
- Forks
- 92
- PR merge metrics
- No merged PRs in 30d
Description
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 **_mrcnn_utils.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.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with examples/keras/mask_rcnn/mrcnn/model.py and the accompanying utils.py, then inspect the import used where batch_slice is called. Reproduce the Keras example through ArcGIS Pro with the provided mask_rcnn.emd file and verify that initialization completes without the AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- keras, python, tensorflow
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100