【问题标题】:name_scope of Tensorflow not work in TensorboardTensorflow 的 name_scope 在 Tensorboard 中不起作用
【发布时间】:2019-12-25 04:28:26
【问题描述】:
Settings:
Mac OS 10.14.6
Python 3.7.4
Tensorflow 2.0.0

我在 name_scope 设置方面遇到了问题。 我在我的代码中写了name_scope(),但它在Tensorboard 中没有像this image in Tensorboard 这样的name_scope。 我打算为这张图片中的 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

【问题讨论】:

    标签: python tensorflow tensorboard


    【解决方案1】:

    我自己解决了这个问题。 这可能是因为 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
    
    1. 重新安装 anaconda。从https://www.anaconda.com/distribution/下载

    2. 重新运行张量板。

      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
      

    【讨论】:

      猜你喜欢
      • 2016-08-05
      • 1970-01-01
      • 2020-03-01
      • 1970-01-01
      • 2016-03-31
      • 1970-01-01
      • 2017-06-06
      • 1970-01-01
      • 2020-06-12
      相关资源
      最近更新 更多