当前位置:网站首页>【Pytorch】conv2d torchvision.transforms
【Pytorch】conv2d torchvision.transforms
2022-07-24 05:15:00 【rejudge】
- 示例代码
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)
# 统一图片维度,转为tensor格式
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) # 图片维度不一致,dataloader不能遍历
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

边栏推荐
- JSP+Dao整合
- Sword finger offer special assault edition day 7
- Pointer learning diary (IV) use structure and pointer (linked list)
- [Basic 6] - encapsulation and inheritance of classes, objects and classes
- Performance test process
- Learning pyramid context encoder network for high quality image painting paper notes
- 智能指针、左值引用右值引用、lambda表达式
- What is the sandbox technology in the data anti disclosure scheme?
- 反射的介绍
- [basic 7] - exceptions, capture and customize exceptions
猜你喜欢

How can NFT, whose stars enter the market against the market, get out of the independent market?

Tips for using the built-in variable props of BeanShell

JSP+Dao整合

Do you want to have a robot that can make cartoon avatars in three steps?

What are the core strengths of a knowledge base that supports customers quickly?

Chapter5 foundation of deep learning

DHCP principle and configuration

jdbc封装一个父类减少代码重复

Reading excerpts from Liu run's "bottom logic"

Image painting for irregular holes using partial revolutions paper notes
随机推荐
编译型语言和解释型语言的区别
JMeter record the BeanShell written into excel instance caused by an automatic data generation
Ben, reducing online importance is the same. Abnormal instance CP operation found
13. Write a program, in which a user-defined function is used to judge whether an integer is a prime number. The main function inputs a number and outputs whether it is a prime number.
Zhaoyi innovation gd25wdxxk6 SPI nor flash product series comes out
反射
Codeforce:d2. remove the substring (hard version) [greedy string + subsequence]
High performance architecture design of wechat circle of friends
Infineon launched the world's first TPM security chip with post quantum encryption technology for firmware update
[basic 7] - exceptions, capture and customize exceptions
支撑复杂的模型群监控、实时告警等t4 文件系统。e
【深度学习】(三)图像分类
[Huang ah code] Introduction to MySQL - 3. I use select *, and the boss directly rushed me home by train, but I still bought a station ticket
PPPoE网关模拟环境搭建
Accuracy of% connections. Now it is planned to meet the demand. The number of enterprises is enough
Installation and login login
IDEA:SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder“.
Hcip-- review the homework for the next day
Learning pyramid context encoder network for high quality image painting paper notes
Image to image translation with conditional advantageous networks paper notes