【发布时间】:2021-09-07 03:30:03
【问题描述】:
我正在加载一个已保存的 tensorflow 模型(.pb 文件)并尝试评估它为带有 guppy 包的模型分配了多少内存。在simple tutorial 之后,这是我尝试过的:
from guppy import hpy
import tensorflow as tf
heap = hpy()
print("Heap Status at starting: ")
heap_status1 = heap.heap()
print("Heap Size : ", heap_status1.size, " bytes\n")
print(heap_status1)
heap.setref()
print("\nHeap Status after setting reference point: ")
heap_status2 = heap.heap()
print("Heap size: ", heap_status2.size, " bytes\n")
print(heap_status2)
model_path = "./saved_model/" #.pb file directory
model = tf.saved_model.load(model_path)
print("\nHeap status after creating model: ")
heap_status3 = heap.heap()
print("Heap size: ", heap_status3.size, " bytes\n")
print(heap_status3)
print("Memory used by the model: ", heap_status3.size - heap_status2.size)
我不知道为什么,但是当我运行代码时,当我调用heap_status1 = heap.heap() 时它突然停止执行。它不会抛出任何错误。
当我不使用任何与 tensorflow 相关的东西时,相同的代码运行良好,即当我只创建一些随机列表、字符串等而不是加载 tensorflow 模型时,它运行成功。
注意:我的模型将在 CPU 设备中运行。不幸的是,tf.config.experimental.get_memory_info 仅适用于 GPU。
【问题讨论】:
标签: python tensorflow memory tensorflow2.0 tensorflow-serving