【问题标题】:TensorBoard hangs when visualizing an Object Detection graph可视化对象检测图时 TensorBoard 挂起
【发布时间】:2021-01-01 17:32:29
【问题描述】:

我需要可视化 TensorFlow 对象检测模型的结构。我正在尝试通过以下代码在 Colab 中使用 TensorBoard。当 TensorBoard 加载日志时,它会卡在“命名空间层次结构:查找相似子图”这一步。

!pip install -U tensorflow

import tensorflow as tf

from tensorflow.python.client import session  
from tensorflow.python.framework import ops  
from tensorflow.python.tools import saved_model_utils
from tensorflow.python.framework import importer
from tensorflow.python.summary import summary

!wget http://download.tensorflow.org/models/object_detection/tf2/20200711/ssd_resnet50_v1_fpn_640x640_coco17_tpu-8.tar.gz
!tar -xf ssd_resnet50_v1_fpn_640x640_coco17_tpu-8.tar.gz

%load_ext tensorboard

log_dir = '/content/logs'
tag_set = "serve"
model_dir = '/content/ssd_resnet50_v1_fpn_640x640_coco17_tpu-8/saved_model'

with session.Session(graph=ops.Graph()) as sess:
  input_graph_def = saved_model_utils.get_meta_graph_def(model_dir,
                                                        tag_set).graph_def
  importer.import_graph_def(input_graph_def)

  pb_visual_writer = summary.FileWriter(log_dir)
  pb_visual_writer.add_graph(sess.graph)
  print("Model Imported. Visualize by running: "
        "tensorboard --logdir={}".format(log_dir))

%tensorboard --logdir=$log_dir

这是笔记本的链接:https://colab.research.google.com/drive/1MrbNJYR2ds8RRgIBvgUgAILw0Jwdygui?usp=sharing。

环境: 浏览器:铬 操作系统:Windows 内存:8 GB

最终,我开始收到以下错误。

仅供参考,我尝试在具有 4 GB RAM 的 Windows 计算机上运行相同的进程,并在 shell 中运行 TensorBoard 服务器。我使用默认 URL(在笔记本之外)访问了 TensorBoard。它在启动过程中的同一点失败。

我看到Tensorboard got stuck in 'namespace hierarchy finding similar subgraphs' 和I'm struggling to implement tensorboard monitoring into the Mask_RCNN training process 提出了类似的问题,但没有提供答案。

提前致谢 -- 这对我正在为我的公司做的重要项目非常有帮助。

【问题讨论】:

    标签: google-colaboratory tensorflow2.0 tensorboard


    【解决方案1】:

    我相信我现在知道如何解决 3 个问题。

    1. RAM/CPU 不足 -> 在资源较多的计算机上运行
    2. 复杂图形,需要放大 -> 使用缩放查看节点
    3. 变量未初始化 -> 评估模型以显示图形边缘

    1。 RAM/CPU 不足

    在具有 24 GB RAM 和 8 个 i7 内核的 Windows 计算机上运行该过程为我消除了崩溃。有时我会收到有关页面无响应的消息,但您只需单击“等待”按钮即可加载。加载本身也快得多。

    2。图复杂,需要放大

    运行上述代码,TensorBoard 会显示一个空白屏幕。但是,图形节点的轮廓很模糊。

    放大以查看详细信息。屏幕右下角的导航框很有帮助。

    3。初始化变量

    代替我上面问题中的代码,使用以下代码:

    import tensorflow as tf
    import numpy as np
    
    !pip install -U tensorflow
    
    %load_ext tensorboard
    
    # Download model
    !wget http://download.tensorflow.org/models/object_detection/tf2/20200711/ssd_resnet50_v1_fpn_640x640_coco17_tpu-8.tar.gz
    !tar -xf ssd_resnet50_v1_fpn_640x640_coco17_tpu-8.tar.gz
    
    model_dir = '/content/ssd_resnet50_v1_fpn_640x640_coco17_tpu-8/saved_model'
    log_dir = '/content/logs'
    
    if os.path.exists(log_dir):
      ! rm -r $log_dir
    
    @tf.function
    def f(x):
        imported = tf.saved_model.load(model_dir)
        results = imported(x)
        return results
        
    #Initialize variables
    imgs = np.zeros((1,640,640,3),dtype=int)
    imgs_t = tf.constant(imgs, dtype=tf.dtypes.uint8)
    imported_g = f.get_concrete_function(imgs_t).graph
    
    # Export the graph
    with session.Session(graph=imported_g) as sess:
      pb_visual_writer = summary.FileWriter(log_dir)
      pb_visual_writer.add_graph(sess.graph)
      print("Model Imported. Visualize by running: "
            "tensorboard --logdir={}".format(log_dir))
    

    新图表显示图表的边缘,而不仅仅是节点。

    这是一个可以运行的笔记本:https://colab.research.google.com/gist/mherzog01/d631998cb4d0b0dbcb70492b933a67c8/tensorboard-hangs-during-graph-visualization-solution.ipynb。

    【讨论】:

      猜你喜欢
      • 2018-04-13
      • 2019-01-29
      • 2018-10-06
      • 2018-05-25
      • 2021-02-24
      • 2018-08-03
      • 2019-04-20
      • 2020-05-09
      • 2019-07-04
      相关资源
      最近更新 更多