亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

首頁 后端開發(fā) Python教程 PyTorch 中的 CocoDetection (3)

PyTorch 中的 CocoDetection (3)

Jan 08, 2025 pm 02:13 PM

請我喝杯咖啡?

*備忘錄:

  • 我的帖子解釋了CocoDetection()使用帶有captions_train2014.json、instances_train2014.json和person_keypoints_train2014.json的train2014、帶有captions_val2014.json、instances_val2014.json和person_keypoints_val2014.json的val2014以及帶有image_info_test2014.json的test2017, image_info_test2015.json 和 image_info_test-dev2015.json。
  • 我的帖子解釋了CocoDetection()使用train2017與captions_train2017.json,instances_train2017.json和person_keypoints_train2017.json,val2017與captions_val2017.json,instances_val2017.json和person_keypoints_val2017.json和test2017與image_info_test2017.json和image_info_test-dev2017.json.
  • 我的帖子解釋了 MS COCO。

CocoDetection() 可以使用 MS COCO 數(shù)據(jù)集,如下所示。 *這是針對帶有 stuff_train2017.json 的 train2017、帶有 stuff_val2017.json 的 val2017、帶有 stuff_train2017.json 的 stuff_train2017_pixelmaps、帶有 stuff_val2017.json 的 stuff_val2017_pixelmaps、帶有 panoptic_train2017.json 的 panoptic_train2017、帶有 panoptic_train2017.json 的 panoptic_val2017 panoptic_val2017.json 和 unlabeled2017 以及 image_info_unlabeled2017.json:

from torchvision.datasets import CocoDetection

stf_train2017_data = CocoDetection(
    root="data/coco/imgs/train2017",
    annFile="data/coco/anns/stuff_trainval2017/stuff_train2017.json"
)

stf_val2017_data = CocoDetection(
    root="data/coco/imgs/val2017",
    annFile="data/coco/anns/stuff_trainval2017/stuff_val2017.json"
)

len(stf_train2017_data), len(stf_val2017_data)
# (118287, 5000)

# pms_stf_train2017_data = CocoDetection(
#     root="data/coco/anns/stuff_trainval2017/stuff_train2017_pixelmaps",
#     annFile="data/coco/anns/stuff_trainval2017/stuff_train2017.json"
# ) # Error

# pms_stf_val2017_data = CocoDetection(
#     root="data/coco/anns/stuff_trainval2017/stuff_val2017_pixelmaps",
#     annFile="data/coco/anns/stuff_trainval2017/stuff_val2017.json"
# ) # Error

# pan_train2017_data = CocoDetection(
#     root="data/coco/anns/panoptic_trainval2017/panoptic_train2017",
#     annFile="data/coco/anns/panoptic_trainval2017/panoptic_train2017.json"
# ) # Error

# pan_val2017_data = CocoDetection(
#     root="data/coco/anns/panoptic_trainval2017/panoptic_val2017",
#     annFile="data/coco/anns/panoptic_trainval2017/panoptic_val2017.json"
# ) # Error

unlabeled2017_data = CocoDetection(
    root="data/coco/imgs/unlabeled2017",
    annFile="data/coco/anns/unlabeled2017/image_info_unlabeled2017.json"
)

len(unlabeled2017_data)
# 123403

stf_train2017_data[2]
# (<PIL.Image.Image image mode=RGB size=640x428>,
#  [{'segmentation': {'counts': 'W2a0S2Q1T7mNmHS1R7mN...0100000000',
#    'size': [428, 640]}, 'area': 112666.0, 'iscrowd': 0, 'image_id': 30, 
#    'bbox': [0.0, 0.0, 640.0, 321.0], 'category_id': 119, 'id': 10000010},
#   {'segmentation': ..., 'category_id': 124, 'id': 10000011},
#   ...
#   {'segmentation': ..., 'category_id': 183, 'id': 10000014}])

stf_train2017_data[47]
# (<PIL.Image.Image image mode=RGB size=640x427>,
#  [{'segmentation': {'counts': '\\j1h0[<a0G2N001O0...00001O0000',
#    'size': [427, 640]}, 'area': 65213.0, 'iscrowd': 0, 'image_id': 294,
#    'bbox': [140.0, 0.0, 500.0, 326.0], 'category_id': 98, 'id': 10000284}, 
#   {'segmentation': ..., 'category_id': 123, 'id': 10000285},
#   ...
#   {'segmentation': ..., 'category_id': 183, 'id': 10000291}])

