新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
pytorch數(shù)據(jù)處理:定義自己的數(shù)據(jù)集合實(shí)例-創(chuàng)新互聯(lián)
數(shù)據(jù)處理
版本1
#數(shù)據(jù)處理 import os import torch from torch.utils import data from PIL import Image import numpy as np #定義自己的數(shù)據(jù)集合 class DogCat(data.Dataset): def __init__(self,root): #所有圖片的絕對路徑 imgs=os.listdir(root) self.imgs=[os.path.join(root,k) for k in imgs] def __getitem__(self, index): img_path=self.imgs[index] #dog-> 1 cat ->0 label=1 if 'dog' in img_path.split('/')[-1] else 0 pil_img=Image.open(img_path) array=np.asarray(pil_img) data=torch.from_numpy(array) return data,label def __len__(self): return len(self.imgs) dataSet=DogCat('./data/dogcat') print(dataSet[0])
本文標(biāo)題:pytorch數(shù)據(jù)處理:定義自己的數(shù)據(jù)集合實(shí)例-創(chuàng)新互聯(lián)
網(wǎng)站URL:http://www.ef60e0e.cn/article/dpipjc.html