彰阙有常 2022-08-23 09:12 采纳率: 0%
浏览 28

加载中间层模型输出的时候报错

问题遇到的现象和发生背景

加载中间层模型输出的时候报错

>       raise AttributeError('Layer ' + self.name + ' has no inbound nodes.')
E       AttributeError: Layer resnet has no inbound nodes.

问题相关代码,请勿粘贴截图

这是Resnet50模型

class ResNet(Model):
    def get_config(self):
        config = {
            "block_layers": self.block_layers,
            "base_filters": self.base_filters,
            "block_type": self.block_type
        }
        base_config = super(ResNet, self).get_config()
        return dict(list(base_config.items()) + list(config.items()))

    def __init__(self, block_layers, name="resnet", base_filters=64, block_type='deep'):
        """
        pa
        :param block_layers:
        :param base_filters:
        :param block_type: deep or simple
        """
        super(ResNet, self).__init__(name=name)
        self.block_layers = block_layers
        self.base_filters = base_filters
        self.block_type = block_type
        self.feature = Sequential([
            layers.Conv2D(filters=base_filters, kernel_size=7, strides=2),
            layers.BatchNormalization(),
            layers.ReLU(),
            layers.MaxPool2D(pool_size=3, strides=2),
        ])
        nlb_dims = base_filters * 4
        if block_type == "deep":
            nlb_dims = base_filters * 16
        self.block1 = build_block(base_filters, block_layers[0], init_stride=1, block_type=block_type,
                                  is_downsample=True, name="res_block_1")
        self.block2 = build_block(base_filters * 2, block_layers[1], block_type=block_type, name='res_block_2')
        self.block3 = build_block(base_filters * 4, block_layers[2], block_type=block_type, name='res_block_3')
        # 非局部网络
        self.nlb = NonLocalBlock(input_dims=nlb_dims)
        self.block4 = build_block(base_filters * 8, block_layers[3], block_type=block_type, name='res_block_4')

    def call(self, inputs, training=None, mask=None):
        x = inputs
        x = self.feature(x)
        x = self.block1(x)
        x = self.block2(x)
        x = self.block3(x)
        x = self.nlb(x)
        x = self.block4(x)
        return x

这是让Resnet50作为中间层的模型
class TestModel(Model):

def __init__(self, drop_rate=0.5, in_shape=(128, 128, 1), block_layers=(3, 4, 6, 3)):
    super(HomographyModel, self).__init__()
    # 特征提取
    self.resnet = ResNet(block_layers=block_layers)
    # self.resnet = resnet(block_layers=block_layers)
    self.avgpool = layers.GlobalAvgPool2D(name="gap")
    self.fc = Sequential([
        layers.Flatten(),
        layers.Dense(1024),
        layers.BatchNormalization(),
        layers.ReLU(),
        layers.Dropout(rate=self.drop_rate),
        layers.Dense(8)], name="fc")
    self.build([(None,) + in_shape, (None,) + in_shape])
运行结果及报错内容
print(model.get_layer("resnet").output.shape)
    if not self._inbound_nodes:
  raise AttributeError('Layer ' + self.name + ' has no inbound nodes.')

E AttributeError: Layer resnet has no inbound nodes.

我的解答思路和尝试过的方法

将类方式建模改为方法建模,但是精度就下不去了

  • 写回答

1条回答 默认 最新

  • 「已注销」 2022-08-23 09:36
    关注

    你把报错发过来给我看一下

    评论

报告相同问题?

问题事件

  • 创建了问题 8月23日

悬赏问题

  • ¥20 物理远程控制麦克风使用问题
  • ¥15 在hololens1上运行unity项目只有空窗口
  • ¥25 TABLEAU PREP无法打开
  • ¥15 百度帐号问题/centos
  • ¥15 关于#c语言#的问题:求完整代码条件好说
  • ¥100 HALCON DELPHI
  • ¥15 (需要远程,AI不回)VB6二进制文件转换成功,但是C#转换总是失败
  • ¥15 关于#matlab#的问题:有没有什么其他办法能够保证不退出进程(相关搜索:matlab调用)
  • ¥15 依据报错在原代吗格式的基础上解决问题
  • ¥15 在虚拟机中安装flash code