stf_train2017_data[64]
# (<PIL.Image.Image image mode=RGB size=480x640>,
#  [{'segmentation': {'counts': '0[9e:1O000000O100000...O5mc0F^Zj7',
#    'size': [640, 480]}, 'area': 20503.0, 'iscrowd': 0, 'image_id': 370,
#    'bbox': [0.0, 0.0, 79.0, 316.0], 'category_id': 102, 'id': 10000383},
#   {'segmentation': ..., 'category_id': 105, 'id': 10000384},
#   ...
#   {'segmentation': ..., 'category_id': 183, 'id': 10000389}])

stf_val2017_data[2]
# (<PIL.Image.Image image mode=RGB size=640x483>,
#  [{'segmentation': {'counts': '\9g5]9O1O1O;EU1kNU1...VMKQ?NY`d3',
#    'size': [483, 640]}, 'area': 5104.0, 'iscrowd': 0, 'image_id': 632,
#    'bbox': [0.0, 300.0, 392.0, 183.0], 'category_id': 93, 'id': 20000017},
#   {'segmentation': ..., 'category_id': 128, 'id': 20000018},
#   ...
#   {'segmentation': ..., 'category_id': 183, 'id': 20000020}])

stf_val2017_data[47]
# (<PIL.Image.Image image mode=RGB size=640x480>,
#  [{'segmentation': {'counts': '[da7T1X>D3M2J5M4M4LoQg1',
#    'size': [480, 640]}, 'area': 122.0, 'iscrowd': 0, 'image_id': 5001,
#    'bbox': [515.0, 235.0, 7.0, 36.0], 'category_id': 104, 'id': 20000247},
#   {'segmentation': ..., 'category_id': 105, 'id': 20000248},
#   ...
#   {'segmentation': ..., 'category_id': 183, 'id': 20000256}])

stf_val2017_data[64]
# (<PIL.Image.Image image mode=RGB size=640x483>,
#  [{'segmentation': {'counts': 'U<^1W>N020mN]B2e>N1O...Mb@N^?2hd2',
#    'size': [500, 375]}, 'area': 2404.0, 'iscrowd': 0, 'image_id': 6763,
#    'bbox': [0.0, 235.0, 369.0, 237.0], 'category_id': 105, 'id': 20000356},
#   {'segmentation': ..., 'category_id': 123, 'id': 20000357},
#   ...
#   {'segmentation': ..., 'category_id': 183, 'id': 20000362}])

unlabeled2017_data[2]
# (<PIL.Image.Image image mode=RGB size=640x427>, [])

unlabeled2017_data[47]
# (<PIL.Image.Image image mode=RGB size=428x640>, [])

unlabeled2017_data[64]
# (<PIL.Image.Image image mode=RGB size=640x480>, [])

import matplotlib.pyplot as plt
from matplotlib.patches import Polygon, Rectangle
import numpy as np
from pycocotools import mask

# `show_images1()` doesn't work very well for the images with
# segmentations so for it, use `show_images2()` which
# more uses the original coco functions. 
def show_images1(data, ims, main_title=None):
    file = data.root.split('/')[-1]
    fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(14, 8))
    fig.suptitle(t=main_title, y=0.9, fontsize=14)
    for i, axis in zip(ims, axes.ravel()):
        if data[i][1] and "segmentation" in data[i][1][0]:
            im, anns = data[i]
            axis.imshow(X=im)
            axis.set_title(label=anns[0]["image_id"])
            ec = ['g', 'r', 'c', 'm', 'y', 'w']
            ec_index = 0
            for ann in anns:
                seg = ann['segmentation']
                compressed_rld = mask.decode(rleObjs=seg)
                y_plts, x_plts = np.nonzero(a=np.squeeze(a=compressed_rld))
                axis.plot(x_plts, y_plts, alpha=0.4)
                x, y, w, h = ann['bbox']
                rect = Rectangle(xy=(x, y), width=w, height=h,
                                 linewidth=3, edgecolor=ec[ec_index],
                                 facecolor='none', zorder=2)
                ec_index += 1
                if ec_index == len(ec)-1:
                    ec_index = 0
                axis.add_patch(p=rect)
        elif not data[i][1]:
            im, _ = data[i]
            axis.imshow(X=im)
    fig.tight_layout()
    plt.show()

