日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

在PyTorch中转换数据

發(fā)布時(shí)間:2023/11/29 编程问答 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在PyTorch中转换数据 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

In continuation of my previous post ,we will keep on deep diving into basic fundamentals of PyTorch. In this post we will discuss about ways to transform data in PyTorch.

延續(xù)我以前的 發(fā)布后 我們將繼續(xù)深入研究PyTorch的基本原理。 在這篇文章中,我們將討論在PyTorch中轉(zhuǎn)換數(shù)據(jù)的方法。

需要數(shù)據(jù)擴(kuò)充 (Need for Data Augmentation)

Data augmentation is an approach that aids in increasing the variety of data for training models thus increasing the breadth of available information.The augmented data thus represents a more comprehensive set of possible data points. It improves the performance and ability of the model to generalize and hence addresses overfitting.

數(shù)據(jù)擴(kuò)充是一種有助于增加訓(xùn)練模型數(shù)據(jù)種類的方法,從而增加了可用信息的廣度。 它提高了模型的性能和泛化能力,從而解決了過擬合問題。

如何進(jìn)行轉(zhuǎn)換? (How to perform transformations?)

torchvision module of PyTorch provides transforms to accord common image transformations. These transformations can be chained together using Compose.

PyTorch的torchvision模塊提供轉(zhuǎn)換以符合常見的圖像轉(zhuǎn)換。 可以使用Compose將這些轉(zhuǎn)換鏈接在一起。

  • transforms.Compose- Compose helps to bind multiple transforms together so we can use more than one transformation.

    transforms.Compose -Compose有助于將多個(gè)轉(zhuǎn)換綁定在一起,因此我們可以使用多個(gè)轉(zhuǎn)換。

Multiple transformations have been chained using transforms.Compose and then it has been passed as an argument while loading dataset.

已使用transforms.Compose鏈接了多個(gè)轉(zhuǎn)換,然后在加載數(shù)據(jù)集時(shí)將其作為參數(shù)傳遞。

  • transforms.ToTensor — Applies a scaling operation of changing range from 0–255 to 0–1. It converts a PIL Image or numpy ndarray to a tensor (C x H x W) in the range of 0–1.

    transforms.ToTensor —應(yīng)用縮放操作,將范圍從0–255更改為0–1。 它將PIL圖像或numpy ndarray轉(zhuǎn)換為范圍為0-1的張量(C xH x W)。

  • transforms.Normalize- This operation normalizes a tensor image with provided mean and standard deviation. For an image with 3 channels (RGB), 3 values for mean and 3 values for standard deviation are given as parameters(in form of tuple) corresponding to each channel.

    transforms.Normalize-此操作使用提供的均值和標(biāo)準(zhǔn)差對(duì)張量圖像進(jìn)行歸一化。 對(duì)于具有3個(gè)通道(RGB)的圖像,將給出3個(gè)平均值和3個(gè)標(biāo)準(zhǔn)差值作為與每個(gè)通道相對(duì)應(yīng)的參數(shù)(以元組的形式)。

Example :- transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)) where first tuple is for mean and second for standard deviation.

示例: -transforms.Normalize((0.5,0.5,0.5),(0.5,0.5,0.5))其中,第一個(gè)元組表示平均值,第二個(gè)元組表示標(biāo)準(zhǔn)偏差。

  • transforms.Pad — It pads given image on all sides with the given padding value. If a single integer value is provided for padding parameter then that value is used to pad all borders. If tuple of length 2 is provided then this acts as padding on left/right and top/bottom respectively. For constant padding mode default value for fill 0 is used.

    transforms.Pad —它使用給定的填充值在所有面上填充給定的圖像。 如果為填充參數(shù)提供單個(gè)整數(shù)值,則該值將用于填充所有邊界。 如果提供長(zhǎng)度為2的元組,則這分別充當(dāng)左側(cè)/右側(cè)和頂部/底部的填充。 對(duì)于恒定填充模式 ,使用填充 0的默認(rèn)值。

Example :- torchvision.transforms.Pad(10)

示例: -torchvision.transforms.Pad(10)

Using torchvision.transforms.Pad(10)使用torchvision.transforms.Pad(10)

