目錄
1、Pytorch環(huán)境的配置與安裝。
2、pytorch編輯器的選擇
(1)pycharm (下載社區(qū)版)
(2)jupyter (可以交互)
3、為什么torch.cuda.is_available()返回False
4、python學(xué)習(xí)中的兩大法寶函數(shù)
(1)dir() 函數(shù):打開(kāi)、看見(jiàn)
(2)help()函數(shù):說(shuō)明書(shū)
5、Pycharm 及Jupyter的使用對(duì)比:
(1)Pycharm文件
(2)Pycharm控制臺(tái)
(3)Jupyter:
6、Pytorch加載數(shù)據(jù)初認(rèn)識(shí)+實(shí)戰(zhàn)
1、Pytorch環(huán)境的配置與安裝。
(1)建議安裝:Anaconda?
(2)檢查顯卡:GPU
(3)管理環(huán)境(不同版本的pytorch 版本不同):
conda create -n pytorch python=3.6
(4)檢測(cè)自己的電腦是否可以使用:
2、pytorch編輯器的選擇
(1)pycharm (下載社區(qū)版)
(2)jupyter (可以交互)
啟動(dòng)本地的jupyter :?
3、為什么torch.cuda.is_available()返回False
(1)檢查自己的電腦是否支持GPU(可以用一些電腦管家,eg: 魯大師等查看)
4、python學(xué)習(xí)中的兩大法寶函數(shù)
(1)dir() 函數(shù):打開(kāi)、看見(jiàn)
(2)help()函數(shù):說(shuō)明書(shū)
# 例子:
torch.cuda.is_available()
5、Pycharm 及Jupyter的使用對(duì)比:
Jupyter:(以塊為運(yùn)行單位)
①shift + 回車
# 例子:
print("Start")
a = 'hello world'
b = 2019
c = a + b
print(c)
(1)Pycharm文件
代碼是以塊為一個(gè)整體運(yùn)行的話;
整改完后,從頭開(kāi)始執(zhí)行。
python文件的塊是所有行的代碼。
(2)Pycharm控制臺(tái)
整改完后,會(huì)從錯(cuò)誤的地方執(zhí)行。
以每一行為塊,運(yùn)行的。
(3)Jupyter:
整改完后,從錯(cuò)誤的地方開(kāi)始運(yùn)行。
以任意行為塊運(yùn)行的。
6、Pytorch加載數(shù)據(jù)初認(rèn)識(shí)+實(shí)戰(zhàn)
Dataset:提供一種方式去獲取數(shù)據(jù)及其label。
????????????????①如何獲取每一個(gè)數(shù)據(jù)及其label。
????????????????②告訴我們總共有多少個(gè)數(shù)據(jù)。
Dataloader:為后面的網(wǎng)絡(luò)提供不同的數(shù)據(jù)形式。
step01:下載數(shù)據(jù)集。
step02:使用數(shù)據(jù)集,代碼如下:
文件夾目錄:
from torch.utils.data import Dataset
from PIL import Image
import os
class MyData(Dataset):
def __init__(self, root_dir, label_dir):
# self.root_dir = 'pytorch_xiaotudui/bee_ant/dataset'
# self.label_dir = 'ants'
self.root_dir = root_dir
self.label_dir = label_dir
self.path = os.path.join(self.root_dir, self.label_dir) # 路徑拼接
self.img_path = os.listdir(self.path) # 獲取到圖片下的所有地址,以列表的形式展示
def __getitem__(self, idx):
img_name = self.img_path[idx]
img_item_path = os.path.join(self.root_dir, self.label_dir, img_name)
img = Image.open(img_item_path)
label = self.label_dir
return img, label
def __len__(self):
return len(self.img_path)
# 獲取螞蟻的數(shù)據(jù)集
root_dir_out = 'pytorch_xiaotudui/bee_ant/dataset'
ants_label_dir = 'ants'
ants_dataset = MyData(root_dir_out, ants_label_dir)
# 獲取蜜蜂的數(shù)據(jù)集
bees_label_dir = 'bees'
bees_dataset = MyData(root_dir_out, bees_label_dir)
# 兩個(gè)數(shù)據(jù)集的集合
train_dataset = ants_dataset + bees_dataset # 螞蟻數(shù)據(jù)集在前,蜜蜂數(shù)據(jù)集在后
?運(yùn)行結(jié)果:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-822458.html
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-822458.html
到了這里,關(guān)于小土堆pytorch學(xué)習(xí)筆記001的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!