Google colaboratory 可视化对象检测图时,TensorBoard会挂起

Google colaboratory 可视化对象检测图时,TensorBoard会挂起,google-colaboratory,tensorflow2.0,tensorboard,Google Colaboratory,Tensorflow2.0,Tensorboard,我需要可视化TensorFlow对象检测模型的结构。我正在尝试在Colab中使用TensorBoard,代码如下。当TensorBoard加载日志时,它会停留在“名称空间层次结构:查找类似子图”的步骤上 以下是指向笔记本的链接: 环境: 浏览器:Chrome 操作系统:Windows 内存:8GB 最后,我开始得到下面的错误 仅供参考,我尝试在一台内存为4GB的Windows计算机上运行相同的进程,同时在一个外壳中运行一个TensorBoard服务器。我使用默认URL访问TensorBoard(

我需要可视化TensorFlow对象检测模型的结构。我正在尝试在Colab中使用TensorBoard,代码如下。当TensorBoard加载日志时,它会停留在“名称空间层次结构:查找类似子图”的步骤上

以下是指向笔记本的链接:

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

最后,我开始得到下面的错误

仅供参考,我尝试在一台内存为4GB的Windows计算机上运行相同的进程,同时在一个外壳中运行一个TensorBoard服务器。我使用默认URL访问TensorBoard(在笔记本之外)。它在启动过程中的同一点失败

我看到了这一点,并提出了类似的问题,但没有提供答案

提前感谢——这对我为公司做的重要项目真的很有帮助


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

  • RAM/CPU不足->在资源较多的计算机上运行
  • 复杂图形,需要放大->使用缩放查看节点
  • 变量未初始化->评估模型以显示图形的边
  • 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))
    
    新图形显示图形的边,而不仅仅是节点

    以下是您可以运行的笔记本:

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