中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

做網(wǎng)站和seo流程接推廣app任務(wù)的平臺

做網(wǎng)站和seo流程,接推廣app任務(wù)的平臺,網(wǎng)站做游客留言做,織夢和wordpress哪個文件1、前言: 在閱讀之前,需要配置好對應(yīng)pytorch版本。 對于一般學習,使用cpu版本的即可。參考教程點我 導(dǎo)入pytorch包,使用如下命令即可。 import torch # 注意雖然叫pytorch,但是在引用時是引用torch2、神經(jīng)網(wǎng)絡(luò)獲取…

1、前言:

在閱讀之前,需要配置好對應(yīng)pytorch版本。
對于一般學習,使用cpu版本的即可。參考教程點我
導(dǎo)入pytorch包,使用如下命令即可。

import torch   # 注意雖然叫pytorch,但是在引用時是引用torch

2、神經(jīng)網(wǎng)絡(luò)獲取數(shù)據(jù)

神經(jīng)網(wǎng)絡(luò)獲取數(shù)據(jù)主要用到Dataset和Dataloader兩個方法
Dataset主要用于獲取數(shù)據(jù)以及對應(yīng)的真實label
Dataloader主要為后面的網(wǎng)絡(luò)提供不同的數(shù)據(jù)形式
在torch.utils.data包內(nèi)提供了DataSet類,可在Pytorch官網(wǎng)看到對應(yīng)的描述

class Dataset(Generic[T_co]):r"""An abstract class representing a :class:`Dataset`.All datasets that represent a map from keys to data samples should subclassit. All subclasses should overwrite :meth:`__getitem__`, supporting fetching adata sample for a given key. Subclasses could also optionally overwrite:meth:`__len__`, which is expected to return the size of the dataset by many:class:`~torch.utils.data.Sampler` implementations and the default optionsof :class:`~torch.utils.data.DataLoader`. Subclasses could alsooptionally implement :meth:`__getitems__`, for speedup batched samplesloading. This method accepts list of indices of samples of batch and returnslist of samples... note:::class:`~torch.utils.data.DataLoader` by default constructs an indexsampler that yields integral indices.  To make it work with a map-styledataset with non-integral indices/keys, a custom sampler must be provided."""def __getitem__(self, index) -> T_co:raise NotImplementedError("Subclasses of Dataset should implement __getitem__.")# def __getitems__(self, indices: List) -> List[T_co]:# Not implemented to prevent false-positives in fetcher check in# torch.utils.data._utils.fetch._MapDatasetFetcherdef __add__(self, other: "Dataset[T_co]") -> "ConcatDataset[T_co]":return ConcatDataset([self, other])# No `def __len__(self)` default?# See NOTE [ Lack of Default `__len__` in Python Abstract Base Classes ]# in pytorch/torch/utils/data/sampler.py

根據(jù)上述描述可知,Dataset是一個抽象類,用于表示數(shù)據(jù)集。你可以通過繼承這個類并實現(xiàn)以下方法來自定義數(shù)據(jù)集:

__len__(self): 返回數(shù)據(jù)集的大小,即數(shù)據(jù)集中有多少個樣本。
__getitem__(self, idx): 根據(jù)索引 idx 返回數(shù)據(jù)集中的一個樣本和對應(yīng)的標簽。

3、案例

使用Dataset讀取文件夾E:\Python_learning\Deep_learning\dataset\hymenoptera_data\train\ants下所有圖片。并獲取對應(yīng)的label,該數(shù)據(jù)集的文件夾的名字為對應(yīng)的標簽,而文件夾內(nèi)為對應(yīng)的訓(xùn)練集的圖片。

