【发布时间】:2019-01-20 11:37:37
【问题描述】:
我有一个 Keras 模型 (.hdf5),我想将它部署在云中进行预测。我现在希望估计为此需要多少资源(CPU、GPU、RAM ......)。
有没有人对功能/经验法则有建议可以帮助解决这个问题?我找不到任何有用的东西。提前致谢!
【问题讨论】:
标签: tensorflow keras conv-neural-network
我有一个 Keras 模型 (.hdf5),我想将它部署在云中进行预测。我现在希望估计为此需要多少资源(CPU、GPU、RAM ......)。
有没有人对功能/经验法则有建议可以帮助解决这个问题?我找不到任何有用的东西。提前致谢!
【问题讨论】:
标签: tensorflow keras conv-neural-network
我认为最现实的估计是运行模型并查看它需要多少资源。 top 或 htop 将向您显示 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,看看会占用多少内存。
【讨论】: