【发布时间】:2020-12-13 11:33:31
【问题描述】:
我正在尝试使用 softmax 对 cifar10 图像进行分类,但模型没有学习任何东西。
下面的代码打印
0 None
1 None
2 None
等等。如何修复我的代码或弄清楚为什么它总是无?
import tensorflow as tf
import numpy as np
from tensorflow.keras.datasets import cifar10, mnist
(x_train,y_train),(x_test,y_test) = cifar10.load_data()
x = tf.placeholder(tf.float32,[None,3072])
y_ = tf.placeholder(tf.float32,[None])
x_train = x_train.astype('float32')
x_test = x_test.astype('float32')
#reshaping the y_train and x_train
y_train = y_train.reshape((5000,10))
x_test =x_test.reshape(10000,3072)
x_train = x_train.reshape(50000,3072)
y_test =y_test.reshape(1000,10)
# Data normalization
x_train = x_train/255
y_train = y_train/255
W1 = tf.Variable(tf.zeros([3072,10]))
b1 = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x,W1)+b1)
# this is a cross entropy
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y),reduction_indices=[1]))
# let's train to get the minimum loss using back+forward propagation
train_step = tf.train.AdamOptimizer(0.5).minimize(cross_entropy)
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
for i in range(1000):
for j in range(50):
print(j,sess.run(train_step,feed_dict={x : x_train , y_ : y_train[j]}))
【问题讨论】:
-
请不要将您的文本格式化为引号(已编辑)。
标签: python tensorflow deep-learning