Tensorflow RNN准确度和成本:NaN

时间:2017-01-13 08:16:02

标签: python tensorflow neural-network deep-learning recurrent-neural-network

我为一些信号及其一个热编码标签训练了RNN。在完成一些尺寸和形状不匹配之后,网络运行没有错误。但是我因损失和准确性而获得NaN。

Epoch 1 completed out of 10 loss: nan
Epoch 2 completed out of 10 loss: nan
Epoch 3 completed out of 10 loss: nan
Epoch 4 completed out of 10 loss: nan
Epoch 5 completed out of 10 loss: nan
Epoch 6 completed out of 10 loss: nan
Epoch 7 completed out of 10 loss: nan
Epoch 8 completed out of 10 loss: nan
Epoch 9 completed out of 10 loss: nan
Epoch 10 completed out of 10 loss: nan
Accuracy: nan

以下是我设置输入数据和标签的方法 -

"""Input signals"""
for X in range(no_tau):

    random.seed()
    tau = np.array([int(math.ceil(np.random.uniform(lorange, hirange)))])
    X= amplitude * np.exp(-t / tau)
    X = np.reshape(X, [-1, 1,1])
    #print(X)
"""Output labels"""
cn = 0
class1 = [0]
class2 = [1]
while (cn <no_tau):
    tau = np.array([int(math.ceil(np.random.uniform(lorange, hirange)))])
    if tau<500:
        label = one_hot(class1, num_labels=2)
    else:
        label = one_hot(class2, num_labels=2)
    cn = cn + 1
    print ('For tau value of', tau, 'label is', label)

我正在分批提供数据 -

        for epoch in range(hm_epochs):
            epoch_loss = 0
            i = 0
            while i < no_tau:
                start = i
                end = i + batch_size
                batch_x = np.array(X[start:end])
                batch_y = np.array(label[start:end])

                _, c = sess.run([optimizer, cost], feed_dict={x: batch_x, y: batch_y})
                epoch_loss += c
                i += batch_size

运行代码后,我得到的成本非常低或NaN。为了准确,我每次都会得到NaN。 我检查了一些相关的堆栈问题,但无法理解问题。请帮忙。

我的完整代码要点是here

0 个答案:

没有答案