名称\u Tensorflow的作用域在Tensorboard中不起作用

2024-09-28 22:20:21 发布

您现在位置:Python中文网/ 问答频道 /正文

Settings:
Mac OS 10.14.6
Python 3.7.4
Tensorflow 2.0.0

我有一个问题,当谈到名称的范围设置。 我在代码中编写name_scope(),但在Tensorboard中它没有像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

Tags: nameself名称modeltensorflowwithsummarydense
1条回答
网友
1楼 · 发布于 2024-09-28 22:20:21

我自己解决了这个问题。 可能是因为皮普和水蟒的碰撞。 所以我在下面做了

  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\u配置文件中的内容

    $ 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
    

enter image description here

相关问题 更多 >