首先,我曾使用过像'model.cuda()'这样的模型和数据转换为cuda。但是它仍然有这样的问题。我调试模型的每一层,每个模块的权重为iscuda = True。那么有人知道为什么会出现这样的问题吗?
我有两种模型,一种是resnet50,另一种包含第一个作为主干。
class FC_Resnet(nn.Module):
def __init__(self, model, num_classes):
super(FC_Resnet, self).__init__()
# feature encoding
self.features = nn.Sequential(
model.conv1,
model.bn1,
model.relu,
model.maxpool,
model.layer1,
model.layer2,
model.layer3,
model.layer4)
# classifier
num_features = model.layer4[1].conv1.in_channels
self.classifier = nn.Sequential(
nn.Conv2d(num_features, num_classes, kernel_size=1, bias=True))
def forward(self, x):
# children=self.features.children()
# for child in children:
# if child.weight is not None:
# print(child.weight.device)
x = self.features(x)
x = self.classifier(x)
return x
def fc_resnet50(num_classes=20, pre_trained=True):
model = FC_Resnet(models.resnet50(pre_trained), num_classes)
return model
Run Code Online (Sandbox Code Playgroud)
还有一个:
class PeakResponseMapping(nn.Sequential):
def __init__(self, *args, **kargs): …Run Code Online (Sandbox Code Playgroud)