我正在加载已保存的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
如果您使用的是Windows,则崩溃可能与https://github.com/zhuyifei1999/guppy3/issues/25有关。检查pywin32版本,如果是<;300,使用升级pywin32
相关问题 更多 >
编程相关推荐