訓練神經網路3
問題解決:
上面定義與下面呼叫的引數不一致,導致出現了錯誤
import出現了新錯誤:numpy as np
import
tensorflow as tf
import
matplotlib.pyplot as plt
import
input_data
mnist = input_data.read_data_sets('
data/
',one_hot=true) #
one_hot=true編碼格式為01編碼
n_hidden_1 = 256n_hidden_2 = 128n_input = 784n_classes = 10x = tf.placeholder("
float
",[none,n_input])
y = tf.placeholder("
float
",[none,n_classes])
stddev = 0.1weights =
biases =
print("
network ready")
defmultilayer_perceptron(_x,_weights,_biases):
layer_1 = tf.nn.sigmoid(tf.add(tf.matmul(_x,_weights['
w1']),_biases['b1'
])) layer_2 = tf.nn.sigmoid(tf.add(tf.matmul(layer_1,_weights['
w2']),_biases['b2'
]))
return (tf.matmul(layer_2,_weights['
out']) + _biases['
out'
])pred =multilayer_perceptron(x, weights, biases)
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(pred,y)) #
tensorflow中已有的交叉熵函式
optm = tf.train.gradientdescentoptimizer(learning_rate=0.01).minimize(cost)
corr = tf.equal(tf.argmax(pred,1),tf.argmax(y,1))
accr = tf.reduce_mean(tf.cast(corr,"
float"))
init =tf.compat.v1.global_variables_initializer()
print("
functions ready
")
可以改成:
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(pred,y))或:
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y, logits=pred))
tensorflow學習筆記1
在跑minist demo時,遇到了這幾句 batchsize 6 label tf.expand dims tf.constant 0,2,3,6,7,9 1 index tf.expand dims tf.range 0,batchsize 1 concated tf.concat 1,inde...
TensorFlow學習筆記1
1 tensorflow 谷歌第二代人工智慧學習系統 2 tensorflow顧名思義tensor flow。tensor的意思是 張量,flow的意思是 流動,合起來就是 張量的流動 3 系統架構及程式設計模型。其中系統架構如圖1所示,程式設計模型如圖2所示。圖1 tensorflow系統架構圖 ...
TensorFlow學習筆記1
編寫tensorflow的兩個步驟 構建計算圖graph 使用session去執行graph中的operation 這裡寫描述 三個基本概念 rank rank一般是指資料的維度,其與線性代數中的rank不是乙個概念。其常 用rank舉例如下。shape 指tensor每個維度資料的個數,可以用py...