Настройка модели Pytorch:
class myResnet(nn.Module):<br>
def __init__(self, resnet):<br>
super(myResnet, self).__init__()<br>
self.resnet = resnet
def forward(self, img, att_size=14):
x = img.unsqueeze(0)
x = self.resnet.conv1(x)
x = self.resnet.bn1(x)
x = self.resnet.relu(x)
x = self.resnet.maxpool(x)
x = self.resnet.layer1(x)
x = self.resnet.layer2(x)
x = self.resnet.layer3(x)
x = self.resnet.layer4(x)
fc = x.mean(3).mean(2).squeeze()
att = F.adaptive_avg_pool2d(x,[att_size,att_size]).squeeze().permute(1, 2, 0)
return fc, att
Resnet - это resnet101, как сделать то же самое, используя Keras Resnet 101?
Не уверен, как поставить модель resnet101в Керасе?
Ниже приведен пример кода.
class ResnetBuilder(object):
def __init__(self, resnet, num_classes=1000):
super(ResnetBuilder, self).__init__()
self.resnet = resnet
@staticmethod
def ResNet101_Image(self, image):
eps = 1.1e-5
# Handle Dimension Ordering for different backends
input_shape = image.shape
img_input = Input(shape=input_shape, name='data')
x = self.resnet.ZeroPadding2D((3, 3), name='conv1_zeropadding')(img_input)
x = self.resnet.Conv2D(64, (7, 7), strides=(2, 2), name='conv1', use_bias=False)(x)