<acronym id="s8ci2"><small id="s8ci2"></small></acronym>
<rt id="s8ci2"></rt><rt id="s8ci2"><optgroup id="s8ci2"></optgroup></rt>
<acronym id="s8ci2"></acronym>
<acronym id="s8ci2"><center id="s8ci2"></center></acronym>

電子發燒友App

硬聲App

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示
電子發燒友網>電子資料下載>電子資料>PyTorch教程14.9之語義分割和數據集

PyTorch教程14.9之語義分割和數據集

2023-06-05 | pdf | 0.26 MB | 次下載 | 免費

資料介紹

第 14.3 節-第 14.8 節討論對象檢測任務時,矩形邊界框用于標記和預測圖像中的對象。本節將討論語義分割問題,重點關注如何將圖像劃分為屬于不同語義類的區域。與目標檢測不同,語義分割在像素級別識別和理解圖像中的內容:它對語義區域的標記和預測是在像素級別。 圖 14.9.1顯示了語義分割中圖像的狗、貓和背景的標簽。與目標檢測相比,語義分割中標記的像素級邊界明顯更細粒度。

https://file.elecfans.com/web2/M00/A9/CD/poYBAGR9O9WAJnnkAAdSBrW48yA985.svg

圖 14.9.1語義分割中圖像的狗、貓和背景的標簽。

14.9.1。圖像分割和實例分割

計算機視覺領域還有兩個與語義分割類似的重要任務,即圖像分割和實例分割。我們將如下簡要地將它們與語義分割區分開來。

  • 圖像分割將圖像分成幾個組成區域。這類問題的方法通常利用圖像中像素之間的相關性。它在訓練時不需要圖像像素的標簽信息,也不能保證分割后的區域在預測時具有我們希望得到的語義。以圖 14.9.1中的圖像 作為輸入,圖像分割可以將狗分成兩個區域:一個覆蓋以黑色為主的嘴巴和眼睛,另一個覆蓋以黃色為主的身體其余部分。

  • 實例分割也稱為同時檢測和分割。它研究如何識別圖像中每個對象實例的像素級區域。與語義分割不同,實例分割不僅需要區分語義,還需要區分不同的對象實例。例如,如果圖像中有兩只狗,實例分割需要區分一個像素屬于這兩只狗中的哪一只。

14.9.2。Pascal VOC2012 語義分割數據集

最重要的語義分割數據集之一是Pascal VOC2012。下面,我們將看看這個數據集。

%matplotlib inline
import os
import torch
import torchvision
from d2l import torch as d2l
%matplotlib inline
import os
from mxnet import gluon, image, np, npx
from d2l import mxnet as d2l

npx.set_np()

數據集的 tar 文件大約 2 GB,因此下載文件可能需要一段時間。提取的數據集位于 ../data/VOCdevkit/VOC2012.

#@save
d2l.DATA_HUB['voc2012'] = (d2l.DATA_URL + 'VOCtrainval_11-May-2012.tar',
              '4e443f8a2eca6b1dac8a6c57641b67dd40621a49')

voc_dir = d2l.download_extract('voc2012', 'VOCdevkit/VOC2012')
Downloading ../data/VOCtrainval_11-May-2012.tar from http://d2l-data.s3-accelerate.amazonaws.com/VOCtrainval_11-May-2012.tar...
#@save
d2l.DATA_HUB['voc2012'] = (d2l.DATA_URL + 'VOCtrainval_11-May-2012.tar',
              '4e443f8a2eca6b1dac8a6c57641b67dd40621a49')

voc_dir = d2l.download_extract('voc2012', 'VOCdevkit/VOC2012')

進入路徑后../data/VOCdevkit/VOC2012,我們可以看到數據集的不同組成部分。ImageSets/Segmentation路徑包含指定訓練和測試樣本的文本文件,而 JPEGImagesSegmentationClass路徑分別存儲每個示例的輸入圖像和標簽。這里的label也是image格式的,和它的labeled input image大小一樣。此外,任何標簽圖像中具有相同顏色的像素屬于同一語義類。下面定義了read_voc_images將所有輸入圖像和標簽讀入內存的函數。

