当前位置:网站首页>pytorch_demo1
pytorch_demo1
2022-07-27 08:09:00 【翟小花@@】
一个简单的分类模型
model.python
import torchvision
import torch
# 准备数据集
from torch import nn
from torch.utils.data import DataLoader
#搭建神经网络
class Tudui(nn.Module):
def __init__(self):
super(Tudui,self).__init__()
self.model=nn.Sequential(
nn.Conv2d(3,32,5,1,2),
nn.MaxPool2d(2),
nn.Conv2d(32, 32, 5, 1, 2),
nn.MaxPool2d(2),
nn.Conv2d(32, 64, 5, 1, 2),
nn.MaxPool2d(2),
nn.Flatten(),
nn.Linear(64*4*4,64),
nn.Linear(64,10)
)
def forward(self,x):
x=self.model(x)
return x
if __name__ == '__main__':
tudui=Tudui()
input=torch.ones((64,3,32,32))
output=tudui(input)
print(output.shape)
train.python
import torchvision
import torch
# 准备数据集
from torch import nn
from torch.utils.data import DataLoader
#搭建神经网络
class Tudui(nn.Module):
def __init__(self):
super(Tudui,self).__init__()
self.model=nn.Sequential(
nn.Conv2d(3,32,5,1,2),
nn.MaxPool2d(2),
nn.Conv2d(32, 32, 5, 1, 2),
nn.MaxPool2d(2),
nn.Conv2d(32, 64, 5, 1, 2),
nn.MaxPool2d(2),
nn.Flatten(),
nn.Linear(64*4*4,64),
nn.Linear(64,10)
)
def forward(self,x):
x=self.model(x)
return x
if __name__ == '__main__':
tudui=Tudui()
input=torch.ones((64,3,32,32))
output=tudui(input)
print(output.shape)
运行:在train.py文件中运行
在terminal中输入:tensorboard --logdir=logs/train_logs(自己的日志存在哪,这里就填哪)
效果如图:
边栏推荐
- 一文速览EMNLP 2020中的Transformer量化论文
- [applet] the upload of the wechat applet issued by uniapp failed error: error: {'errcode': -10008,'errmsg':'Invalid IP
- "Intermediate and advanced test questions": what is the implementation principle of mvcc?
- "PHP Basics" uses echo statements to output information
- [resolved] SSO forwarding succeeded, and there was an unexpected error (type=internal server error, status=500) caused by parameters in the forwarding URL
- Harbor正确密码登录不上去
- 杂谈:把肉都烂在锅里就是保障学生权益了?
- mqtt指令收发请求订阅
- Design and development of GUI programming for fixed-point one click query
- 如何更新pip3?和Running pip as the ‘root‘ user can result in broken permissions and conflicting behaviour
猜你喜欢

A quick overview of transformer quantitative papers in emnlp 2020

综合案例、

Happy holidays, everyone

On data security

Internet of things industrial UART serial port to WiFi to wired network port to Ethernet Gateway WiFi module selection

北京五日游记

Lu Xun: I don't remember saying it, or you can check it yourself!

Comprehensive cases
![[ten thousand words long article] thoroughly understand load balancing, and have a technical interview with Alibaba Daniel](/img/fc/1ee8b77d675e34da2eb8574592c489.png)
[ten thousand words long article] thoroughly understand load balancing, and have a technical interview with Alibaba Daniel

软件调优方法有哪些?看看飞腾技术专家怎么说 | 龙蜥技术
随机推荐
Design and development of GUI programming for fixed-point one click query
Harbor can't log in with the correct password
shell脚本学习day01
如何在 60 秒内去分析和定位问题?
Shell scripts related
杂谈:把肉都烂在锅里就是保障学生权益了?
Hu related configuration
Gossip: is rotting meat in the pot to protect students' rights and interests?
A quick overview of transformer quantitative papers in emnlp 2020
[golang] golang develops wechat official account web page authorization function
JS access cookie example
Database startup report error_ user_ connect_ times > 0 error
Qt Creator代码风格插件Beautifier
kalibr标定realsenseD435i --多相机标定
[resolved] the new version of pychart (2022) connects to the server to upload files and reports an error of "command Rsync is not found in path", and the files cannot be synchronized
Use of string type "PHP Basics"
Lua iterator
[pytorch] resnet18, resnet20, resnet34, resnet50 network structure and Implementation
End of year summary
slf4j如何进行logback配置呢?