Pytorch模型自定义:
QModelIndex::isValid()
Resnet是resnet101,如何使用Keras Resnet 101进行相同操作?
不确定如何将resnet101模型放入Keras中吗?
下面的代码是一个示例。
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