为什么我在输出时得到 nan

  • 本文关键字:nan 输出 theano keras
  • 更新时间 :
  • 英文 :


关于任务:我有类距离作为输入,并希望获得类置信度(0.0 到 1.0 之间的数字)。所以我有这样的东西:

[
  [
    0.0,
    0.0,
    0.0,
    6.371921190238224,
    0.0,
    3.3287083713830516,
    7.085957828217146,
    7.747408965761948,
    5.498717498872398,
    5.498717498872398,
    5.498717498872398,
    5.498717498872398,
    8.529725281060978
  ],
  [
    6.396501448825533,
    0.0,
    0.0,
    5.217483270813266,
    0.0,
    5.319046151560534,
    5.823161030197735,
    3.8991256371824976,
    6.269856323952211,
    5.517874167220461,
    6.396501448825533,
    5.328678274963717,
    3.8991256371824976
  ],
]

结果

[
  [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
  [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
  ...
]

我有大约 200 个例子。我的网络构建代码是下一个:

def train(self, distances, classes):
    """
    Train network
    :param distances: array of distances to classes
    :type distances: list[list[float]]
    :param classes: array of class indicators
    :type classes: list[list[float]]
    """
    example_count, class_count = self._dimensions(distances, classes)
    self.model = Sequential()
    self.model.add(Dense(128, input_dim=class_count))
    self.model.add(Dense(class_count))
    self.model.compile(optimizer=SGD(), loss='mse')
    self.model.fit(array(distances), array(classes))

但是在训练期间我得到下一个输出:

Epoch 1/10
425/425 [==============================] - 0s - loss: nan     
Epoch 2/10
425/425 [==============================] - 0s - loss: nan     
Epoch 3/10
425/425 [==============================] - 0s - loss: nan     
Epoch 4/10
425/425 [==============================] - 0s - loss: nan     
Epoch 5/10
425/425 [==============================] - 0s - loss: nan     
Epoch 6/10
425/425 [==============================] - 0s - loss: nan     
Epoch 7/10
425/425 [==============================] - 0s - loss: nan     
Epoch 8/10
425/425 [==============================] - 0s - loss: nan     
Epoch 9/10
425/425 [==============================] - 0s - loss: nan     
Epoch 10/10
425/425 [==============================] - 0s - loss: nan    

当我尝试使用model.predict(numpy.array([[ 0.0, 0.0, 0.0, 6.371921190238224, 0.0, 3.3287083713830516, 7.085957828217146, 7.747408965761948, 5.498717498872398, 5.498717498872398, 5.498717498872398, 5.498717498872398, 8.529725281060978]]))(火车组的示例)时 - 我得到[[ nan nan nan nan nan nan nan nan nan nan nan nan nan]]

数据或建筑规范中可能出现什么问题?

似乎我的拟合参数(学习率和其他)错误。现在我有下一个代码(是的,我在测试期间将神经元添加到隐藏层并增加了训练周期计数):

    example_count, class_count = self._dimensions(distances, classes)
    self.model = Sequential()
    self.model.add(Dense(1024, input_dim=class_count))
    self.model.add(Dense(class_count))
    self.model.compile(optimizer=SGD(lr=0.002, momentum=0.0, decay=0.0, nesterov=True), loss='mse', metrics=['accuracy'])
    self.model.fit(array(distances), array(classes), nb_epoch=80)

它给了

...
Epoch 79/80
425/425 [==============================] - 0s - loss: 0.0381 - acc: 0.6729     
Epoch 80/80
425/425 [==============================] - 0s - loss: 0.0382 - acc: 0.6871     
[[ 0.19048974  0.1585739   0.28798762 -0.23555818  0.4293299   0.10981751
-0.08614585 -0.06363138  0.05927059  0.07283521 -0.07852616 -0.02396417
-0.28515971]]

不是一个好的精度,但主题问题解决了

相关内容

  • 没有找到相关文章

最新更新