RuntimeError: Expected object of backend CPU but got backend CUDA for argument #4 'mat1'
该Error出现在pytroch框架下,加载完模型后计划修改最后一层全连接层。
checkpoint = torch.load(config.best_models + config.model_name+ os.sep +str(fold) + os.sep + best_models_name)
start_epoch = checkpoint["epoch"]
fold = checkpoint["fold"]
best_precision1 = checkpoint["best_precision1"]
model.load_state_dict(checkpoint["state_dict"])
optimizer.load_state_dict(checkpoint["optimizer"])
# model.fc = nn.Linear(512, m)
# model.cuda()
若加载完模型后需要修改网络层,修改完后需使用model.cuda()操作。