pytorch学习笔记2

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

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的话用这个命令

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

添加清华镜像

在这里插入图片描述
写python可以使用这个python console,是ipython内核,可以交互式运行Python语句(jupyter也是这个内核)

写代码时
在这里插入图片描述
上边部分写代码
在这里插入图片描述

下面部分进行实时调试

一个简单的Dataset类

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#对两个数据集进行拼接

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值