当前位置:网站首页>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(自己的日志存在哪,这里就填哪)
效果如图:
边栏推荐
- A quick overview of transformer quantitative papers in emnlp 2020
- Can Linux install sqlserver
- Usage scenarios for automated testing
- Use of string type "PHP Basics"
- 虚拟机克隆
- [applet] the upload of the wechat applet issued by uniapp failed error: error: {'errcode': -10008,'errmsg':'Invalid IP
- 北京五日游记
- C language: random generated number + insertion sort
- CommonTitleBar hide left right
- "PHP Basics" uses echo statements to output information
猜你喜欢

Record a PG master-slave setup and data synchronization performance test process

idea远程调试

剑指 Offer 58 - I. 翻转单词顺序

数据提取1

Is redis really slowing down?

如何在 60 秒内去分析和定位问题?

鲁迅:我不记得说没说过,要不你自己查!

How to obtain the cash flow data of advertising services to help analyze the advertising effect?
![[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

Ubuntu: install PostgreSQL
随机推荐
Ubuntu: install PostgreSQL
Bash: sudo: command not found in container
【Day42 文献精读】A Bayesian Model of Perceived Head-Centered Velocity during Smooth Pursuit Eye Movement
[ten thousand words long article] thoroughly understand load balancing, and have a technical interview with Alibaba Daniel
大家节日快乐哈
Day111.尚医通:集成NUXT框架、前台页面首页数据、医院详情页
Lua iterator
Development of three database general SQL code based on PG Oracle and MySQL
How to log in multiple wechat on the computer
idea远程调试
Usage scenarios for automated testing
Digital transformation driven by enterprise architecture!
CommonTitleBar hide left right
[flight control development foundation tutorial 4] crazy shell · open source formation UAV - serial port (optical flow data acquisition)
Lua迭代器
Practical new drug R & D project management platform
How does kettle handle text data transfer as' 'instead of null
擎创科技加入龙蜥社区,共建智能运维平台新生态
redis配置文件下载
剑指 Offer 58 - I. 翻转单词顺序