【TensorFlow】ValueError: Shape must be rank 1 but is rank 0 for ' ’ with input shapes: [].问题
生活随笔
收集整理的这篇文章主要介绍了
【TensorFlow】ValueError: Shape must be rank 1 but is rank 0 for ' ’ with input shapes: [].问题
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
基于TensorFlow训练mnist数据集出现如下错误:
检测代码,发现是偏置设置格式错误导致。
1、错误代码:
# 定义权重和偏置 n_input = 784 n_output = 10 weights = {'wc1': tf.Variable(tf.random_normal([3, 3, 1, 64], stddev=0.1)),'wc2': tf.Variable(tf.random_normal([3, 3, 64, 128], stddev=0.1)),'wd1': tf.Variable(tf.random_normal([7 * 7 * 128, 1024], stddev=0.1)),'wd2': tf.Variable(tf.random_normal([1024, n_output], stddev=0.1)) } biases = {'bc1': tf.Variable(tf.random_normal(64), stddev=0.1),'bc2': tf.Variable(tf.random_normal(128), stddev=0.1),'bd1': tf.Variable(tf.random_normal(1024), stddev=0.1),'bd2': tf.Variable(tf.random_normal(n_output), stddev=0.1) }2、修改后的代码如下:
把biases的"()"改为"[]"
#定义权重和偏置 n_input = 784 n_output= 10 weights = {'wc1':tf.Variable(tf.random_normal([3,3,1,64], stddev=0.1)),'wc2':tf.Variable(tf.random_normal([3,3,64,128],stddev=0.1)),'wd1':tf.Variable(tf.random_normal([7*7*128,1024],stddev=0.1)),'wd2':tf.Variable(tf.random_normal([1024,n_output],stddev=0.1)) } biases = {'bc1':tf.Variable(tf.random_normal([64], stddev=0.1)),'bc2':tf.Variable(tf.random_normal([128],stddev=0.1)),'bd1':tf.Variable(tf.random_normal([1024],stddev=0.1)),'bd2':tf.Variable(tf.random_normal([n_output],stddev=0.1)) }
总结
以上是生活随笔为你收集整理的【TensorFlow】ValueError: Shape must be rank 1 but is rank 0 for ' ’ with input shapes: [].问题的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 【TensorFlow】PyCharm中
- 下一篇: 【智能驾驶】车道线检测中的新IPM(逆透