gpt4 book ai didi

tensorflow - 估计服务 Keras 模型所需的资源

转载 作者:行者123 更新时间:2023-12-05 04:02:39 30 4
gpt4 key购买 nike

我有一个 Keras 模型 (.hdf5),我想将其部署在云端进行预测。我现在想估计为此需要多少资源(CPU、GPU、RAM 等)。

有没有人对功能/经验法则有帮助的建议?我找不到任何有用的东西。提前致谢!

最佳答案

我认为最现实的估计是运行模型并查看它需要多少资源。 tophtop 将显示 CPU 和 RAM 负载,但如果是 GPU 内存,它会稍微复杂一些,因为 TensorFlow(Keras 后端最流行的选项)出于性能原因保留所有可用内存。

您必须告诉 TensorFlow 不要占用所有可用内存,而是按需分配。以下是如何在 Keras 中执行此操作:

import tensorflow as tf
import keras.backend as K
config = tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction=0.2 # Initially allocate only 20% of memory
config.gpu_options.allow_growth = True # dynamically grow the memory used on the GPU
config.log_device_placement = True # to log device placement (on which device the operation ran)
# (nothing gets printed in Jupyter, only if you run it standalone)
sess = tf.Session(config=config)
K.set_session(sess) # set this TensorFlow session as the default session for Keras

https://github.com/keras-team/keras/issues/4161#issuecomment-366031228

然后,运行 watch nvidia-smi 并查看将占用多少内存。

关于tensorflow - 估计服务 Keras 模型所需的资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54276040/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com