pytorch | 学习笔记1

教程

PyTorch深度学习快速入门教程(绝对通俗易懂!)【小土堆】


安装

pytorch | 学习笔记1_第1张图片
pytorch官网
pytorch快速安装【清华源】(真的很快)

Python | win10 python3.6.7安装pytorch(很久以前镜像挂了的时候安装成功的经验)


pycharm与jupyter比较

pytorch | 学习笔记1_第2张图片


练手小代码

from torch.utils.data import Dataset
from PIL import Image
import os

class MyData(Dataset):

    def __init__(self, root_dir, label_dir):
        self.root_dir = root_dir
        self.label_dir = label_dir
        self.path = os.path.join(self.root_dir, self.label_dir)
        self.img_path = os.listdir(self.path)

    def __getitem__(self, idx):
        img_name = self.img_path[idx]
        img_item_path = os.path.join(self.root_dir, self.label_dir, img_name)
        img = Image.open(img_item_path)
        label = self.label_dir
        return img, label

    def __len__(self):
        return len(self.img_path)


root_dir = "dataset/train"
ants_label_dir = "ants"
bees_label_dir = "bees"
ants_dataset = MyData(root_dir, ants_label_dir)
bees_dataset = MyData(root_dir, bees_label_dir)

train_dataset = ants_dataset + bees_dataset

你可能感兴趣的:(pytorch)