#@save
def read_voc_images(voc_dir, is_train=True):
  """Read all VOC feature and label images."""
  txt_fname = os.path.join(voc_dir, 'ImageSets', 'Segmentation',
               'train.txt' if is_train else 'val.txt')
  mode = torchvision.io.image.ImageReadMode.RGB
  with open(txt_fname, 'r') as f:
    images = f.read().split()
  features, labels = [], []
  for i, fname in enumerate(images):
    features.append(torchvision.io.read_image(os.path.join(
      voc_dir, 'JPEGImages', f'{fname}.jpg')))
    labels.append(torchvision.io.read_image(os.path.join(
      voc_dir, 'SegmentationClass' ,f'{fname}.png'), mode))
  return features, labels

train_features, train_labels = read_voc_images(voc_dir, True)
#@save
def read_voc_images(voc_dir, is_train=True):
  """Read all VOC feature and label images."""
  txt_fname = os.path.join(voc_dir, 'ImageSets', 'Segmentation',
               'train.txt' if is_train else 'val.txt')
  with open(txt_fname, 'r') as f:
    images = f.read().split()
  features, labels = [], []
  for i, fname in enumerate(images):
    features.append(image.imread(os.path.join(
      voc_dir, 'JPEGImages', f'{fname}.jpg')))
    labels.append(image.imread(os.path.join(
      voc_dir, 'SegmentationClass', f'{fname}.png')))
  return features, labels

train_features, train_labels = read_voc_images(voc_dir, True)

我們繪制前五個輸入圖像及其標簽。在標簽圖像中,白色和黑色分別代表邊框和背景,而其他顏色對應不同的類別。

n = 5
imgs = train_features[:n] + train_labels[:n]
imgs = [img.permute(1,2,0) for img in imgs]
d2l.show_images(imgs, 2, n);
https://file.elecfans.com/web2/M00/A9/00/poYBAGR4YpiAUiS-AAFQfESlL94544.png
n = 5
imgs = train_features[:n] + train_labels[:n]
d2l.show_images(imgs, 2, n);
https://file.elecfans.com/web2/M00/A9/00/poYBAGR4YpiAUiS-AAFQfESlL94544.png

接下來,我們枚舉該數據集中所有標簽的 RGB 顏色值和類名。

#@save
VOC_COLORMAP = [[0, 0, 0], [128, 0, 0], [0, 128, 0], [128, 128, 0],
        [0, 0, 128], [128, 0, 128], [0, 128, 128], [128, 128, 128],
        [64, 0, 0], [192, 0, 0], [64, 128, 0], [192, 128, 0],
        [64, 0, 128], [192, 0, 128], [64, 128, 128], [192, 128, 128],
        [0, 64, 0], [128, 64, 0], [0, 192, 0], [128, 192, 0],
        [0, 64, 128]]

#@save
VOC_CLASSES = ['background', 'aeroplane', 'bicycle', 'bird', 'boat',
        'bottle', 'bus', 'car', 'cat', 'chair', 'cow',
        'diningtable', 'dog', 'horse', 'motorbike', 'person',
        'potted plant', 'sheep', 'sofa', 'train', 'tv/monitor']
#@save
VOC_COLORMAP = [[0, 0, 0], [128, 0, 0], [0, 128, 0], [128, 128, 0],
        [0, 0, 128], [128, 0, 128], [0, 128, 128], [128, 128, 128],
        [64, 0, 0], [192, 0, 0], [64, 128, 0], [192, 128, 0],
        [64, 0, 128], [192, 0, 128], [64, 128, 128], [192, 128, 128],
        [0, 64, 0], [128, 64, 0], [0, 192, 0], [128, 192, 0],
        [0, 64, 128]]

