최근 mnist tensorflow 안내서를 작성하여 조금 변경하려고했습니다. 이 예제에서는 28 * 28 * 3 (r, g, b의 경우 3)의 입력을 얻으려고 시도하고 똑같은 출력을 돌려줍니다. 쉽게 나는 순수한 흰색을 안팎으로하고 있습니다.tensorflow 예측에 모두 0이 포함되어 있습니다.
#!/usr/bin/env python
import tensorflow as tf
input_layer_size = 2352 # number of pixels * number of color channels (rgb)
white = [255] * input_layer_size # white is a square of white pixels
white = [white]
sess = tf.InteractiveSession()
x = tf.placeholder(tf.float32, shape=[None, input_layer_size])
y_ = tf.placeholder(tf.float32, shape=[None, input_layer_size])
W = tf.Variable(tf.truncated_normal([input_layer_size,input_layer_size], stddev=0.1))
b = tf.Variable(tf.truncated_normal([input_layer_size], stddev=0.1))
sess.run(tf.initialize_all_variables())
y = tf.nn.softmax(tf.matmul(x,W) + b)
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(tf.clip_by_value(y, 1e-10, 1.0)), reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
for i in range(100):
train_step.run(feed_dict={x: white, y_: white})
feed_dict = {x:white}
classification = sess.run(y, feed_dict)
print ("Output:", classification[0])
어떤 이유로이 출력은 [ 0., 0., 0., ..., 0., 0., 0.]
입니다. 예상 결과가 아닌 이유는 무엇입니까 ([ 255., 255., ... ]
)?
나는 똑같은 코드를 mnist 데이터와 함께 시도해 보았고 정상적으로 작동하여 10 개의 출력 채널에 각각 적절한 결과를 제공했습니다.
그러나 원래 코드의 문제점은 무엇입니까? –
여러 가지가 잘못되었습니다. –
위의 사고 설명을 무시하십시오. 여러 가지가 잘못되었습니다. y는 손실을 최소화하기 위해 약 1e-10, 1 범위로 클리핑되지만, 손실 자체 (softmax의 교차 엔트로피)는 다중 클래스 분류 문제이지만 회귀 문제는 아닙니다. –