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#对两个数据集进行拼接
相关推荐
Purple Coder1 天前
BMS学习经验
学习
经济元宇宙1 天前
摄影培训行业百科:机构选择与学习路径全解析
大数据·人工智能·学习
じ☆冷颜〃1 天前
实分析与测度论、复分析、傅里叶分析、泛函分析、凸分析概述.
笔记·学习·数学建模·拓扑学·傅立叶分析
星夜夏空991 天前
STM32单片机学习(10)——GPIO输入
stm32·单片机·学习
kobesdu1 天前
【ROS2实战笔记-19】ROS2 生命周期节点的启动顺序、状态转换陷阱与热备方案
java·前端·笔记·机器人·ros·ros2
谙弆悕博士1 天前
快速学C语言——第16章:预处理
c语言·开发语言·chrome·笔记·创业创新·预处理·业界资讯
南境十里·墨染春水1 天前
linux学习进展 shell编程
linux·运维·学习
handler011 天前
UDP协议与网络通信知识点
c语言·网络·c++·笔记·网络协议·udp
xwz小王子1 天前
机器人学习十年进化史——从强化学习到VLA的范式变迁
大数据·学习·机器人
小新同学^O^1 天前
简单学习 --> WebSocket
java·websocket·网络协议·学习