ims = (2, 47, 64)

show_images1(data=stf_train2017_data, ims=ims,
             main_title="stf_train2017_data")
show_images1(data=stf_val2017_data, ims=ims, 
             main_title="stf_val2017_data")
show_images1(data=unlabeled2017_data, ims=ims,
             main_title="unlabeled2017_data")

def show_images2(data, index, main_title=None):
    img_set = data[index]
    img, img_anns = img_set
    if img_anns and "segmentation" in img_anns[0]:
        img_id = img_anns[0]['image_id']
        coco = data.coco
        def show_image(imgIds, areaRng=[],
                       iscrowd=None, draw_bbox=False):
            plt.figure(figsize=(11, 8))
            plt.imshow(X=img)
            plt.suptitle(t=main_title, y=1, fontsize=14)
            plt.title(label=img_id, fontsize=14)
            anns_ids = coco.getAnnIds(imgIds=img_id,
                                      areaRng=areaRng, iscrowd=iscrowd)
            anns = coco.loadAnns(ids=anns_ids)
            coco.showAnns(anns=anns, draw_bbox=draw_bbox)
            plt.show()
        show_image(imgIds=img_id, draw_bbox=True)
        show_image(imgIds=img_id, draw_bbox=False)
        show_image(imgIds=img_id, iscrowd=False, draw_bbox=True)
        show_image(imgIds=img_id, areaRng=[0, 5000], draw_bbox=True)
    elif not img_anns:
        plt.figure(figsize=(11, 8))
        plt.imshow(X=img)
        plt.suptitle(t=main_title, y=1, fontsize=14)
        plt.show()

show_images2(data=stf_val2017_data, index=47, 
             main_title="stf_train2017_data")

顯示_圖像1():

Image description

Image description

Image description

顯示圖像2():

Image description

Image description

Image description

Image description

以上是PyTorch 中的 CocoDetection (3)的詳細內(nèi)容。更多信息請關注PHP中文網(wǎng)其他相關文章!

本站聲明
本文內(nèi)容由網(wǎng)友自發(fā)貢獻,版權歸原作者所有,本站不承擔相應法律責任。如您發(fā)現(xiàn)有涉嫌抄襲侵權的內(nèi)容,請聯(lián)系admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣服圖片

Undresser.AI Undress

Undresser.AI Undress

人工智能驅(qū)動的應用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用于從照片中去除衣服的在線人工智能工具。

Clothoff.io

Clothoff.io

AI脫衣機

Video Face Swap

Video Face Swap

使用我們完全免費的人工智能換臉工具輕松在任何視頻中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的代碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

功能強大的PHP集成開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級代碼編輯軟件(SublimeText3)

熱門話題

Laravel 教程
1597
29
PHP教程
1488
72
Python類中的多態(tài)性 Python類中的多態(tài)性 Jul 05, 2025 am 02:58 AM

多態(tài)是Python面向?qū)ο缶幊讨械暮诵母拍?,指“一種接口,多種實現(xiàn)”,允許統(tǒng)一處理不同類型的對象。1.多態(tài)通過方法重寫實現(xiàn),子類可重新定義父類方法,如Animal類的speak()方法在Dog和Cat子類中有不同實現(xiàn)。2.多態(tài)的實際用途包括簡化代碼結構、增強可擴展性,例如圖形繪制程序中統(tǒng)一調(diào)用draw()方法,或游戲開發(fā)中處理不同角色的共同行為。3.Python實現(xiàn)多態(tài)需滿足:父類定義方法,子類重寫該方法,但不要求繼承同一父類,只要對象實現(xiàn)相同方法即可,這稱為“鴨子類型”。4.注意事項包括保持方

解釋Python發(fā)電機和迭代器。 解釋Python發(fā)電機和迭代器。 Jul 05, 2025 am 02:55 AM

