python-3.x - 为什么 tf.keras model.fit() 初始化需要这么长时间?如何优化?

标签 python-3.x tensorflow tf.keras

使用 tensorflow.keras(支持 GPU 的 2.0-alpha0)我在新编译的模型和之前保存和重新加载的模型上使用 tf.keras.model.fit() 的初始化时间非常长。

我相信这是在 tf.data.Datasets() 已经加载和预处理之后,所以我不明白是什么花了这么长时间并且 TF/Keras 没有输出:

2019-04-19 23:29:18.109067: tensorflow/core/common_runtime/gpu/gpu_device.cc:1149] Created TensorFlow device
Resizing images and creating data sets with num_parallel_calls=8
Loading existing model to continue training.
Starting model.fit()
Epoch 1/100
2019-04-19 23:32:22.934394: tensorflow/core/kernels/data/shuffle_dataset_op.cc:150] Shuffle buffer filled.
2019-04-19 23:38:52.374924: tensorflow/core/common_runtime/bfc_allocator.cc:230] Allocator (GPU_0_bfc) ran out of memory trying to allocate 2.62GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.

3 分钟加载模型并填充 shuffle 缓冲区,6 分钟用于……什么?而这个神秘的作品又该如何优化呢? (5GHz 8700K、32 GB RAM、NVME SSD、1080ti 11G DDR5 - 任务管理器显示 100% 单线程 CPU 使用率、中等磁盘访问、缓慢将 RAM 使用率扩展到最大 ~28GB,在此期间 GPU 使用率为零)。

有没有办法以更有效的方式序列化或存储模型,以便它们可以定期启动和停止而无需 10 分钟的开销?

在此期间,TF/Keras 是否以某种方式延迟加载数据集并对其进行预处理?

最佳答案

为 tf.data.Datasets() 使用多个工作人员似乎是一个问题。从日志消息中,它显示您正在使用 8 个并行进程,这可以解释为什么您显示如此高的 CPU/RAM 使用率。所以这不是模型的问题。
据我所知,您第一次使用 Datasets 应该相当慢,但是在数据被缓存后它会变得更快。
如果 model.fit() 调用的启动速度仍然很慢,您可以将进程数调整为 4 或 2。这可能会影响您的训练时间,因为您的 SSD 可能会因必须加载数据而变慢。

关于python-3.x - 为什么 tf.keras model.fit() 初始化需要这么长时间?如何优化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55770407/

相关文章:

python - 如何通过函数返回 *args, **kwargs

python-3.x - 使用 urllib.request 查询具有一系列 x-api-key header 的 url

python - Seq2Seq 模型学会在几次迭代后只输出 EOS token (<\s>)

python - 如何使用 tf.keras 在 RNN 中应用层归一化?

anaconda - 我无法加载我已经训练和保存的 nn 模型

python - Maya Python 3x - 基于法线角度选择边

python - for 循环和 'numpy.float64' object is not iterable 错误

tensorflow - Swift 中 Vision/CoreML 对象识别器的精度

python - 为什么每次我在这个特定数据集上运行 train-test split 时我的内核都会死掉?

lstm - 将 LSTM/GRU 添加到 keras tensorflow 中的 BERT 嵌入