notAI-tech / NudeNet

Lightweight nudity detection
https://nudenet.notai.tech/
GNU Affero General Public License v3.0
1.73k stars 336 forks source link

AttributeError: module 'tensorflow' has no attribute 'placeholder' #31

Closed ghost closed 4 years ago

ghost commented 4 years ago

Describe the bug and error messages (if any) When I try to run my code I get the following error: AttributeError: module 'tensorflow' has no attribute 'placeholder'

Here is the full trace:

$ python test.py
2020-02-16 12:25:55.443845: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-02-16 12:25:55.444326: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Using TensorFlow backend.
Traceback (most recent call last):
  File "test.py", line 4, in <module>
    classifier = NudeClassifier()
  File "C:\Users\Nicol\AppData\Local\Programs\Python\Python37\lib\site-packages\nudenet\classifier.py", line 56, in __init__
    Classifier.nsfw_model = keras.models.load_model(model_path)
  File "C:\Users\Nicol\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\engine\saving.py", line 419, in load_model
    model = _deserialize_model(f, custom_objects, compile)
  File "C:\Users\Nicol\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\engine\saving.py", line 225, in _deserialize_model
    model = model_from_config(model_config, custom_objects=custom_objects)
  File "C:\Users\Nicol\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\engine\saving.py", line 458, in model_from_config
    return deserialize(config, custom_objects=custom_objects)
  File "C:\Users\Nicol\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\layers\__init__.py", line 55, in deserialize
    printable_module_name='layer')
  File "C:\Users\Nicol\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\utils\generic_utils.py", line 145, in deserialize_keras_object
    list(custom_objects.items())))
  File "C:\Users\Nicol\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\engine\network.py", line 1022, in from_config
    process_layer(layer_data)
  File "C:\Users\Nicol\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\engine\network.py", line 1008, in process_layer
    custom_objects=custom_objects)
  File "C:\Users\Nicol\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\layers\__init__.py", line 55, in deserialize
    printable_module_name='layer')
  File "C:\Users\Nicol\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\utils\generic_utils.py", line 147, in deserialize_keras_object
    return cls.from_config(config['config'])
  File "C:\Users\Nicol\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\engine\base_layer.py", line 1109, in from_config
    return cls(**config)
  File "C:\Users\Nicol\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\Nicol\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\engine\input_layer.py", line 87, in __init__
    name=self.name)
  File "C:\Users\Nicol\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\backend\tensorflow_backend.py", line 517, in placeholder
    x = tf.placeholder(dtype, shape=shape, name=name)
AttributeError: module 'tensorflow' has no attribute 'placeholder'

**The code snippet which gave this error***

This is the script I am trying to run:

from nudenet import NudeClassifier
classifier = NudeClassifier()
classifier.classify('https://images.unsplash.com/photo-1450778869180-41d0601e046e?ixlib=rb-1.2.1&auto=format&fit=crop&w=1150&q=80')

Here's how I am running it: python test.py

Specify versions of the following libraries

  1. nudenet-1.1.0
  2. tensorflow-2.1.0-cp37-cp37m-win_amd64
  3. keras-2.2.4
  4. Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)]

Expected behavior I was expecting a JSON response like this: {'path_to_nude_image': {'safe': 5.8822202e-08, 'unsafe': 1.0}}

bedapudi6788 commented 4 years ago

Keras 2.2 versions do not support tf >= 2.1 as far as I am aware. Either downgrade your tensorflow or upgrade your keras.

The classifier is tested with tf 1.8 to 1.12 and keras 2.1 to 2.2
ghost commented 4 years ago

Thanks!