PyTorch实现AlexNet示例
2020-02-13 10:21
1591 查看
PyTorch: https://github.com/shanglianlm0525/PyTorch-Networks
import torch import torch.nn as nn import torchvision class AlexNet(nn.Module): def __init__(self,num_classes=1000): super(AlexNet,self).__init__() self.feature_extraction = nn.Sequential( nn.Conv2d(in_channels=3,out_channels=96,kernel_size=11,stride=4,padding=2,bias=False), nn.ReLU(inplace=True), nn.MaxPool2d(kernel_size=3,stride=2,padding=0), nn.Conv2d(in_channels=96,out_channels=192,kernel_size=5,stride=1,padding=2,bias=False), nn.ReLU(inplace=True), nn.MaxPool2d(kernel_size=3,stride=2,padding=0), nn.Conv2d(in_channels=192,out_channels=384,kernel_size=3,stride=1,padding=1,bias=False), nn.ReLU(inplace=True), nn.Conv2d(in_channels=384,out_channels=256,kernel_size=3,stride=1,padding=1,bias=False), nn.ReLU(inplace=True), nn.Conv2d(in_channels=256,out_channels=256,kernel_size=3,stride=1,padding=1,bias=False), nn.ReLU(inplace=True), nn.MaxPool2d(kernel_size=3, stride=2, padding=0), ) self.classifier = nn.Sequential( nn.Dropout(p=0.5), nn.Linear(in_features=256*6*6,out_features=4096), nn.ReLU(inplace=True), nn.Dropout(p=0.5), nn.Linear(in_features=4096, out_features=4096), nn.ReLU(inplace=True), nn.Linear(in_features=4096, out_features=num_classes), ) def forward(self,x): x = self.feature_extraction(x) x = x.view(x.size(0),256*6*6) x = self.classifier(x) return x if __name__ =='__main__': # model = torchvision.models.AlexNet() model = AlexNet() print(model) input = torch.randn(8,3,224,224) out = model(input) print(out.shape)
以上这篇PyTorch实现AlexNet示例就是小编分享给大家的全部内容了,希望能给大家一个参考
您可能感兴趣的文章:
相关文章推荐
- PyTorch实现的AlexNet
- PyTorch上搭建简单神经网络实现回归和分类的示例
- Pytorch实现各种2d卷积示例
- Pytorch实现的手写数字mnist识别功能完整示例
- Asp.net 2.0 实现自定义Email格式有效性验证(示例代码下载)
- 利用python实现命令行有道词典的方法示例
- PHP实现一维数组与二维数组去重功能示例
- 通过ContentResolver调用系统URI实现的通讯录示例
- 原生javascript实现无间缝滚动示例
- ASP.NET 简单的柱形图实现(附带示例)
- Android 获取Root权限之后的静默安装实现 代码示例分析&&源码下载
- java实现从方法返回多个值功能示例
- 原生JavaScript生成GUID的实现示例
- jQuery实现ToolTip元素定位显示功能示例
- Angularjs 实现一个幻灯片示例代码
- IDisposable 接口实现示例
- spring mvc 实现获取后端传递的值操作示例
- JS简单实现移动端日历功能示例
- Java实现求解一元n次多项式的方法示例
- Python递归实现汉诺塔算法示例