Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'tensorflow._api.v2.compat.v1' has no attribute 'estimator' #160

Open
cirosantilli opened this issue Mar 24, 2024 · 4 comments

Comments

@cirosantilli
Copy link

cirosantilli commented Mar 24, 2024

Clone repo at 699b679 then try to run on a clean virtualenv:

tmp.py

#!/usr/bin/env python
from nsfw_detector import predict
model = predict.load_model('mobilenet_v2_140_224')
predict.classify(model, 'tmp.jpg')

blows up with:

2024-03-24 07:41:21.502070: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-03-24 07:41:21.502308: I external/local_tsl/tsl/cuda/cudart_stub.cc:32] Could not find cuda drivers on your machine, GPU will not be used.
2024-03-24 07:41:21.504877: I external/local_tsl/tsl/cuda/cudart_stub.cc:32] Could not find cuda drivers on your machine, GPU will not be used.
2024-03-24 07:41:21.533738: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX512F AVX512_VNNI AVX512_BF16 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-03-24 07:41:22.045317: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
Traceback (most recent call last):
  File "/home/ciro/tmp/nsfw_model/./tmp.py", line 2, in <module>
    from nsfw_detector import predict
  File "/home/ciro/tmp/nsfw_model/nsfw_detector/predict.py", line 11, in <module>
    import tensorflow_hub as hub
  File "/home/ciro/tmp/nsfw_model/.venv/lib/python3.11/site-packages/tensorflow_hub/__init__.py", line 88, in <module>
    from tensorflow_hub.estimator import LatestModuleExporter
  File "/home/ciro/tmp/nsfw_model/.venv/lib/python3.11/site-packages/tensorflow_hub/estimator.py", line 62, in <module>
    class LatestModuleExporter(tf.compat.v1.estimator.Exporter):
                               ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ciro/tmp/nsfw_model/.venv/lib/python3.11/site-packages/tensorflow/python/util/module_wrapper.py", line 232, in _getattr
    attr = getattr(self._tfmw_wrapped_module, name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'tensorflow._api.v2.compat.v1' has no attribute 'estimator'

Ubuntu 23.10, Python 3.11.6.

pip freeze contains:

absl-py==2.1.0                                                                                 
astunparse==1.6.3                                                                                                                                                                             
certifi==2024.2.2                                                                              
charset-normalizer==3.3.2                                                                      
flatbuffers==24.3.25                                                                                                                                                                          
gast==0.5.4                                   
google-pasta==0.2.0                                                                            
grpcio==1.63.0                                                                                 
h5py==3.11.0                                                                                   
idna==3.7                                                                                      
keras==3.3.3                                                                                   
libclang==18.1.1                                                                               
Markdown==3.6                                                                                  
markdown-it-py==3.0.0                                                                          
MarkupSafe==2.1.5                                                                              
mdurl==0.1.2                                                                                                                                                                                  
ml-dtypes==0.3.2                                                                                                                                                                              namex==0.0.8                                                                                                                                                                                  
numpy==1.26.4                                                                                                                                                                                 
opt-einsum==3.3.0                                                                                                                                                                             
optree==0.11.0                                                                                                                                                                                
packaging==24.0                                                                                                                                                                               
pillow==10.3.0                                                                                                                                                                                
protobuf==4.25.3                                                                                                                                                                              
Pygments==2.17.2                                                                                                                                                                              
requests==2.31.0                                                                               
rich==13.7.1                                                                                   
six==1.16.0                                   
tensorboard==2.16.2                                                                                                                                                                           
tensorboard-data-server==0.7.2                                                                 
tensorflow==2.16.1                                                                                                                                                                            
tensorflow-hub==0.12.0                                                                         
tensorflow-io-gcs-filesystem==0.37.0                                                           
termcolor==2.4.0                                                                                                                                                                              
typing_extensions==4.11.0                                                                      
urllib3==2.2.1                                                                                 
Werkzeug==3.0.2                                                                                
wrapt==1.16.0 
@ibrahemdhade33
Copy link

same issue here

@Winvoker
Copy link

Winvoker commented Apr 25, 2024

Did you find any solution?

Edit : works with python 3.6 and tensorflow==2.2.0

@cirosantilli
Copy link
Author

cirosantilli commented Apr 25, 2024

Edit : works with python 3.6 and tensorflow==2.2.0

Ah nice! Maintainers made the fatal mistake of using >= on requirements.txt:

tensorflow>=2.2.0;sys_platform != 'darwin'

@cirosantilli
Copy link
Author

That's annoying, on Python 3.11.6 I get:

$ pip install tensorflow==2.2.0
ERROR: Could not find a version that satisfies the requirement tensorflow==2.2.0 (from versions: 2.12.0rc0, 2.12.0rc1, 2.12.0, 2.12.1, 2.13.0rc0, 2.13.0rc1, 2.13.0rc2, 2.13.0, 2.13.1, 2.14.0rc0, 2.14.0rc1, 2.14.0, 2.14.1, 2.15.0rc0, 2.15.0rc1, 2.15.0, 2.15.0.post1, 2.15.1, 2.16.0rc0, 2.16.1)
ERROR: No matching distribution found for tensorflow==2.2.0

so you really have to go down the Python version... and pyenv install 3.6.0 segfaults...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants