【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: [].问题
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
基于TensorFlow訓(xùn)練mnist數(shù)據(jù)集出現(xiàn)如下錯(cuò)誤:
檢測(cè)代碼,發(fā)現(xiàn)是偏置設(shè)置格式錯(cuò)誤導(dǎo)致。
1、錯(cuò)誤代碼:?
# 定義權(quán)重和偏置 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的"()"改為"[]"
#定義權(quán)重和偏置 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)) }?
總結(jié)
以上是生活随笔為你收集整理的【TensorFlow】ValueError: Shape must be rank 1 but is rank 0 for ' ’ with input shapes: [].问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【TensorFlow】PyCharm中
- 下一篇: 【Python】raise ValueE