#@save
VOC_CLASSES = ['background', 'aeroplane', 'bicycle', 'bird', 'boat',
        'bottle', 'bus', 'car', 'cat', 'chair', 'cow',
        'diningtable', 'dog', 'horse', 'motorbike', 'person',
        'potted plant', 'sheep', 'sofa', 'train', 'tv/monitor']

使用上面定義的兩個常量,我們可以方便地找到標簽中每個像素的類索引。我們定義了voc_colormap2label 構建從上述 RGB 顏色值到類索引的映射的函數,以及voc_label_indices將任何 RGB 值映射到此 Pascal VOC2012 數據集中它們的類索引的函數。

#@save
def voc_colormap2label():
  """Build the mapping from RGB to class indices for VOC labels."""
  colormap2label = torch.zeros(256 ** 3, dtype=torch.long)
  for i

下載該資料的人也在下載 下載該資料的人還在閱讀
更多 >

評論

查看更多

下載排行

本周

  1. 1山景DSP芯片AP8248A2數據手冊
  2. 1.06 MB  |  532次下載  |  免費
  3. 2RK3399完整板原理圖(支持平板,盒子VR)
  4. 3.28 MB  |  339次下載  |  免費
  5. 3TC358743XBG評估板參考手冊
  6. 1.36 MB  |  330次下載  |  免費
  7. 4DFM軟件使用教程
  8. 0.84 MB  |  295次下載  |  免費
  9. 5元宇宙深度解析—未來的未來-風口還是泡沫
  10. 6.40 MB  |  227次下載  |  免費
  11. 6迪文DGUS開發指南
  12. 31.67 MB  |  194次下載  |  免費
  13. 7元宇宙底層硬件系列報告
  14. 13.42 MB  |  182次下載  |  免費
  15. 8FP5207XR-G1中文應用手冊
  16. 1.09 MB  |  178次下載  |  免費

本月

  1. 1OrCAD10.5下載OrCAD10.5中文版軟件
  2. 0.00 MB  |  234315次下載  |  免費
  3. 2555集成電路應用800例(新編版)
  4. 0.00 MB  |  33566次下載  |  免費
  5. 3接口電路圖大全
  6. 未知  |  30323次下載  |  免費
  7. 4開關電源設計實例指南
  8. 未知  |  21549次下載  |  免費
  9. 5電氣工程師手冊免費下載(新編第二版pdf電子書)
  10. 0.00 MB  |  15349次下載  |  免費
  11. 6數字電路基礎pdf(下載)
  12. 未知  |  13750次下載  |  免費
  13. 7電子制作實例集錦 下載
  14. 未知  |  8113次下載  |  免費
  15. 8《LED驅動電路設計》 溫德爾著
  16. 0.00 MB  |  6656次下載  |  免費

總榜

  1. 1matlab軟件下載入口
  2. 未知  |  935054次下載  |  免費
  3. 2protel99se軟件下載(可英文版轉中文版)
  4. 78.1 MB  |  537798次下載  |  免費
  5. 3MATLAB 7.1 下載 (含軟件介紹)
  6. 未知  |  420027次下載  |  免費
  7. 4OrCAD10.5下載OrCAD10.5中文版軟件
  8. 0.00 MB  |  234315次下載  |  免費
  9. 5Altium DXP2002下載入口
  10. 未知  |  233046次下載  |  免費
  11. 6電路仿真軟件multisim 10.0免費下載
  12. 340992  |  191187次下載  |  免費
  13. 7十天學會AVR單片機與C語言視頻教程 下載
  14. 158M  |  183279次下載  |  免費
  15. 8proe5.0野火版下載(中文版免費下載)
  16. 未知  |  138040次下載  |  免費
亚洲欧美日韩精品久久_久久精品AⅤ无码中文_日本中文字幕有码在线播放_亚洲视频高清不卡在线观看
<acronym id="s8ci2"><small id="s8ci2"></small></acronym>
<rt id="s8ci2"></rt><rt id="s8ci2"><optgroup id="s8ci2"></optgroup></rt>
<acronym id="s8ci2"></acronym>
<acronym id="s8ci2"><center id="s8ci2"></center></acronym>