简体   繁体   English

tensorflow ValueError:两个形状的尺寸0必须相等

[英]tensorflow ValueError: Dimension 0 in both shapes must be equal

I am currently studying TensorFlow. 我目前正在研究TensorFlow。 I am trying to create a NN which can accurately assess a prediction model and assign it a score. 我正在尝试创建一个可以准确评估预测模型并为其分配分数的NN。 My plan right now is to combine scores from already existing programs run them through a mlp while comparing them to true values. 我现在的计划是将已经存在的程序中的分数通过mlp进行运行,同时将它们与真实值进行比较。 I have played around with the MNIST data and I am trying to apply what I have learnt to my project. 我一直在处理MNIST数据,并试图将学到的知识应用到项目中。 Unfortunately i have a problem 不幸的是我有一个问题

def multilayer_perceptron(x, w1):
   # Hidden layer with RELU activation
   layer_1 = tf.matmul(x, w1)
   layer_1 = tf.nn.relu(layer_1)
   # Output layer with linear activation
   #out_layer = tf.matmul(layer_1, w2)
   return layer_1

def my_mlp (trainer, trainer_awn, learning_rate, training_epochs, n_hidden, n_input, n_output):
trX, trY= trainer, trainer_awn
#create placeholders
x = tf.placeholder(tf.float32, shape=[9517, 5])
y_ = tf.placeholder(tf.float32, shape=[9517, ])
#create initial weights
w1 = tf.Variable(tf.zeros([5, 1]))
#predicted class and loss function
y = multilayer_perceptron(x, w1)
cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(y, y_))
#training
train_step = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cross_entropy)
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
with tf.Session() as sess:
    # you need to initialize all variables
    sess.run(tf.initialize_all_variables())
    print("1")
    for i in range(training_epochs + 1):
        sess.run([train_step], feed_dict={x: [trX['V7'], trX['V8'], trX['V9'], trX['V10'], trX['V12']], y_: trY})
return 

The code gives me this error 代码给我这个错误

ValueError: Dimension 0 in both shapes must be equal, but are 9517 and 1

This error occurs when running the line for cross_entropy. 在为cross_entropy行时,会发生此错误。 I don't understand why this is happing, if you need any more information I would be happy to give it to you. 我不明白为什么会这样,如果您需要更多信息,我很乐意为您提供。

in your case, y has shape [9517, 1] while y_ has shape [9517]. 在您的情况下,y的形状为[9517,1],而y_的形状为[9517]。 they are not campatible. 他们不适合居住。 Please try to reshape y_ using tf.reshape(y_, [-1, 1]) 请尝试使用tf.reshape(y_,[-1,1])重塑y_

This was caused by the weights.hdf5 file being incompatible with the new data in the repository. 这是由于weights.hdf5文件与存储库中的新数据不兼容所致。 I have updated the repo and it should work now. 我已经更新了仓库,现在应该可以使用了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SHAP ValueError:两个形状中的维度 1 必须相等,但为 2 和 1。形状为 [?,2] 和 [?,1] - SHAP ValueError: Dimension 1 in both shapes must be equal, but are 2 and 1. Shapes are [?,2] and [?,1] 两个形状的维度 2 必须相等,但是是 3 和 1 - Dimension 2 in both shapes must be equal, but are 3 and 1 ValueError:两个形状中的维度 2 必须相等,但分别为 512 和 511。形状为 [?,384,512] 和 [?,384,511] - ValueError: Dimension 2 in both shapes must be equal, but are 512 and 511. Shapes are [?,384,512] and [?,384,511] keras使用权重加载模型,发出ValueError:两个形状的尺寸1必须相等,但分别为124和121 - keras use weight to load model, issue ValueError: Dimension 1 in both shapes must be equal, but are 124 and 121 Tensorflow LSTM错误(ValueError:形状必须等于等级,但为2和1) - Tensorflow LSTM Error (ValueError: Shapes must be equal rank, but are 2 and 1 ) Tensorflow ValueError:必须完全定义所有形状:[TensorShape([Dimension(None),Dimension(None),Dimension(3)]),TensorShape([]) - Tensorflow ValueError: All shapes must be fully defined: [TensorShape([Dimension(None), Dimension(None), Dimension(3)]), TensorShape([]) Tensorflow Transformer ValueError:维度必须为 5 但为 4 - Tensorflow Transformer ValueError: Dimension must be 5 but is 4 Tensorflow错误:ValueError:形状必须等于等级,但是2和1从形状1与其他形状合并 - Tensorflow Error: ValueError: Shapes must be equal rank, but are 2 and 1 From merging shape 1 with other shapes Tensorflow 尺寸问题:ValueError:形状 (3, 1) 和 (None, 3) 不兼容 - Tensorflow dimension issue: ValueError: Shapes (3, 1) and (None, 3) are incompatible Tensorflow:ValueError:尺寸必须相等 - Tensorflow : ValueError: Dimensions must be equal
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM