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#对两个数据集进行拼接
相关推荐
AI即插即用23 分钟前
即插即用涨点系列 (八):AMDNet 详解!AAAI 2025 SOTA,MLP 融合多尺度分解(MDM)与 AMS 的涨点新范式。
人工智能·pytorch·深度学习·目标检测·计算机视觉·transformer
BullSmall31 分钟前
《道德经》第五十八章
学习
摇滚侠1 小时前
Vue 项目实战《尚医通》,预约挂号的路由与静态搭建,笔记36
javascript·vue.js·笔记
Keep_Trying_Go1 小时前
论文STEERER人群计数,车辆计数以及农作物计数算法详解(pytorch)
人工智能·pytorch·python
三品吉他手会点灯1 小时前
STM32F103学习笔记-16-RCC(第4节)-使用 HSI 配置系统时钟并用 MCO 监控系统时钟
笔记·stm32·单片机·嵌入式硬件·学习
gzu_011 小时前
基于昇腾 配置pytorch环境
人工智能·pytorch·python
Lester_11011 小时前
嵌入式学习笔记 - 关于看门狗定时器的喂狗的操作放在中断还是放在主循环
笔记·单片机·学习
缪懿2 小时前
JavaEE:多线程基础,多线程的创建和用法
java·开发语言·学习·java-ee
AA陈超3 小时前
ASC学习笔记0017:返回此能力系统组件的所有属性列表
c++·笔记·学习·ue5·虚幻引擎
谅望者3 小时前
数据分析笔记07:Python编程语言介绍
大数据·数据库·笔记·python·数据挖掘·数据分析