Tensorflow CPU内存问题(分配超过系统内存的10%)

6

我使用Keras/Tensorflow在python中创建了一个程序。对于我的数据的创建和训练,我没有任何问题。然而,当我想要评估我的模型时,出现了以下错误:

Using TensorFlow backend.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:4213: sparse_to_dense (from tensorflow.python.ops.sparse_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Create a `tf.sparse.SparseTensor` and use `tf.sparse.to_dense` instead.
2018-12-05 19:20:44.932780: W tensorflow/core/framework/allocator.cc:122] Allocation of 3359939800 exceeds 10% of system memory.
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Abandon (core dumped)

看起来是一个内存分配问题。虽然我减小了模型的大小并缩小了所有参数,但仍然没有改变。我不知道如何解决这个问题。


请参考以下链接:https://dev59.com/P1UL5IYBdhLWcg3weH4j - Framester
1个回答

3

根据我的经验,这种问题的常见原因是我们在训练时使用了合理的批量大小,但在评估时尝试使用更大的批量大小(通常是整个数据集)。

我发现自己会犯这种错误:

model.fit(x_train, y_train, epochs=5, batch_size=10)
model.evaluate(x_test, y_test)

我们实际上需要这样做:

model.fit(x_train, y_train, epochs=5, batch_size=10)
model.evaluate(x_test, y_test, 批量大小=10)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接