python - Tensorflow 的 name_scope 在 Tensorboard 中不起作用

标签 python tensorflow tensorboard

Settings:
Mac OS 10.14.6
Python 3.7.4
Tensorflow 2.0.0

我在 name_scope 设置方面遇到问题。 我在代码中编写 name_scope() ,但 Tensorboard 中没有 name_scope,如 this image in Tensorboard 。 我打算在此图像中为 Flatten、Dense 等创建一个名称范围。

我卸载并重新安装 Tensorflow,但得到了相同的结果。 作为附加信息,我在终端中没有收到任何错误。 有人对这种情况有任何想法吗?

def _model_B0001(self):
    with tf.name_scope('1stLayer'):
        inputs = Input(self.shape)
        x = Flatten()(inputs)
        x = Dense(512)(x)
        output1 = Dense(self.nb_classes1, activation='softmax', name='output1')(x)
        output2 = Dense(self.nb_classes2, activation='softmax', name='output2')(x)
        predictions = [output1, output2]
    model = Model(inputs, predictions)
    model.compile(loss={'output1': 'categorical_crossentropy',
                        'output2': 'categorical_crossentropy'},
                  optimizer='adam',
                  metrics=['accuracy'])
    model.summary()
    with open(self.summary_txt, "w") as fp:
        model.summary(print_fn=lambda x: fp.write(x + "\r\n"))
    return model

最佳答案

这个问题我自己解决了。 可能是因为 pip 和 anaconda 的碰撞。 所以我做了下面的事情。

  1. 卸载所有 pip 软件包。

     $ pip freeze > piplist.txt
     $ sudo pip uninstall -r piplist.txt
    
  2. 卸载所有 anaconda 软件包。

卸载软件包。

    $ conda install anaconda-clean
    $ anaconda-clean

删除包后删除空文件夹。

    $ rm -fr ~/.anaconda_backup
    $ rm -fr /anaconda3

删除.bash_profile中的内容

    $ sudo nano .bash_profile
  • 重新安装 anaconda。从https://www.anaconda.com/distribution/下载

  • 重新运行张量板。

    def _model_A0001(self):
     with tf.name_scope('1stLayer') as scope:
        # print(scope)
        # sys.exit()
        inputs = Input(self.shape)
        x = Conv2D(32, (3, 3), border_mode='same', name='conv2d')(inputs)
        x = Activation('relu', name='relu')(x)
        x = MaxPooling2D(pool_size=(2, 2), name='max_pooling')(x)
        x = Dropout(0.25, name='dropout')(x)
    
     with tf.name_scope('2ndLayer'):
        x = Conv2D(64, (3, 3), border_mode='same')(x)
        x = Activation('relu')(x)
        x = Conv2D(64, (3, 3))(x)
        x = MaxPooling2D(pool_size=(2, 2))(x)
        x = Dropout(0.25)(x)
    
     with tf.name_scope('DenseLayer'):
        x = Flatten()(x)
        x = Dense(512)(x)
        x = Activation('relu')(x)
        x = Dropout(0.5)(x)
        output1 = Dense(self.nb_classes1, activation='softmax', name='output1')(x)
        output2 = Dense(self.nb_classes2, activation='softmax', name='output2')(x)
        predictions = [output1, output2]
        # inputs = [inputs, inputs]
        model = Model(inputs, outputs=predictions)
        model.compile(loss={'output1': 'categorical_crossentropy',
                            'output2': 'categorical_crossentropy'},
                      optimizer='adam',
                      metrics=['accuracy'])
     model.summary()
     with open(self.summary_txt, "w") as fp:
        model.summary(print_fn=lambda x: fp.write(x + "\r\n"))
     return model
    
  • enter image description here

    关于python - Tensorflow 的 name_scope 在 Tensorboard 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59475228/

    相关文章:

    python - requirements.txt 波形符等于 (~=) 与波形符大于 (~>)

    Python Pandas 科学记数法不一致

    tensorflow - Keras 模型在 fit() 和 Predict() 期间对相同输入给出不同的预测

    python - Tensorflow:在不使用 .eval() 或 sess.run() 的情况下将 Tensor 转换为 numpy 数组

    tensorflow - 如何在 Tensorboard 中隐藏 "Cond"张量? (附截图)

    tensorflow - 如何在Tensorflow中编写多次运行的摘要

    python - Scrapy 使用 css 选择器抓取嵌套文本

    python - 分割字符串而不删除分隔符

    python - 异常训练Resnet50 : "The shape of the input to "Flatten"is not fully defined"

    python - 从 Tensorboard 上保存的 .pbtxt 文件查看图形