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#对两个数据集进行拼接
相关推荐
我的xiaodoujiao14 小时前
快速学习Python基础知识详细图文教程18--多线程
开发语言·python·学习·测试工具
AI Dog15 小时前
MathHub:数学建模学习社区,内置数学建模智能体Modulus
学习·数学建模·智能体·modulus·数学建模智能体
坐吃山猪15 小时前
WebFlux_学习Subscriber总结
java·开发语言·学习·webflux
GlueNa2SiO315 小时前
10-Docker生产环境部署与K8s入门
笔记·学习·docker·容器·kubernetes
茯苓gao15 小时前
无感FOC核心原理:没有编码器,电机如何获得转子电角度?
笔记·嵌入式硬件·学习
xiaoxiangsiyan16 小时前
机房交换机交换技术与服务器链路聚合深度指南
运维·服务器·网络·学习·自动化·bond
天天爱吃肉821816 小时前
【工程师笔记|新能源整车电控一次过CISPR25/BCI,汽车EMC/EMI落地十大核心设计技巧】
大数据·人工智能·笔记·python·汽车
代码地平线16 小时前
C++类与对象(中):默认成员函数与日期类实战
c++·笔记·算法
chemddd16 小时前
快递 选择
学习·交友
单词记忆方法研究16 小时前
探索上海背单词小程序品牌:高效学习工具的优化之路
大数据·学习·小程序