AttributeError: 'module' Object Has No Attribute 'placeholder', How Can I Resolve This Problem?
When I run the code, that error message raise.
I'm using python 2.7.5, keras 2.2.4 and tensorflow 2.0.0-beta1. Somebody told me 'don't make file name tensorflow', but I didn't make like that. I think it might be occurred by changed items that is in upgraded tensorflow version, https://www.tensorflow.org/beta/guide/effective_tf2 , but the lower version also can't run with error that is "ValueError:bad marshal data". All the processes are running on virtual environment.
Error message is
Using TensorFlow backend.
WARNING: Logging before flag parsing goes to stderr.
W0619 16:47:38.715425 139651914356544 deprecation.py:323] From /home/sea/Programs/generalized-phase-detection/generalized-phase-detection-master/venv/lib/python2.7/site-packages/tensorflow/python/compat/v2_compat.py:65: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating:
non-resource variables are not supported in the long term
Traceback (most recent call last):
File "./gpd_predict.py", line 165, in <module>
model = model_from_json(loaded_model_json, custom_objects={'tf':tf})
File "/home/sea/Programs/generalized-phase-detection/generalized-phase-detection-master/venv/lib/python2.7/site-packages/keras/engine/saving.py", line 622, in model_from_json
return deserialize(config, custom_objects=custom_objects)
File "/home/sea/Programs/generalized-phase-detection/generalized-phase-detection-master/venv/lib/python2.7/site-packages/keras/layers/__init__.py", line 168, in deserialize
printable_module_name='layer')
File "/home/sea/Programs/generalized-phase-detection/generalized-phase-detection-master/venv/lib/python2.7/site-packages/keras/utils/generic_utils.py", line 147, in deserialize_keras_object
list(custom_objects.items())))
File "/home/sea/Programs/generalized-phase-detection/generalized-phase-detection-master/venv/lib/python2.7/site-packages/keras/engine/network.py", line 1043, in from_config
process_layer(layer_data)
File "/home/sea/Programs/generalized-phase-detection/generalized-phase-detection-master/venv/lib/python2.7/site-packages/keras/engine/network.py", line 1029, in process_layer
custom_objects=custom_objects)
File "/home/sea/Programs/generalized-phase-detection/generalized-phase-detection-master/venv/lib/python2.7/site-packages/keras/layers/__init__.py", line 168, in deserialize
printable_module_name='layer')
File "/home/sea/Programs/generalized-phase-detection/generalized-phase-detection-master/venv/lib/python2.7/site-packages/keras/utils/generic_utils.py", line 149, in deserialize_keras_object
return cls.from_config(config['config'])
File "/home/sea/Programs/generalized-phase-detection/generalized-phase-detection-master/venv/lib/python2.7/site-packages/keras/engine/base_layer.py", line 1103, in from_config
return cls(**config)
File "/home/sea/Programs/generalized-phase-detection/generalized-phase-detection-master/venv/lib/python2.7/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "/home/sea/Programs/generalized-phase-detection/generalized-phase-detection-master/venv/lib/python2.7/site-packages/keras/engine/input_layer.py", line 87, in __init__
name=self.name)
File "/home/sea/Programs/generalized-phase-detection/generalized-phase-detection-master/venv/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 529, in placeholder
x = tf.placeholder(dtype, shape=shape, name=name)
AttributeError: 'module' object has no attribute 'placeholder'
I don't know if this is a problem line, but this line is only my code in the error message. (last line)
# load json and create model
json_file = open('model_pol.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
model = model_from_json(loaded_model_json, custom_objects={'tf':tf})
How can I run the program without error code?
Answer
Tensorflow 2 is does not use placeholders by default so it is not available without using compatibility mode.
You could do
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
but, really, you probably want to migrate your code to best utelise v2. Check out the official guide here: https://www.tensorflow.org/beta/guide/migration_guide
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module