class UNET(tf.keras.Model): def __init__(self, in_channel, out_channel): super(UNET, self).__init__() self.layer1 = conv_block(in_channel, out_channel) self.layer2 = Downsample(out_channel) self.layer3 = conv_block(out_channel, out_channel*2) self.layer4 = Downsample(out_channel*2) self.layer5 = conv_block(out_channel*2, out_channel*4) self.layer6 = Downsample(out_channel*4) self.layer7 = conv_block(out_channel*4, out_channel*8) self.layer8 = Downsample(out_channel*8) self.layer9 = conv_block(out_channel*8, out_channel*16) self.layer10 = Upsample(out_channel*16) self.layer11 = conv_block(out_channel*16, out_channel*8) self.layer12 = Upsample(out_channel*8) self.layer13 = conv_block(out_channel*8, out_channel*4) self.layer14 = Upsample(out_channel*4) self.layer15 = conv_block(out_channel*4, out_channel*2) self.layer16 = Upsample(out_channel*2) self.layer17 = conv_block(out_channel*2, out_channel) self.layer18 = tf.keras.layers.Conv2DTranspose(filters=in_channel, kernel_size=1, strides=1, activation=None) self.act = tf.keras.layers.Activation('sigmoid') #激活函数 def call(self, x): x = self.layer1(x) f1 = x x = self.layer2(x) x = self.layer3(x) f2 = x x = self.layer4(x) x = self.layer5(x) f3 = x x = self.layer6(x) x = self.layer7(x) f4 = x x = self.layer8(x) x = self.layer9(x) x = self.layer10(x, f4) x = self.layer11(x) x = self.layer12(x, f3) x = self.layer13(x) x = self.layer14(x, f2) x = self.layer15(x) x = self.layer16(x, f1) x = self.layer17(x) x = self.layer18(x) return self.act(x) x = tf.random.normal(shape=(2, 256, 256, 1)) y = tf.random.normal(shape=(2, 256, 256, 1)) model = UNET(in_channel=1, out_channel=64) loss_fn = tf.keras.losses.BinaryCrossentropy() optimizer = tf.keras.optimizers.Adam() TypeError: conv_block() missing 1 required positional argument: 'name'
时间: 2023-12-23 19:03:39 浏览: 128
u-net 实现(keras)
3星 · 编辑精心推荐
从错误信息来看,是因为在创建`UNET`类的时候,调用了`conv_block()`函数,但是缺少了一个必需的参数`name`。因此建议您检查一下`conv_block()`函数的定义,确保它需要的参数是否包括`name`,并且在调用时传递了正确的参数。
此外,如果您能提供更多代码或上下文信息,我们可以更好地理解您的问题,并提供更具体的帮助。
阅读全文