pytorch学习笔记2

首先如果遇到conda找不到包,pip老是超时的情况建议添加一下镜像源

conda的

python 复制代码
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
# reference
# https://mirror.tuna.tsinghua.edu.cn/help/anaconda/

cuda最好还是像下面链接里的用10.0

https://blog.csdn.net/zzq060143/article/details/88042075

安装pytorch的时候,主要是把官网指令后面的-c pytorch删掉,-c pytorch的意思是,安装下载的channel强制为pytorch官网的channel。所以需要删除才能走清华镜像的channel。

pip的话用这个命令

python 复制代码
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

添加清华镜像

写python可以使用这个python console,是ipython内核,可以交互式运行Python语句(jupyter也是这个内核)

写代码时

上边部分写代码

下面部分进行实时调试

一个简单的Dataset类

python 复制代码
import os
from PIL import Image
from torch.utils.data import Dataset

class MyDateSet(Dataset):
    def __init__(self,root_dir,lable_dir):#提供全局变量,root_dir通常为train文件的地址,lable_dir提供标签
        self.root_dir=root_dir
        self.lable_dir=lable_dir
        self.path=os.path.join(root_dir,lable_dir)
        self.img_path=os.listdir(self.path)


    def __getitem__(self, idx):
        img_name=self.img_path[idx]
        img_item_name=os.path.join(self.root_dir,self.lable_dir,img_name)
        img=Image.open(img_item_name)
        lable=self.lable_dir
        return img,lable

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

root_dir=r'hymenoptera_data/train'
ants_lable_dir=r'ants'
bees_lable_dir=r'bees'
ants_dataset=MyDateSet(root_dir,ants_lable_dir)
bees_dataset=MyDateSet(root_dir,bees_lable_dir)

train_dataset=ants_dataset+bees_dataset#对两个数据集进行拼接
相关推荐
byzh_rc5 分钟前
[模式识别-从入门到入土] 无监督学习
学习·机器学习·支持向量机
浩浩的科研笔记21 分钟前
投论文常用技术笔记-使用visio导出贴合图像尺寸大小的PDF(无白边、无黑框)
笔记·pdf·论文笔记
SJLoveIT29 分钟前
神经网络反向传播推导笔记 (整理版)
人工智能·笔记·神经网络
love530love36 分钟前
【笔记】华硕 ROG MAXIMUS Z890 HERO 主板 BIOS 更新完整操作实录
运维·人工智能·windows·笔记·单片机·嵌入式硬件·bios
tgethe1 小时前
Nginx笔记
运维·笔记·nginx
nnerddboy1 小时前
解决传统特征波段选择的局限性:1.对偶学习
学习·算法·机器学习
初九之潜龙勿用1 小时前
GMM NZ 全流程详解实战:FSDP MOE 训练加速
人工智能·pytorch·python
山土成旧客1 小时前
【Python学习打卡-Day28】类的蓝图:从模板到对象的构建艺术
linux·python·学习
三品吉他手会点灯1 小时前
STM32F103 学习笔记-20-通信的基本概念
笔记·stm32·单片机·嵌入式硬件·学习
悠哉悠哉愿意1 小时前
【嵌入式学习笔记】GPIO与LED
笔记·单片机·嵌入式硬件·学习