Pytorch Workflow


Abstract

Personal understanding of the working paradigm of training an artificial neural network (ANN) based on Pytorch.


Paradigm

一、数据(torch.utils.data.DataLoader)
--> 
二、模型(torch.nn)
 --> 
三、策略(损失函数, criterion = torch.nn.BlaBlaLoss)+ 算法(优化算法, optimizer = torch.optim.SGD|Adam|Adadelta...)
 --> 
四、迭代训练
(
    FOR 
        1. optimizer.zero_grad() 
        2. outputs_train = net(inputs_train) 
        3. loss_train = criterion(outputs_train, labels_train) 
        4. loss_train.backward() 
        5. optimizer.step() 
    END FOR
)
--> 
五、调参/测试(验证集调参/测试集进行最后的打分)
(
    with torch.no_grad():
        outputs_test = net(inputs_test)
        loss_test = criterion(outputs_test, labels_test)
        ... other test criterion ...
)
--> 
六、加速(optional)
(
    # Train on GPU
    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
    net.to(device) 
    inputs, labels = inputs.to(device), labels .to(device)
    # Data parallelism
    net = nn.DataParallel(net)
)

to be continued...


References

Pytorch tutorial: https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html
李航老师: 《统计机器学习》

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容