为什么会出现AttributeError:“模块”对象没有属性“占位符”?

时间:2019-11-17 21:49:23

标签: python tensorflow machine-learning keras attributeerror

我正在尝试制作一个基本的机器学习应用程序,该应用程序允许用户上传图像并通过模型运行它。尝试导入模型和权重时遇到此错误。

`json_file = open('model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
loaded_model.load_weights("model.h5")`

我收到此错误:

File "flasktesting2.py", line 17, in <module>
loaded_model = model_from_json(loaded_model_json)
File "/Users/adityasridhar/Library/Python/2.7/lib/python/site- 
packages/keras/engine/saving.py", line 492, in model_from_json
return deserialize(config, custom_objects=custom_objects)
File "/Users/adityasridhar/Library/Python/2.7/lib/python/site- 
packages/keras/layers/__init__.py", line 55, in deserialize
printable_module_name='layer')
File "/Users/adityasridhar/Library/Python/2.7/lib/python/site- 
packages/keras/utils/generic_utils.py", line 145, in 
deserialize_keras_object
list(custom_objects.items())))
File "/Users/adityasridhar/Library/Python/2.7/lib/python/site- 
packages/keras/engine/sequential.py", line 301, in from_config
model.add(layer)
File "/Users/adityasridhar/Library/Python/2.7/lib/python/site- 
packages/keras/engine/sequential.py", line 161, in add
name=layer.name + '_input')
File "/Users/adityasridhar/Library/Python/2.7/lib/python/site- 
packages/keras/engine/input_layer.py", line 178, in Input
input_tensor=tensor)
File "/Users/adityasridhar/Library/Python/2.7/lib/python/site- 
packages/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "/Users/adityasridhar/Library/Python/2.7/lib/python/site- 
packages/keras/engine/input_layer.py", line 87, in __init__
name=self.name)
File "/Users/adityasridhar/Library/Python/2.7/lib/python/site- 
packages/keras/backend/tensorflow_backend.py", line 517, in placeholder
x = tf.placeholder(dtype, shape=shape, name=name)
AttributeError: 'module' object has no attribute 'placeholder'

我已经重新安装了tensorflow和keras,并确保我所有的API都是最新的。我还检查了文件名是否一致(例如tensorflow.py)。有人知道为什么会这样吗?

0 个答案:

没有答案