我的创作纪念日

机缘

每次都是新的开始,决定用博客记录所学知识的那一刻,觉得自己开始尝试做一下东西,也真正有了收获。


收获

看过好的创作者会把自己的思考或者一系列总结记录下来,我目前只是单纯的记录,总结的却很少,不过仅仅是记录,就让我觉得学习的过程中真正的学到了些东西,忘记的内容回来翻阅,也会觉得这些东西是熟悉的。


日常

学习与创作结合,但有时候也会懒得记录,觉得脑子能记着,但事实证明,好记性不如烂笔头!!


成就

from torch.utils.data import DataLoader,Dataset
from tqdm import tqdm

class CatDogDataset(Dataset):

    def __init__(self, filepath,transform=None):
        self.images = []
        self.labels = []
        self.transform = transform
        for catelog in tqdm(os.listdir(filepath)):
          for filename in os.listdir(filepath+catelog):
            image = Image.open(filepath+catelog+"/"+ filename)
            image = self.transform(image)           
            self.images.append(image)
            #这部分根据需要修改
            if catelog == 'Cat':     
                self.labels.append(0)
            elif catelog == 'Dog':
                self.labels.append(1)
        self.labels = torch.LongTensor(self.labels)    
    
    def __getitem__(self, index):           
        return self.images[index], self.labels[index]
 
    def __len__(self):                      
        images = np.array(self.images)
        len = images.shape[0]
        return len

data_transform = transforms.Compose([
        transforms.Grayscale(3),
        transforms.Resize((224,224)),
        # transforms.RandomRotation(degrees=45),
        # transforms.RandomHorizontalFlip(p=0.3),
        # transforms.RandomVerticalFlip(p=0.05),
        # transforms.RandomGrayscale(p=0.1),
        # transforms.RandomCrop((224,224)),
        # transforms.Resize((224,224)),
        transforms.ToTensor(),
        # transforms.Normalize(mean=[0.5,0.5,0.5],std=[1.0,1.0,1.0])
])

train_dir='xxx'
val_dir='xxx'
batch_size = 32

train_dataset = CatDogDataset(train_dir, transform = data_transform)
val_dataset = CatDogDataset(val_dir, transform = data_transform)
train_dataloader = DataLoader(train_dataset, batch_size=batch_size, shuffle=True, num_workers=0)
val_dataloader = DataLoader(val_dataset, batch_size=batch_size, shuffle=True, num_workers=0)

憧憬

之后会继续记录自己的学习,也计划着总结一些东西,也期待着自己到底能弄成什么样子。

你可能感兴趣的:(开发语言)