DeepForest: Unable to run prediction with error AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'
Describe the bug
When running the python example code provided on your GitHub page for usage/prediction and using a setup you’ve tested (Mojave 10.14, python 3.7.5, managed with https://github.com/pyenv/pyenv-virtualenv), I get the error AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'. The error is thrown on the line model.use_release().
I can solve the error by either using Keras 2.4.3 (you use 2.3.0) or by manually changing '_TensorLike' to Tensor in the file "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py" (as seen in https://github.com/tensorflow/tensorflow/issues/38589 ). Either of these “fixes” produce other errors and shouldn’t be necessary to do in the first place. As I’ve followed your installation instructions and am presumably using the same setup you used, I’m not sure why it’s not working and was hoping for some guidance. Thanks in advance.
To Reproduce
-
Create virtual env called “deep-forest” (using pyenv-virtualenv)
pyenv virtualenv 3.7.5 deep-forestpyenv activate deep-forest
-
Install dependencies (make sure you’ve activated the virtual env)
pip install DeepForest
-
Do detection using the
main.py(shown below)- e.g.
python main.py --path images/some_image.jpg
- e.g.
Code
# main.py
def main():
# Parse command line arguments (if any)
parser = argparse.ArgumentParser()
parser.add_argument('--path', help='Full or relative path to image.')
cmd_args = parser.parse_args()
# Load the deepforest model
model = deepforest.deepforest()
model.use_release()
# Do prediction on user provided image
image_path = get_data(cmd_args['path'])
image = model.predict_image(image_path = image_path)
# Show image, matplotlib expects RGB channel order, but keras-retinanet predicts in BGR
plt.imshow(image[...,::-1])
plt.show()
if __name__ == '__main__':
main()
Command line output & error
(deep-forest) (base) ➜ python main.py --path images/test/DJI_0442.JPG
Using TensorFlow backend.
Reading config file: /Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/deepforest/data/deepforest_config.yml
A blank deepforest object created. To perform prediction, either train or load an existing model.
Downloading model from DeepForest release v0.3.0, see https://github.com/weecology/DeepForest/releases/tag/v0.3.0 for details
NEON.h5: 146MB [00:40, 3.63MB/s]
Model was downloaded and saved to /Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/deepforest/data/NEON.h5
Loading pre-built model: https://github.com/weecology/DeepForest/releases/tag/v0.3.0
Traceback (most recent call last):
File "main.py", line 37, in <module>
main()
File "main.py", line 23, in main
model.use_release()
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/deepforest/deepforest.py", line 171, in use_release
self.model = utilities.read_model(self.weights, self.config)
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/deepforest/utilities.py", line 49, in read_model
model = models.load_model(model_path, backbone_name='resnet50')
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/deepforest/keras_retinanet/models/__init__.py", line 83, in load_model
return keras.models.load_model(filepath, custom_objects=backbone(backbone_name).custom_objects)
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/keras/engine/saving.py", line 492, in load_wrapper
return load_function(*args, **kwargs)
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/keras/engine/saving.py", line 584, in load_model
model = _deserialize_model(h5dict, custom_objects, compile)
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/keras/engine/saving.py", line 274, in _deserialize_model
model = model_from_config(model_config, custom_objects=custom_objects)
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/keras/engine/saving.py", line 627, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/keras/layers/__init__.py", line 168, in deserialize
printable_module_name='layer')
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/keras/utils/generic_utils.py", line 147, in deserialize_keras_object
list(custom_objects.items())))
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/keras/engine/network.py", line 1056, in from_config
process_layer(layer_data)
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/keras/engine/network.py", line 1042, in process_layer
custom_objects=custom_objects)
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/keras/layers/__init__.py", line 168, in deserialize
printable_module_name='layer')
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/keras/utils/generic_utils.py", line 147, in deserialize_keras_object
list(custom_objects.items())))
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/keras/engine/network.py", line 1075, in from_config
process_node(layer, node_data)
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/keras/engine/network.py", line 1025, in process_node
layer(unpack_singleton(input_tensors), **kwargs)
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py", line 75, in symbolic_fn_wrapper
return func(*args, **kwargs)
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/keras/engine/base_layer.py", line 446, in __call__
self.assert_input_compatibility(inputs)
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/keras/engine/base_layer.py", line 310, in assert_input_compatibility
K.is_keras_tensor(x)
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py", line 695, in is_keras_tensor
if not is_tensor(x):
File "/Users/grant/.pyenv/versions/deep-forest/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py", line 703, in is_tensor
return isinstance(x, tf_ops._TensorLike) or tf_ops.is_dense_tensor_like(x)
AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'
Desktop (please complete the following information):
- Mojave 10.14.6
- Python 3.7.5
- Environment managed with https://github.com/pyenv/pyenv-virtualenv
- Packages managed with pip (output following)
(deep-forest) (base) ➜ pip freeze
absl-py==0.11.0
astunparse==1.6.3
cachetools==4.2.0
certifi==2020.12.5
chardet==4.0.0
cycler==0.10.0
deepforest==0.3.4
flatbuffers==1.12
gast==0.3.3
google-auth==1.24.0
google-auth-oauthlib==0.4.2
google-pasta==0.2.0
grpcio==1.32.0
h5py==2.10.0
idna==2.10
importlib-metadata==3.3.0
Keras==2.3.0
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.2
keras-resnet==0.1.0
kiwisolver==1.3.1
Markdown==3.3.3
matplotlib==3.3.3
numpy==1.19.4
oauthlib==3.1.0
opencv-python==4.5.1.48
opt-einsum==3.3.0
pandas==1.2.0
Pillow==8.1.0
progressbar2==3.53.1
protobuf==3.14.0
psutil==5.8.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pyparsing==2.4.7
python-dateutil==2.8.1
python-utils==2.4.0
pytz==2020.5
PyYAML==5.3.1
requests==2.25.1
requests-oauthlib==1.3.0
rsa==4.6
scipy==1.6.0
six==1.15.0
slidingwindow==0.0.14
tensorboard==2.4.0
tensorboard-plugin-wit==1.7.0
tensorflow==2.4.0
tensorflow-estimator==2.4.0
termcolor==1.1.0
tqdm==4.55.1
typing-extensions==3.7.4.3
urllib3==1.26.2
Werkzeug==1.0.1
wrapt==1.12.1
xmltodict==0.12.0
zipp==3.4.0
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (4 by maintainers)
@baka-san , i’ve pushed a pypi version 0.3.5 and everything looks good. You should be able to pip install deepforest without issue. Please confirm and close.