可视化对象检测图时,TensorBoard挂起 [英] TensorBoard hangs when visualizing an Object Detection graph

查看:382
本文介绍了可视化对象检测图时,TensorBoard挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要可视化TensorFlow对象检测模型的结构.我正在尝试将Colab中的TensorBoard与下面的代码一起使用.当TensorBoard加载日志时,它会卡在名称空间层次结构:查找相似的子图"步骤中.

I need to visualize the structure of a TensorFlow Object Detection model. I am trying to use TensorBoard in Colab with the code below. When TensorBoard loads the logs, it gets stuck on the step "Namespace hierarchy: Finding similar subgraphs".

!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 .

Here is a link to the notebook: https://colab.research.google.com/drive/1MrbNJYR2ds8RRgIBvgUgAILw0Jwdygui?usp=sharing.

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

Environment: Browser: Chrome OS: Windows RAM: 8 GB

最终,我开始出现以下错误.

Eventually, I start getting the errors below.

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

FYI, I tried to run this same process on a Windows computer with 4 GB of RAM, with a TensorBoard server running in a shell. I accessed TensorBoard using the default URL (outside of a notebook). It failed at the same point in the startup process.

我看到 Tensorboard卡在了命名空间层次结构查找"中和我正在努力在Mask_RCNN训练过程中实施张量板监视,问了类似的问题,但没有提供答案.

I see that Tensorboard got stuck in 'namespace hierarchy finding similar subgraphs' and I'm struggling to implement tensorboard monitoring into the Mask_RCNN training process asked similar questions, but no answer has been provided.

预先感谢-这确实有助于我为公司所做的重要项目.

Thanks in advance -- this would really help in the important project I am doing for my company.

推荐答案

我认为现在有3个问题,我知道该如何解决.

There are 3 issues that I believe I now know how to fix.

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

1. RAM/CPU不足

在具有24 GB RAM和8个i7内核的Windows计算机上运行该过程,对我来说消除了崩溃.有时,我会收到一条有关页面变得无响应的消息,但是您只需单击等待"按钮即可.按钮,它将加载.负载本身也快得多.

1. Insufficient RAM/CPU

Running the process on a Windows computer with 24 GB RAM and 8 i7 cores eliminated the crashes for me. Sometimes I get a message about the page becoming unresponsive, but you can just click the "Wait" button and it will load. The load itself was also much faster.

运行以上代码,TensorBoard将显示为空白屏幕.但是,图节点的轮廓很模糊.

Running the above code, TensorBoard displays what appears to be a blank screen. However, there is a faint outline of graph nodes.

放大以查看详细信息.屏幕右下方的导航框很有用.

Zoom in to see the details. The navigation box in the lower right portion of the screen is helpful.

使用以下代码代替上述问题中的代码:

Instead of the code in my question above, use the following:

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))

新图形显示了图形的边缘,而不仅仅是节点.

The new graph shows the edges of the graph, not just the nodes.

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

Here's a notebook that you can run: https://colab.research.google.com/gist/mherzog01/d631998cb4d0b0dbcb70492b933a67c8/tensorboard-hangs-during-graph-visualization-solution.ipynb.

这篇关于可视化对象检测图时,TensorBoard挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