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-forest
    • pyenv 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

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):

(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)

Most upvoted comments

@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.

(base) benweinstein@Bens-MacBook-Pro DeepForest % conda create --name test python=3.7
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /Users/benweinstein/opt/miniconda3/envs/test

  added / updated specs:
    - python=3.7


The following NEW packages will be INSTALLED:

  ca-certificates    pkgs/main/osx-64::ca-certificates-2020.12.8-hecd8cb5_0
  certifi            pkgs/main/osx-64::certifi-2020.12.5-py37hecd8cb5_0
  libcxx             pkgs/main/osx-64::libcxx-10.0.0-1
  libedit            pkgs/main/osx-64::libedit-3.1.20191231-h1de35cc_1
  libffi             pkgs/main/osx-64::libffi-3.3-hb1e8313_2
  ncurses            pkgs/main/osx-64::ncurses-6.2-h0a44026_1
  openssl            pkgs/main/osx-64::openssl-1.1.1i-h9ed2024_0
  pip                pkgs/main/osx-64::pip-20.3.3-py37hecd8cb5_0
  python             pkgs/main/osx-64::python-3.7.9-h26836e1_0
  readline           pkgs/main/osx-64::readline-8.0-h1de35cc_0
  setuptools         pkgs/main/osx-64::setuptools-51.0.0-py37hecd8cb5_2
  sqlite             pkgs/main/osx-64::sqlite-3.33.0-hffcf06c_0
  tk                 pkgs/main/osx-64::tk-8.6.10-hb0a8c7a_0
  wheel              pkgs/main/noarch::wheel-0.36.2-pyhd3eb1b0_0
  xz                 pkgs/main/osx-64::xz-5.2.5-h1de35cc_0
  zlib               pkgs/main/osx-64::zlib-1.2.11-h1de35cc_3


Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: \ |/- \/done
Executing transaction: \/ -\|/-\/-\
-|done
p#
# To activate this environment, use
#
#     $ conda activate test
#
# To deactivate an active environment, use
#
#     $ conda deactivate

 %
(base) benweinstein@Bens-MacBook-Pro DeepForest % conda activate test
pip i%
(test) benweinstein@Bens-MacBook-Pro DeepForest % pip install deepforest
Collecting deepforest
  Downloading deepforest-0.3.5-cp37-cp37m-macosx_10_6_intel.whl (9.2 MB)
     |████████████████████████████████| 9.2 MB 2.7 MB/s
Collecting h5py==2.10.0
  Using cached h5py-2.10.0-cp37-cp37m-macosx_10_6_intel.whl (3.0 MB)
Collecting keras==2.3.0
  Using cached Keras-2.3.0-py2.py3-none-any.whl (377 kB)
Collecting keras-resnet==0.1.0
  Using cached keras_resnet-0.1.0-py2.py3-none-any.whl
Collecting tensorflow==1.14.0
  Using cached tensorflow-1.14.0-cp37-cp37m-macosx_10_11_x86_64.whl (105.8 MB)
Requirement already satisfied: wheel>=0.26 in /Users/benweinstein/opt/miniconda3/envs/test/lib/python3.7/site-packages (from tensorflow==1.14.0->deepforest) (0.36.2)
Collecting absl-py>=0.7.0
  Using cached absl_py-0.11.0-py3-none-any.whl (127 kB)
Collecting astor>=0.6.0
  Using cached astor-0.8.1-py2.py3-none-any.whl (27 kB)
Collecting gast>=0.2.0
  Using cached gast-0.4.0-py3-none-any.whl (9.8 kB)
Collecting google-pasta>=0.1.6
  Using cached google_pasta-0.2.0-py3-none-any.whl (57 kB)
Collecting grpcio>=1.8.6
  Using cached grpcio-1.34.0-cp37-cp37m-macosx_10_10_x86_64.whl (3.6 MB)
Collecting keras-applications>=1.0.6
  Using cached Keras_Applications-1.0.8-py3-none-any.whl (50 kB)
Collecting keras-preprocessing>=1.0.5
  Using cached Keras_Preprocessing-1.1.2-py2.py3-none-any.whl (42 kB)
Collecting numpy>=1.7
  Using cached numpy-1.19.5-cp37-cp37m-macosx_10_9_x86_64.whl (15.6 MB)
Collecting protobuf>=3.6.1
  Using cached protobuf-3.14.0-cp37-cp37m-macosx_10_9_x86_64.whl (1.0 MB)
Collecting pyyaml>5.1.0
  Using cached PyYAML-5.3.1-cp37-cp37m-macosx_10_9_x86_64.whl
Collecting scipy
  Using cached scipy-1.6.0-cp37-cp37m-macosx_10_9_x86_64.whl (30.7 MB)
Collecting six
  Using cached six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting tensorboard<1.15.0,>=1.14.0
  Using cached tensorboard-1.14.0-py3-none-any.whl (3.1 MB)
Requirement already satisfied: setuptools>=41.0.0 in /Users/benweinstein/opt/miniconda3/envs/test/lib/python3.7/site-packages (from tensorboard<1.15.0,>=1.14.0->tensorflow==1.14.0->deepforest) (51.0.0.post20201207)
Collecting markdown>=2.6.8
  Using cached Markdown-3.3.3-py3-none-any.whl (96 kB)
