【问题标题】:Tensorflow CPU memory problem (allocation exceeds 10% of system memory)TensorFlow CPU 内存问题(分配超过系统内存的 10%)
【发布时间】:2019-05-07 10:07:30
【问题描述】:

我使用 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)

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

【问题讨论】:

标签: python tensorflow memory keras cpu


【解决方案1】:

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

我发现自己做这种事情是错误的:

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, batch_size=10)

【讨论】:

    猜你喜欢
    • 2018-10-22
    • 1970-01-01
    • 2019-06-06
    • 2013-07-30
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 2016-08-06
    • 1970-01-01
    相关资源
    最近更新 更多