batchsize的问题
- parser.add_argument('--batch_size', help='the size of reading data size', default=64, type=int) #batch_size =单卡的batch_size*卡的个数,这里的batchSIze指的是总的batchSize,如果单卡设置的是10,多卡的时候batchsize依然是10,结果才相近
- parser.add_argument('--num_workers', help='the num of workers when reading data', default=20, type=int) #起的线程的个数=设备的最大cpu核数
模型加载的问题
net = torch.nn.DataParallel(net,device_ids=configs.DEVICEIDS)
net = net.cuda(device=configs.DEVICEIDS[0])
if configs.RESTORE:
# mutil-gpu,训练加载带有module的文件
net.load_state_dict(torch.load(configs.RESTORE_PATH))
#第一次加载npy转为pt的模型文件时,需要卷在积层名称前面加上module的
kwargs={'map_location':lambda storage, loc: storage.cuda()}
state_dict = torch.load(configs.RESTORE_PATH,**kwargs)
# create new OrderedDict that does not contain `module.`
# 第一次加载预训练模型,添加“module”
from collections import OrderedDict
new_state_dict = OrderedDict()
for k, v in state_dict.items():
name = 'module.'+ k # add "module"
new_state_dict[name] = v
# load params
net.load_state_dict(new_state_dict)