class BasicBlock(layers.Layer):
#残差模块
def __init__(self,filter_num,stride=1):
super(BasicBlock,self).__init__()
# 第一个卷积单元
super.conv1 = layers.Conv2D(filter_num,(3,3),strides=stride,padding="same")
self.bn1 = layers.BatchNormalization()
self.relu = layers.Activation("relu")
#第二个卷积单元
super.conv2 = layers.Conv2D(filter_num, (3, 3), strides=1, padding="same")
self.bn2 = layers.BatchNormalization()
if stride !=1: #通过1*1卷积完成shape的匹配
self.downsample = Sequential()
self.downsample.add(layers.Conv2D(filter_num,(1,1),strides=stride))
else:
self.downsample=lambda x:x
报错如下
File "C:/Users/SKC/Desktop/CNN/ResNet 18 - 副本.py", line 14, in __init__
super.conv1 = layers.Conv2D(filter_num,(3,3),strides=stride,padding="same")
TypeError: can't set attributes of built-in/extension type 'super'