当前位置:网站首页>【Pytorch】conv2d torchvision.transforms
【Pytorch】conv2d torchvision.transforms
2022-07-24 07:34:00 【rejudge】
- Sample code
from torchvision import transforms
from torch.utils.data import Dataset, DataLoader
from PIL import Image
from torch import nn
import os
class ImgDataset(Dataset):
def __init__(self, root_dir):
self.root_dir = root_dir
self.img_path_list = os.listdir(root_dir)
# Unified picture dimension , To tensor Format
self.compose = transforms.Compose([transforms.Resize((500, 500)), transforms.ToTensor()])
def __getitem__(self, idx):
img_path = os.path.join(self.root_dir, self.img_path_list[idx])
img = Image.open(img_path)
# img = transforms.ToTensor()(img) # Inconsistent picture dimensions ,dataloader Can not traverse
img = self.compose(img)
return img
def __len__(self):
return len(self.img_path_list)
class MyConv(nn.Module):
def __init__(self):
super(MyConv, self).__init__()
self.conv2d = nn.Conv2d(in_channels=3, out_channels=6, kernel_size=3, stride=1)
def forward(self, data):
data = self.conv2d(data)
return data
dataset = ImgDataset('./img_data')
dataloader = DataLoader(dataset=dataset, batch_size=2, shuffle=False, drop_last=False)
test_conv2d = MyConv()
print('befor conv', '=' * 20)
for i in dataloader:
print(i.shape)
print('after conv', '=' * 20)
for i in dataloader:
print(test_conv2d(i).shape)
- img_data

边栏推荐
- There are two tables in Oracle, a and B. these two tables need to be associated with the third table C. how to update the field MJ1 in table a to the value MJ2 in table B
- Induction, generalization, deduction
- Source code analysis of Nacos configuration center
- 二维平面多段线Y轴最短距离
- fopen、fwrite、fseek、ftell、fread使用demo
- Notes on the basics of using parameters in libsvm (1)
- 25.消息订阅与发布——PubSub-js
- Who can stand it when the project goes online
- C language file operation
- Log in to the server using the fortress machine (springboard machine)
猜你喜欢

Oauth2==sso three protocols. Oauth2 four modes

Unity中使用深度和法线纹理

Li Kou, niuke.com - > linked list related topics (Article 1) (C language)

Mitre att & CK ultra detailed learning notes-01 (background, terms, cases)

Requests crawler multi page crawling to KFC restaurant location

Kali安装pip以及pip换源

Bookkeeping app: xiaoha bookkeeping 2 - production of registration page

全国职业院校技能大赛网络安全B模块 缓冲区溢出漏洞

Mutual implementation of stack and queue (c)

MITRE ATT&CK超详细学习笔记-02(大量案例)
随机推荐
觉维设计响应式布局
【云原生】MySql索引分析及查询优化
Log in to the server using the fortress machine (springboard machine)
Cloud version upgrade
Win10 sound icon has no sound
爬虫学习-概述
Bookkeeping app: xiaoha bookkeeping 2 - production of registration page
Learning strategies of 2D target detection overview (final chapter)
Development system selection route
C语言文件操作
25.消息订阅与发布——PubSub-js
给一个字符串 ① 请统计出其中每一个字母出现的次数② 请打印出字母次数最多的那一对
23.组件自定义事件
研究会2022.07.22--对比学习
MITRE ATT&CK超详细学习笔记-01(背景,术语,案例)
[leetcode] 11. Container with the most water - go language solution
Deep analysis of data storage in memory
Requests crawler implements a simple web page collector
Wild pointer, null pointer, invalid pointer
Game three piece chess