如何在Pytorch中使用torch.nn.Sequential实现我自己的ResNet? [英] How to implement my own ResNet with torch.nn.Sequential in Pytorch?

查看:112
本文介绍了如何在Pytorch中使用torch.nn.Sequential实现我自己的ResNet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个ResNet网络(或更确切地说,是剩余块),但是我真的希望它采用顺序网络形式.

I want to implement a ResNet network (or rather, residual blocks) but I really want it to be in the sequential network form.

依序网络形式的含义如下:

What I mean by sequential network form is the following:

## mdl5, from cifar10 tutorial
mdl5 = nn.Sequential(OrderedDict([
    ('pool1', nn.MaxPool2d(2, 2)),
    ('relu1', nn.ReLU()),
    ('conv1', nn.Conv2d(3, 6, 5)),
    ('pool1', nn.MaxPool2d(2, 2)),
    ('relu2', nn.ReLU()),
    ('conv2', nn.Conv2d(6, 16, 5)),
    ('relu2', nn.ReLU()),
    ('Flatten', Flatten()),
    ('fc1', nn.Linear(1024, 120)), # figure out equation properly
    ('relu4', nn.ReLU()),
    ('fc2', nn.Linear(120, 84)),
    ('relu5', nn.ReLU()),
    ('fc3', nn.Linear(84, 10))
]))

但是,当然,NN lego块是"ResNet".

but of course with the NN lego blocks being "ResNet".

我知道方程式是这样的:

I know the equation is something like:

但是我不确定如何在Pytorch AND Sequential中做到这一点.顺序是我的关键!

but I am not sure how to do it in Pytorch AND Sequential. Sequential is key for me!

交叉发布:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