TypeError:模型的输入张量必须是Keras张量。找到:Tensor(“Placeholder_3:0”,dtype = float32)(缺少Keras元数据)

时间:2017-04-20 04:18:11

标签: tensorflow deep-learning keras jupyter-notebook conv-neural-network

我的输入变量

IMG_SIZE_PX=50
SLICE_COUNT=20

n_classes=2

x=tf.placeholder('float')
y=tf.placeholder('float')

keep_rate=0.8
keep_prob=tf.placeholder(tf.float32)

我的卷积3d函数

def conv3d(x, W):
return tf.nn.conv3d(x, W, strides=[1,1,1,1,1], padding='SAME')

我的maxpooling 3d功能

def maxpool3d(x):
return tf.nn.max_pool3d(x, ksize=[1,2,2,2,1], strides=[1,2,2,2,1], 
padding='SAME')

这是我的网络

def convolutional_neural_network(x):

我的网络权重

weights = {'W_conv1':tf.Variable(tf.random_normal([3,3,3,1,32])),

           'W_conv2':tf.Variable(tf.random_normal([3,3,3,32,64])),
            'W_fc':tf.Variable(tf.random_normal([ 54080 ,1024])),#here 54080 
is the input tensor value
           'out':tf.Variable(tf.random_normal([1024, n_classes]))}

我的网络偏见

biases = {'b_conv1':tf.Variable(tf.random_normal([32])),
           'b_conv2':tf.Variable(tf.random_normal([64])),
            'b_fc':tf.Variable(tf.random_normal([1024])),
           'out':tf.Variable(tf.random_normal([n_classes]))}

这是我的输入x

x = tf.reshape(x, shape=[-1, IMG_SIZE_PX, IMG_SIZE_PX, SLICE_COUNT, 1])

我的2个隐藏层(卷积+最大化)

conv1 = tf.nn.relu(conv3d(x, weights['W_conv1']) + biases['b_conv1'])
conv1 = maxpool3d(conv1)
conv2 = tf.nn.relu(conv3d(conv1, weights['W_conv2']) + biases['b_conv2'])
conv2 = maxpool3d(conv2)

我完全连接的图层

 fc = tf.reshape(conv2,[-1,  54080 ])
fc = tf.nn.relu(tf.matmul(fc, weights['W_fc'])+biases['b_fc'])
fc = tf.nn.dropout(fc, keep_rate)

我的输出图层

output = tf.matmul(fc, weights['out'])+biases['out']
return output

我的输入numpy数组

much_data = np.load('D:/muchdata-50-50-20.npy')
train_data = much_data[-10:]
validation_data = much_data[-2:]

终于训练我的网络了

 def train_neural_network(x):
 outl = convolutional_neural_network(x)#don't know this is my output 
layer
 model=Model(input=x, output=outl)
 model.compile(optimizer='rmsprop',loss='categorical_crossentropy',metrics=
['accuracy'])
train_neural_network(x)#train the net

我的错误是keras meta data is missing 任何帮助都可以得到赞赏

0 个答案:

没有答案