2 Star 53 Fork 20

qiaofengsheng / pytorch-unet

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
data.py 923 Bytes
一键复制 编辑 原始数据 按行查看 历史
qiaofengsheng 提交于 2022-01-13 21:15 . 2022年01月13日提交
import os
from torch.utils.data import Dataset
from utils import *
from torchvision import transforms
transform=transforms.Compose([
transforms.ToTensor()
])
class MyDataset(Dataset):
def __init__(self,path):
self.path=path
self.name=os.listdir(os.path.join(path,'SegmentationClass'))
def __len__(self):
return len(self.name)
def __getitem__(self, index):
segment_name=self.name[index] #xx.png
segment_path=os.path.join(self.path,'SegmentationClass',segment_name)
image_path=os.path.join(self.path,'JPEGImages',segment_name.replace('png','jpg'))
segment_image=keep_image_size_open(segment_path)
image=keep_image_size_open(image_path)
return transform(image),transform(segment_image)
if __name__ == '__main__':
data=MyDataset('D:\pythonSpace\data\VOC\VOCdevkit\VOC2007')
print(data[0][0].shape)
print(data[0][1].shape)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/qiaofengsheng/pytorch-unet.git
git@gitee.com:qiaofengsheng/pytorch-unet.git
qiaofengsheng
pytorch-unet
pytorch-unet
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891