You can notice the output size of the transformed image.

您會(huì)注意到轉(zhuǎn)換后的圖像的輸出大小。

Using image from FMNIST dataset, used in my previous post. Image size for this dataset is 28*28 .

使用 我以前的 文章中 使用的 FMNIST數(shù)據(jù)集中的 圖像 。 該數(shù)據(jù)集的圖像大小為28 * 28。

  • transforms.RandomHorizontalFlip — Flipping operation helps in changing the orientation of the image. RandomHorizontalFlip changes the orientation horizontally similarly we can use RandomVerticalFlip for changing vertical orientation. It flips the image randomly with a given probability (p).

    transforms.RandomHorizo??ntalFlip —翻轉(zhuǎn)操作有助于更改圖像的方向。 類似地,我們可以使用RandomVerticalFlip來改變垂直方向。 它以給定的概率(p)隨機(jī)翻轉(zhuǎn)圖像。

Example :- torchvision.transforms.RandomHorizontalFlip(p=1)

示例: -torchvision.transforms.RandomHorizo??ntalFlip(p = 1)

Using torchvision.transforms.RandomHorizontalFlip(p=1)使用torchvision.transforms.RandomHorizo??ntalFlip(p = 1)
  • transforms.CenterCrop- We can do cropping of an image using this transformation. CenterCrop crops the given image at the center as per the size parameter. Crop can be square or rectangle in shape depending on the size parameter dimensions. Similarly, we have RandomCrop that crops the given image at a random location.

    transforms.CenterCrop-我們可以使用此變換來裁剪圖像。 CenterCrop根據(jù)大小參數(shù)在中心裁剪給定圖像。 作物的形狀可以是正方形或矩形,具體取決于大小參數(shù)的尺寸。 同樣,我們有RandomCrop可以在任意位置裁剪給定圖像。

Example :- torchvision.transforms.CenterCrop((18, 18))

示例: -torchvision.transforms.CenterCrop((18,18))

Using 使用 torchvision.transforms.CenterCrop((18, 18))torchvision.transforms.CenterCrop((18,18))
  • transforms.Resize —To resize image this transformation can be used. It is also very useful incase of images with large dimensions to reduce it to a particular size (parameter for desired output size) . By resizing, the resolution can be lowered and thus will help in training the network faster.

    transforms.Resize —要調(diào)整圖像的大小,可以使用此變換。 在具有大尺寸的圖像的情況下將其減小到特定尺寸 (用于期望的輸出尺寸的參數(shù))也是非常有用的。 通過調(diào)整大小,可以降低分辨率,從而有助于更快地訓(xùn)練網(wǎng)絡(luò)。

Example :- torchvision.transforms.Resize((300, 300))

范例: -torchvision.transforms.Resize((300,300))

Using torchvision.transforms.Resize((300, 300))使用torchvision.transforms.Resize((300,300))
  • transforms.RandomRotation- To rotate an image by certain degrees (parameter). If degrees is an integer rather than (min, max) then the range is interpreted as (-degrees, +degrees).

    transforms.RandomRotation-將圖像旋轉(zhuǎn)一定程度 (參數(shù))。 如果度數(shù)是整數(shù)而不是(min,max),則該范圍將解釋為(-度數(shù)+ +度數(shù))。

Example :- torchvision.transforms.RandomRotation(degrees=(180))

范例: -torchvision.transforms.RandomRotation(degrees =(180))

Using torchvision.transforms.RandomRotation(degrees=(180))使用torchvision.transforms.RandomRotation(degrees =(180))
  • transforms.ColorJitter- It helps to change the brightness, contrast and saturation of an image.

    transforms.ColorJitter-它有助于 更改圖像的亮度,對(duì)比度和飽和度。

Apart from these above mentioned transformations, you can refer to full list here.

除了上述轉(zhuǎn)換之外,您還可以在此處參考完整列表

最后的想法 (Final Thoughts)

It is not always necessary to use multiple augmentations all at once, it is more of data dependant process.We need to be careful while using these transformations . For example, with crop operation if the crops are too small, we might be at risk of cutting out important parts of the image and making the model train on the wrong thing. For instance, if a dog is playing near a tree and the crop takes out the dog and just leaves part of the tree to be classified as dog that may create issues.

