GantMan / nsfw_model

Keras model of NSFW detector
Other
1.67k stars 267 forks source link

ModuleNotFoundError: No module named 'tensorflow.python.training.tracking' #157

Closed tudubucket closed 4 months ago

tudubucket commented 4 months ago

I've recently got this error while making from nsfw_detector import predict. I am just running the example code from readme:

from nsfw_detector import predict

model = predict.load_model('./nsfw_mobilenet2.224x224.h5')

print(predict.classify(model, 'D:/images/image.jpg'))

This is the full output:

2024-03-01 13:37:55.562720: 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`.
WARNING:tensorflow:From C:\Users\PC\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.

WARNING:tensorflow:From C:\Users\PC\AppData\Local\Programs\Python\Python311\Lib\site-packages\tensorflow_estimator\python\estimator\util.py:74: The name tf.train.SessionRunHook is deprecated. Please use tf.estimator.SessionRunHook instead.

WARNING:tensorflow:From C:\Users\PC\AppData\Local\Programs\Python\Python311\Lib\site-packages\tensorflow_hub\native_module.py:92: The name tf.GraphKeys is deprecated. Please use tf.compat.v1.GraphKeys instead.

Traceback (most recent call last):
  File "d:\---\antinsfw.py", line 2, in <module>
    from nsfw_detector import predict
  File "C:\Users\PC\AppData\Local\Programs\Python\Python311\Lib\site-packages\nsfw_detector\predict.py", line 11, in <module>
    import tensorflow_hub as hub
  File "C:\Users\PC\AppData\Local\Programs\Python\Python311\Lib\site-packages\tensorflow_hub\__init__.py", line 93, in <module>
    from tensorflow_hub.feature_column_v2 import text_embedding_column_v2
  File "C:\Users\PC\AppData\Local\Programs\Python\Python311\Lib\site-packages\tensorflow_hub\feature_column_v2.py", line 24, in <module>
    from tensorflow_hub import keras_layer
  File "C:\Users\PC\AppData\Local\Programs\Python\Python311\Lib\site-packages\tensorflow_hub\keras_layer.py", line 27, in <module>
    from tensorflow.python.training.tracking import data_structures
ModuleNotFoundError: No module named 'tensorflow.python.training.tracking'

I'm running in Windows Python 3.11.5, all python package version can be found here: https://mystb.in/JewelFashionAndrews

tudubucket commented 4 months ago

update tensorflow-hub from 0.12.0 to 0.16.0 solved my problem.