1 Star 0 Fork 1

bocinfor/DeepLearning-MachineLearning-Note

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
modules.py 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
edata 提交于 2020-01-07 23:48 +08:00 . add verification code recogintion note
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchsummary import summary
class DigitalLetterNet(nn.Module):
def __init__(self, in_chs, out_chs, fcn=False):
super(DigitalLetterNet, self).__init__()
self.in_chs = in_chs
self.out_chs = out_chs
self.fcn = fcn
self.conv = nn.Sequential(
nn.Conv2d(self.in_chs, 16, 5, padding=2),
nn.ReLU(True),
nn.MaxPool2d(2),
nn.Conv2d(16, 32, 3, padding=1),
nn.ReLU(True),
nn.BatchNorm2d(32),
nn.MaxPool2d(2),
nn.Conv2d(32, 64, 3, padding=1),
nn.ReLU(True),
nn.MaxPool2d(2),
nn.Conv2d(64, 128, 3, padding=1),
nn.ReLU(True),
nn.MaxPool2d(2),
nn.Conv2d(128, 256, 3, padding=1),
nn.ReLU(True),
nn.MaxPool2d(2),
)
if self.fcn:
self.classifier = nn.Conv2d(256, self.out_chs, 1)
else:
self.classifier = nn.Linear(256, self.out_chs)
def forward(self, x):
x = self.conv(x)
if not self.fcn:
x.squeeze_()
x = self.classifier(x)
if self.fcn:
x.squeeze_()
x = F.log_softmax(x, dim=-1)
return x
# just for test
if __name__ == '__main__':
dl_net = DigitalLetterNet(3, 36, True)
print(summary(dl_net, (3, 32, 32), device='cpu'))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/bocinfor/DeepLearning-MachineLearning-Note.git
git@gitee.com:bocinfor/DeepLearning-MachineLearning-Note.git
bocinfor
DeepLearning-MachineLearning-Note
DeepLearning-MachineLearning-Note
master

搜索帮助