五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

PyTorch Tutorial 09 - Dataset and Dat...

2023-02-16 11:36 作者:Mr-南喬  | 我要投稿

教程Python代碼如下:


"""

epoch = 1 forward and backward pass of ALL training samples

batch_size = numberlof training samples in one forward & backward pass

number of iterations = number of passes,each pass using [batch_size] number of samples

e.g. 100 samples,batch_size=20 --> 100/20 = 5 iterations for 1 epoch

"""

import torch

import torchvision

from torch.utils.data import Dataset, DataLoader

import numpy as np

import math


#實(shí)現(xiàn)自己的自定義數(shù)據(jù)集

class WineDataset():

??def __init__(self):

????# data loading, 數(shù)據(jù)加載

????xy = np.loadtxt('./Data/wine.csv',delimiter=",", dtype=np.float32, skiprows=1) #delomiter分隔符,skiprows=1跳過(guò)第一行(第一行為標(biāo)題)

????# 把數(shù)據(jù)集分成 x 和 y

????self.x = torch.from_numpy(xy[:,1:]) #不要第一行

????self.y = torch.from_numpy(xy[:, [0]]) # n_samples, 1:只要第一列,這樣就有了樣品的大小數(shù)

????self.n_samples = xy.shape[0]



??def __getitem__(self, index):

????# dataset[0], 允許以后進(jìn)行索引,所以我們可以調(diào)用索引為0的數(shù)據(jù)集

????return self.x[index], self.y[index]


??def __len__(self):

????# len(dataset), 調(diào)用數(shù)據(jù)集的長(zhǎng)度

????return self.n_samples


dataset = WineDataset()

# firat_data = dataset[0]

# features, labels = firat_data

# print(features, labels)


# 使用數(shù)據(jù)加載器

dataloader = DataLoader(dataset = dataset, batch_size=4, shuffle=True, num_workers=0)

"""

datatiter = iter(dataloader)

data = next(datatiter)

features, labels = data

print(features, labels)

"""


# training loop

num_epochs = 2

total_samples = len(dataset)

n_iterations = math.ceil(total_samples/4)

print(total_samples, n_iterations)


for epoch in range(num_epochs):

??for i, (inputs, labels) in enumerate(dataloader):

????#forward, backward, updata

????if (i+1) % 5 == 0:

??????print(f'epoch {epoch+1}/{num_epochs}, step {i+1}/{n_iterations}, inputs {inputs.shape}')

PyTorch Tutorial 09 - Dataset and Dat...的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
周宁县| 玉溪市| 锡林浩特市| 繁昌县| 凤翔县| 凤山县| 丽水市| 胶南市| 昆山市| 墨脱县| 博乐市| 海原县| 中西区| 阳高县| 江口县| 股票| 乐昌市| 虎林市| 镇雄县| 巴青县| 尉犁县| 柞水县| 凭祥市| 阜康市| 新乐市| 新野县| 承德县| 徐闻县| 长寿区| 六盘水市| 崇文区| 五台县| 正阳县| 瑞昌市| 北辰区| 二连浩特市| 介休市| 汉中市| 清涧县| 四川省| 怀远县|