迭代器是實現(xiàn)__iter__()和__next__()方法的對象,生成器是簡化版的迭代器,通過yield關鍵字自動實現(xiàn)這些方法。1.迭代器每次調(diào)用next()返回一個元素,無更多元素時拋出StopIteration異常。2.生成器通過函數(shù)定義,使用yield按需生成數(shù)據(jù),節(jié)省內(nèi)存且支持無限序列。3.處理已有集合時用迭代器,動態(tài)生成大數(shù)據(jù)或需惰性求值時用生成器,如讀取大文件時逐行加載。注意:列表等可迭代對象不是迭代器,迭代器到盡頭后需重新創(chuàng)建,生成器只能遍歷一次。

如何處理Python中的API身份驗證 如何處理Python中的API身份驗證 Jul 13, 2025 am 02:22 AM

處理API認證的關鍵在于理解并正確使用認證方式。1.APIKey是最簡單的認證方式,通常放在請求頭或URL參數(shù)中;2.BasicAuth使用用戶名和密碼進行Base64編碼傳輸,適合內(nèi)部系統(tǒng);3.OAuth2需先通過client_id和client_secret獲取Token,再在請求頭中帶上BearerToken;4.為應對Token過期,可封裝Token管理類自動刷新Token;總之,根據(jù)文檔選擇合適方式,并安全存儲密鑰信息是關鍵。

如何一次迭代兩個列表 如何一次迭代兩個列表 Jul 09, 2025 am 01:13 AM

在Python中同時遍歷兩個列表的常用方法是使用zip()函數(shù),它會按順序配對多個列表并以最短為準;若列表長度不一致,可使用itertools.zip_longest()以最長為準并填充缺失值;結合enumerate()可同時獲取索引。1.zip()簡潔實用,適合成對數(shù)據(jù)迭代;2.zip_longest()處理不一致長度時可填充默認值;3.enumerate(zip())可在遍歷時獲取索引,滿足多種復雜場景需求。

什么是Python型提示? 什么是Python型提示? Jul 07, 2025 am 02:55 AM

typeHintsInpyThonsolverbromblemboyofambiguityandPotentialBugSindyNamalytyCodeByallowingDevelopsosteSpecefectifyExpectedTypes.theyenhancereadability,enablellybugdetection,andimprovetool.typehintsupport.typehintsareadsareadsareadsareadsareadsareadsareadsareadsareaddedusidocolon(

什么是Python迭代器? 什么是Python迭代器? Jul 08, 2025 am 02:56 AM

Inpython,IteratorSareObjectSthallowloopingThroughCollectionsByImplementing_iter __()和__next __()。1)iteratorsWiaTheIteratorProtocol,使用__ITER __()toreTurnterateratoratoranteratoratoranteratoratorAnterAnteratoratorant antheittheext__()

解釋Python斷言。 解釋Python斷言。 Jul 07, 2025 am 12:14 AM

Assert是Python用于調(diào)試的斷言工具,當條件不滿足時拋出AssertionError。其語法為assert條件加可選錯誤信息,適用于內(nèi)部邏輯驗證如參數(shù)檢查、狀態(tài)確認等,但不能用于安全或用戶輸入檢查,且應配合清晰提示信息使用,僅限開發(fā)階段輔助調(diào)試而非替代異常處理。

Python Fastapi教程 Python Fastapi教程 Jul 12, 2025 am 02:42 AM

要使用Python創(chuàng)建現(xiàn)代高效的API,推薦使用FastAPI;其基于標準Python類型提示,可自動生成文檔,性能優(yōu)越。安裝FastAPI和ASGI服務器uvicorn后,即可編寫接口代碼。通過定義路由、編寫處理函數(shù)并返回數(shù)據(jù),可以快速構建API。FastAPI支持多種HTTP方法,并提供自動生成的SwaggerUI和ReDoc文檔系統(tǒng)。URL參數(shù)可通過路徑定義捕獲,查詢參數(shù)則通過函數(shù)參數(shù)設置默認值實現(xiàn)。合理使用Pydantic模型有助于提升開發(fā)效率和準確性。

See all articles