【问题标题】:Getting Memory usage of a tensorflow model with guppy.hpy() not working使用 guppy.hpy() 获取 tensorflow 模型的内存使用不工作
【发布时间】: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


    【解决方案1】:

    如果您使用的是 Windows,则崩溃可能与 https://github.com/zhuyifei1999/guppy3/issues/25 有关。检查 pywin32 版本,如果

    pip install -U pywin32
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-22
      • 1970-01-01
      • 2017-01-15
      • 1970-01-01
      • 1970-01-01
      • 2017-11-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多