当前位置:网站首页>PyTorch⑩---卷积神经网络_一个小的神经网络搭建
PyTorch⑩---卷积神经网络_一个小的神经网络搭建
2022-08-02 14:07:00 【伏月三十】
一个小的神经网络搭建
import torch
from torch import nn
from torch.nn import Conv2d, MaxPool2d, Flatten, Linear
class Demo(nn.Module):
def __init__(self) -> None:
super().__init__()
self.conv1=Conv2d(in_channels=3,out_channels=32,kernel_size=5,stride=1,padding=2,dilation=1,)
self.maxpool1=MaxPool2d(kernel_size=2,)
self.conv2=Conv2d(in_channels=32,out_channels=32,kernel_size=5,stride=1,padding=2,)
self.maxpool2=MaxPool2d(kernel_size=2)
self.conv3=Conv2d(32,64,5,1,2)
self.maxpool3=MaxPool2d(2)
self.flatten=Flatten()#如果在这里不知道展开后是多少,直接运行到这里查看一下情况
self.linear1=Linear(1024,64)
#为什么最后一个线性层是10,因为label是10,根据概率进行分类
self.linear2=Linear(64,10)
def forward(self,x):
x=self.conv1(x)
x=self.maxpool1(x)
x=self.conv2(x)
x=self.maxpool2(x)
x=self.conv3(x)
x=self.maxpool3(x)
x=self.flatten(x)
x=self.linear1(x)
x=self.linear2(x)
return x
demo=Demo()
print(demo)
'''对网络步骤进行验证'''
input=torch.ones((64,3,32,32))
output=demo(input)
print(output)
print(output.shape)
结果:
边栏推荐
猜你喜欢
随机推荐
YOLOv7 uses cloud GPU to train its own dataset
宝塔搭建PESCMS-Ticket开源客服工单系统源码实测
spark写sql的方式
关于Flink
关于UDF
内存申请(malloc)和释放(free)之上篇
芝诺悖论的理解
Tornado framework routing system introduction and (IOloop.current().start()) start source code analysis
Word2vec词向量
spark资源调度和任务调度
MySQL知识总结 (四) 事务
自定义UDF函数
宝塔搭建DM企业建站系统源码实测
MySQL知识总结 (十) 一条 SQL 的执行过程详解
LLVM系列第四章:逻辑代码块Block
AAPT: error: duplicate value for resource ‘attr/xxx‘ with config ‘‘, file failed to compile.
It is not allowed to subscribe with a(n) xxx multiple times.Please create a fresh instance of xxx
1.RecyclerView是什么
十分钟带你入门Nodejs
Policy Evaluation收敛性、炼丹与数学家