'OrderedDict'object has no attribute'module'マルチカードトレーニングテスト

2010 ワード

検出のためにマルチカードトレーニングのモデルをロードして走る
device_ids=[0,1]

use_gpu = torch.cuda.is_available()
# 
model = se_resnet20_v2()  
model = model.cuda(device_ids[0])
model = nn.DataParallel(model, device_ids=device_ids)

# 

pretained_model = torch.load('/home/zj/senetial/save_models/SENet/SEnet_model_33.pth')
model.load_state_dict(pretained_model)

# test 
test_file = h5py.File('/home/zj/senetial/data/round1_test_a_20181109.h5', 'r')
test_sen1 = test_file['sen1']
test_sen2 = test_file['sen2']
count=test_sen1.shape[0]

f=open('/home/zj/senetial/data/test_33_meanstd_test.csv','w')for i in tqdm(range(int(math.ceil(count/16.0))zeros((16,17),dtype=int)     images=mean_std(AddFeatures(np.concatenate((test_sen1[i*16:(i+1)*16,:,:,:],test_sen 2[i*16:(i+1)*16,:,:,:]),axis=3)))))#リスト:最後のinputs=Variable((torch.from_numpy(images)).float().permute(0, 3, 1, 2).Cuda(device_ids[0])#必ずdevice_を追加idsはデフォルト()outputs=model(inputs)scores,preds=torchではない.max(outputs.data,1)#preds for i in range(inputs.shape[0]):#ここでbatchsizeは使用できませんので、リスト[:]後のshape onehot[i,preds[i]=1 f.writeline(','.join(map(str,onehot[i])+')のみ使用できます.
 
単一GPU:
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"

マルチGPU:
device_ids = [0,1,2,3]

model = model.cuda(device_ids[0])
model = nn.DataParallel(model, device_ids=device_ids)

optimizer = optim.SGD(model.parameters(), lr=learning_rate, momentum=0.9, weight_decay=0.001)
optimizer = nn.DataParallel(optimizer, device_ids=device_ids)

optimizer.module.step()
for param_lr in optimizer.module.param_groups:  #  module
        #     param_lr['lr'] = param_lr['lr'] * 0.999



マルチGPUプリトレーニングモデルのロード
model = ft_net()
pretained_model = torch.load('./model/all/8_model.pkl')
pretained_dict = pretained_model.module.state_dict()
model = ft_net()
model.load_state_dict(pretained_dict)