import os
from torch.utils.data import Dataset
from PIL import Image
from torch.utils.tensorboard import SummaryWriter
from torchvision import transformsclass MyDataset(Dataset):def __init__(self, root_path, label):self.root_path = root_pathself.label = labelself.img_path = os.path.join(root_path, label)  # 拼接路徑print(f"圖片路徑: {self.img_path}")  # 打印路徑以進行調(diào)試try:self.img_path_list = os.listdir(self.img_path)  # 列出文件夾中的文件print(f"圖片列表: {self.img_path_list}")  # 打印圖片列表以進行調(diào)試except PermissionError as e:print(f"權(quán)限錯誤: {e}")except FileNotFoundError as e:print(f"文件未找到錯誤: {e}")def __getitem__(self, index):img_index = self.img_path_list[index]img_path = os.path.join(self.img_path, img_index)try:img = Image.open(img_path)except Exception as e:print(f"讀取圖片時出錯: {e}, 圖片路徑: {img_path}")raise elabel = self.labelreturn img, labeldef __len__(self):return len(self.img_path_list)# 實例化這個類
my_data = MyDataset(root_path=r'E:\Python_learning\Deep_learning\dataset\hymenoptera_data\train', label='ants')
writer = SummaryWriter('logs')
for i in range(my_data.__len__()):img, label = my_data[i]  # 依次獲取對應(yīng)的圖片# 此處img為PIL Image, 使用transforms中的ToTensor方法轉(zhuǎn)化為tensor格式writer.add_image(tag=label, img_tensor=transforms.ToTensor()(img), global_step=i)
writer.close()
print(f"當前文件夾下{i + 1}張圖片已讀取完畢,請在Tensorboard中查看")

在這里插入圖片描述
在控制臺輸入tensorboard --logdir='E:\Python_learning\Deep_learning\note\logs'打開tensorboard查看
在這里插入圖片描述
在這里插入圖片描述

http://www.risenshineclean.com/news/22834.html

相關(guān)文章:

  • 企業(yè)網(wǎng)站html源代碼永久免費二級域名申請
  • 二次網(wǎng)站開發(fā)電商seo是什么
  • 輕定制網(wǎng)站建設(shè)seo在中國
  • 河北網(wǎng)站建設(shè)與推廣站長域名查詢工具
  • 網(wǎng)站設(shè)計開發(fā)人員招聘40個免費靠譜網(wǎng)站
  • 食品包裝設(shè)計價格seo崗位工資
  • 做網(wǎng)站用windows和 linux廣州網(wǎng)絡(luò)推廣公司有哪些
  • 企業(yè)網(wǎng)站建設(shè)論文糕點烘焙專業(yè)培訓(xùn)學校
  • 網(wǎng)站域名免費申請網(wǎng)站排名優(yōu)化培訓(xùn)哪家好
  • 做 愛 網(wǎng)站小視頻下載查詢網(wǎng)官網(wǎng)
  • 中石化第五建設(shè)有限公司官方網(wǎng)站濰坊關(guān)鍵詞優(yōu)化平臺
  • wordpress商家展示主題企業(yè)網(wǎng)站的優(yōu)化建議
  • 社區(qū)工作者優(yōu)化設(shè)計方法
  • 保定市住房和城鄉(xiāng)建設(shè)局網(wǎng)站競價廣告點擊軟件
  • 武漢黃浦醫(yī)院網(wǎng)站建設(shè)關(guān)鍵詞優(yōu)化排名平臺
  • 獨立做網(wǎng)站需要學什么條件關(guān)鍵詞優(yōu)化怎么寫
  • 做代購注冊什么網(wǎng)站搜索引擎優(yōu)化解釋
  • 臺州網(wǎng)站開發(fā)太原網(wǎng)站優(yōu)化公司
  • 學會了vue 能搭建一個網(wǎng)站平臺比較靠譜的電商培訓(xùn)機構(gòu)
  • jsp開發(fā)網(wǎng)站百度指數(shù)人群畫像哪里查詢
  • 網(wǎng)站備案的是域名還是空間電子商務(wù)網(wǎng)站建設(shè)與維護
  • 搭建網(wǎng)站難嗎電商培訓(xùn)學校
  • 玉溪做網(wǎng)站的公司seo的優(yōu)化步驟
  • 奪寶網(wǎng)站怎樣做優(yōu)化泰安做百度推廣的公司
  • 網(wǎng)站開發(fā)有什么點子軟文生成器
  • 公司主頁網(wǎng)站怎么做免費推廣軟件 推廣幫手
  • 服務(wù)器方面如何規(guī)劃建設(shè)網(wǎng)站外貿(mào)網(wǎng)站有哪些平臺
  • 政府門戶網(wǎng)站建設(shè)的基本意義有哪些網(wǎng)絡(luò)營銷的概念和特點是什么
  • 網(wǎng)站建設(shè)項目合同如何做好網(wǎng)絡(luò)推廣
  • 網(wǎng)站建設(shè)網(wǎng)站維護的具體內(nèi)容是什么seo推廣員是做什么的