不一定總是一次使用多個(gè)擴(kuò)充,更多的是依賴于數(shù)據(jù)的過程。在使用這些轉(zhuǎn)換時(shí),我們需要小心。 例如,如果作物太小,則使用作物操作時(shí),我們可能會(huì)面臨切掉圖像重要部分并使模型針對(duì)錯(cuò)誤的事物進(jìn)行訓(xùn)練的風(fēng)險(xiǎn)。 例如,如果一只狗在樹附近玩耍,而莊稼將狗拔出,只留下部分樹被分類為狗,這可能會(huì)造成問題。

Apart from torchvision.transforms we can explore albumentations library too for deep learning image augmentation.

除了torchvision.transforms我們可以探索albumentations庫(kù)過深學(xué)習(xí)圖像增強(qiáng)。

翻譯自: https://medium.com/analytics-vidhya/transforming-data-in-pytorch-741fab9e008c

總結(jié)

以上是生活随笔為你收集整理的在PyTorch中转换数据的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 91视频污在线观看 | 中文字幕.com | 亚洲另类视频 | 4色av| 香蕉视频在线观看视频 | 奇米影视一区二区三区 | 国产少女免费观看高清 | 久久久com | 伊人av在线播放 | 伊朗做爰xxxⅹ性视频 | 久久免费的精品国产v∧ | 成年男女免费视频网站 | 99精品99 | 日韩电影在线一区二区 | 亚洲高清在线 | 人人99 | 五月天在线播放 | 久久9999久久免费精品国产 | 麻豆免费观看网站 | 在线观看欧美国产 | 欧美色xxxxx| 美女扒开内裤让男人桶 | 欧美激情黑人 | xxxx999| 熟妇高潮精品一区二区三区 | 久久久久久999 | 成人免费在线视频观看 | 亚洲三级在线 | 自拍中文字幕 | a级黄色片网站 | 久久久国产精华液999999 | 亚洲黄色在线观看视频 | 狠狠躁日日躁夜夜躁 | 精品国产av一区二区 | 99国产精品久久久久99打野战 | 高清不卡一区 | 国产伦人伦偷精品视频 | 亚洲精品无码不卡在线播he | 欧美激情第五页 | 裸体按摩www性xxxcom | xxxx在线播放| 91av入口| 97天天干| 欧美色欧美| 国产婷婷在线视频 | 97在线视频人妻无码 | 亚洲无av在线中文字幕 | 国产女主播视频 | 一级黄色a级片 | 久久久久成人精品免费播放动漫 | 久久国产一区 | 国产精品熟女久久久久久 | 天堂8中文在线 | 性猛交xxxx乱大交3 | 麻豆福利在线观看 | 日韩欧美中文字幕一区二区三区 | 爽妇网av| 91久久一区二区三区 | 日批免费在线观看 | 四虎影院永久地址 | 国产亚洲一区二区三区不卡 | 奇米婷婷 | 中文字幕一区二区三区在线观看 | 午夜久草 | 欧美激情免费观看 | 肮脏的交易在线观看 | 人人妻人人澡人人爽精品欧美一区 | 中日黄色片 | 日本一级免费视频 | 狠狠狠狠干 | 日韩欧美一区二区在线观看 | 嫩草影院在线视频 | 中国黄色1级片 | 中文字幕亚洲乱码 | 在线成人中文字幕 | 人人看av| 国产精品一二三四 | 久久aⅴ国产欧美74aaa | 中文字幕av久久爽一区 | 免费看黄色a级片 | 9l视频自拍蝌蚪9l视频成人 | 在线一二区 | 国产性生活网站 | 精品人妻二区中文字幕 | 国产国语性生话播放 | 国产精品.com | 久久久亚洲成人 | 丁香伊人网 | 久草视频在线资源 | 天天摸天天看 | 日批网站在线观看 | 边啃奶头边躁狠狠躁 | 欧美人与按摩师xxxx | 欧美三级视频在线观看 | 国产黑人| 国产三级成人 | 亚洲AV成人午夜无码精品久久 | 日韩午夜免费视频 | 三级视频在线播放 |