我试着用tensorflow建立一个神经网络的隐藏层,但是我一直收到错误信息
“Operation”对象没有“dtype”属性。
这是代码抛出错误的地方:
codings = tf.layers.dense(X, n_hidden, name="hidden")
import numpy as np
import tensorflow as tf
from PIL import Image
data = []
test2 = Image.open("./ters/test2.jpg")
prepared_data = np.asarray(test2.resize((800, 1000), Image.ANTIALIAS))
data.append(prepared_data)
data = np.asarray(data)
saver = tf.train.import_meta_graph("./my_model.ckpt.meta")
batch_size, height, width, channels = data.shape
n_hidden = 400
X = tf.get_default_graph().get_operation_by_name("Placeholder")
training_op = tf.get_default_graph().get_operation_by_name("train/Adam")
codings = tf.layers.dense(X, n_hidden, tf.float32)
n_iterations = 5
with tf.Session() as sess:
saver.restore(sess, "./my_model.ckpt")
sess.run(training_op)
test_img = codings.eval(feed_dict={X: X_test})
print(test_img)
注:
我已经训练过这个模型并命名了它
我的模型.ckpt
这是错误消息:
Traceback (most recent call last):
File "using_img_cleaner.py", line 36, in <module>
codings = tf.layers.dense(X, n_hidden, tf.float32)
File "/home/exceptions/env/lib/python3.5/site-packages/tensorflow/python/layers/core.py", line 250, in dense
dtype=inputs.dtype.base_dtype,
AttributeError: 'Operation' object has no attribute 'dtype'