建设工程国检中心网站做网站需要哪些技术
1、datasets_make函数中最后全部转化为numpy形式
data=np.array(data)
否则会出现问题,比如数据是103216,经过trainloader生成tensor后(batch_size为30),发现生成的数据为:
data.shape #(10,)
data[0].shape #(30,32,16)
而不是(30,10, 32,16)
2、模型推导时数据首先进行处理,移到cuda上
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
input_batch = input_batch.cuda()
否则会报错:
RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same
3、保存模型时注意路径
torch.save(model.state_dict(), f'{checkpoints_dir}/{epoch:003}.pth')
当时没有新建checkpoints_dir文件夹,所以报错:
FileNotFoundError: [Errno 2] No such file or directory:
注意:epoch:003中后面的意思是保留三位,即000,001…