Collecting tensorflow-estimator<1.15.0rc0,>=1.14.0rc0
  Using cached tensorflow_estimator-1.14.0-py2.py3-none-any.whl (488 kB)
Collecting termcolor>=1.1.0
  Using cached termcolor-1.1.0-py3-none-any.whl
Collecting werkzeug>=0.11.15
  Using cached Werkzeug-1.0.1-py2.py3-none-any.whl (298 kB)
Collecting wrapt>=1.11.1
  Using cached wrapt-1.12.1-cp37-cp37m-macosx_10_9_x86_64.whl
Collecting importlib-metadata
  Using cached importlib_metadata-3.3.0-py3-none-any.whl (10 kB)
Collecting typing-extensions>=3.6.4
  Using cached typing_extensions-3.7.4.3-py3-none-any.whl (22 kB)
Collecting zipp>=0.5
  Using cached zipp-3.4.0-py3-none-any.whl (5.2 kB)
Collecting matplotlib
  Using cached matplotlib-3.3.3-cp37-cp37m-macosx_10_9_x86_64.whl (8.5 MB)
Collecting cycler>=0.10
  Using cached cycler-0.10.0-py2.py3-none-any.whl (6.5 kB)
Collecting kiwisolver>=1.0.1
  Using cached kiwisolver-1.3.1-cp37-cp37m-macosx_10_9_x86_64.whl (61 kB)
Collecting Pillow
  Using cached Pillow-8.1.0-cp37-cp37m-macosx_10_10_x86_64.whl (2.2 MB)
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3
  Using cached pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)
Collecting python-dateutil>=2.1
  Using cached python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
Collecting opencv-python
  Using cached opencv_python-4.5.1.48-cp37-cp37m-macosx_10_13_x86_64.whl (40.3 MB)
Collecting pandas
  Using cached pandas-1.2.0-cp37-cp37m-macosx_10_9_x86_64.whl (10.3 MB)
Collecting pytz>=2017.3
  Using cached pytz-2020.5-py2.py3-none-any.whl (510 kB)
Collecting progressbar2
  Using cached progressbar2-3.53.1-py2.py3-none-any.whl (25 kB)
Collecting python-utils>=2.3.0
  Using cached python_utils-2.4.0-py2.py3-none-any.whl (12 kB)
Collecting slidingwindow
  Using cached slidingwindow-0.0.14-py3-none-any.whl (9.0 kB)
Collecting psutil
  Using cached psutil-5.8.0-cp37-cp37m-macosx_10_9_x86_64.whl (236 kB)
Collecting tqdm
  Using cached tqdm-4.55.1-py2.py3-none-any.whl (68 kB)
Collecting xmltodict
  Using cached xmltodict-0.12.0-py2.py3-none-any.whl (9.2 kB)
Installing collected packages: zipp, typing-extensions, six, numpy, importlib-metadata, h5py, werkzeug, scipy, pyyaml, protobuf, markdown, keras-preprocessing, keras-applications, grpcio, absl-py, wrapt, termcolor, tensorflow-estimator, tensorboard, pytz, python-utils, python-dateutil, pyparsing, psutil, Pillow, kiwisolver, keras, google-pasta, gast, cycler, astor, xmltodict, tqdm, tensorflow, slidingwindow, progressbar2, pandas, opencv-python, matplotlib, keras-resnet, deepforest
Successfully installed Pillow-8.1.0 absl-py-0.11.0 astor-0.8.1 cycler-0.10.0 deepforest-0.3.5 gast-0.4.0 google-pasta-0.2.0 grpcio-1.34.0 h5py-2.10.0 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.5 opencv-python-4.5.1.48 pandas-1.2.0 progressbar2-3.53.1 protobuf-3.14.0 psutil-5.8.0 pyparsing-2.4.7 python-dateutil-2.8.1 python-utils-2.4.0 pytz-2020.5 pyyaml-5.3.1 scipy-1.6.0 six-1.15.0 slidingwindow-0.0.14 tensorboard-1.14.0 tensorflow-1.14.0 tensorflow-estimator-1.14.0 termcolor-1.1.0 tqdm-4.55.1 typing-extensions-3.7.4.3 werkzeug-1.0.1 wrapt-1.12.1 xmltodict-0.12.0 zipp-3.4.0
(test) benweinstein@Bens-MacBook-Pro DeepForest % python
Python 3.7.9 (default, Aug 31 2020, 07:22:35)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
tf.__version__/Users/benweinstein/opt/miniconda3/envs/test/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/Users/benweinstein/opt/miniconda3/envs/test/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/Users/benweinstein/opt/miniconda3/envs/test/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/Users/benweinstein/opt/miniconda3/envs/test/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/Users/benweinstein/opt/miniconda3/envs/test/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/Users/benweinstein/opt/miniconda3/envs/test/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
/Users/benweinstein/opt/miniconda3/envs/test/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/Users/benweinstein/opt/miniconda3/envs/test/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/Users/benweinstein/opt/miniconda3/envs/test/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/Users/benweinstein/opt/miniconda3/envs/test/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/Users/benweinstein/opt/miniconda3/envs/test/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/Users/benweinstein/opt/miniconda3/envs/test/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
>>> tf.__version__
'1.14.0'