tflearn softmax输出不总和为1

时间:2017-06-06 17:24:45

标签: python tensorflow deep-learning softmax tflearn

我正在使用2层GRU进行多分类值的回归。 因此,我将最后一层的激活函数用作“softmax”,其输出需要总计为1。 但是,正如我使用测试集测试的那样,预测值的输出未添加到1(对于每个时间步长)。我检查了tflearn的“objective.py”中的“categorical_crossentropy”,但似乎定义是正确的(y_pred使用预测值)。

这是我的tflearn代码。我做错了吗?

Train_Label = np.zeros((num_Train, max_time, 3))

for i in range(num_Train):
    Train_Label[i,:, :] = tflearn.data_utils.to_categorical(tmp[i, :, 0], 3)

tf.reset_default_graph()

net = tflearn.input_data([None, max_time, num_Feature])    
net = tflearn.gru(net, num_Feature, activation='relu', inner_activation='sigmoid', return_seq=True, dynamic=True, weights_init='truncated_normal')
net = tf.stack(net, axis=1)
net = tflearn.gru(net, 3, activation='softmax', inner_activation='sigmoid', return_seq=True, dynamic=True, weights_init='truncated_normal')
output = tf.stack(net, axis=1) #output of encoder (stacked in terms of time axis)

net = tflearn.regression(output, optimizer='adam', learning_rate=0.0001, loss='categorical_crossentropy')
model = tflearn.DNN(net, tensorboard_verbose=0)
model.fit(Train_Feature, Train_Label, n_epoch = 10, show_metric=False, batch_size=10, shuffle=False)

tmp_score= np.array(model.predict(Test_Feature))

0 个答案:

没有答案