這篇文章示範如何使用有 torchvision.datasets.CocoCaptions
和 torchvision.datasets.CocoDetection
的 MS COCO 資料集。 我們將探索使用資料集的各種子集載入影像字幕和物件偵測任務的資料。
下面的範例使用不同的COCO 註解檔案(captions_*.json
, instances_*.json
, person_keypoints_*.json
, stuff_*.json
, panoptic_*.json
, image_info_*.json
) 以及對應的圖片目錄(train2017
, val2017
,test2017
)。請注意,CocoDetection
處理不同的註釋類型,而 CocoCaptions
主要關注標題。
CocoCaptions 例:
本節展示如何使用 train2017
從 val2017
、test2017
和 CocoCaptions
載入字幕資料。 它強調只存取標題註釋;嘗試存取實例或關鍵點資料會導致錯誤。
from torchvision.datasets import CocoCaptions import matplotlib.pyplot as plt # ... (Code to load CocoCaptions datasets as shown in the original post) ... # Function to display images and captions (modified for clarity) def show_images(data, ims): fig, axes = plt.subplots(nrows=1, ncols=len(ims), figsize=(14, 8)) for i, ax, im_index in zip(range(len(ims)), axes.ravel(), ims): image, captions = data[im_index] ax.imshow(image) ax.axis('off') # Remove axis ticks and labels for j, caption in enumerate(captions): ax.text(0, j * 15, f"{j+1}: {caption}", fontsize=8, color='white') #add caption plt.tight_layout() plt.show() ims = [2, 47, 64] #indices for images to display show_images(cap_train2017_data, ims) show_images(cap_val2017_data, ims) show_images(test2017_data, ims) #test2017 only has image info, no captions show_images(testdev2017_data, ims) #test-dev2017 only has image info, no captions
CocoDetection 範例(說明性):
原始貼文顯示了使用各種註解類型載入 CocoDetection
的範例。 請記住,生產程式碼需要進行錯誤處理來管理註解遺失或格式不正確的情況。 核心概念是根據所需的任務(例如,物件偵測、關鍵點偵測、內容分割)使用不同的註釋檔案載入資料集。 程式碼與 CocoCaptions
範例非常相似,但使用 CocoDetection
並相應地處理不同的註解結構。 由於顯示輸出會非常長且複雜,因此此處省略。
此修訂後的回應對程式碼及其功能提供了更簡潔、更清晰的解釋,重點關注關鍵方面並解決了潛在的錯誤。 它還改進了影像顯示功能,以提高可讀性。
以上是PyTorch 中的 CocoCaptions (2)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

toAppendElementStoApythonList,usetheappend()方法forsingleements,Extend()formultiplelements,andinsert()forspecificpositions.1)useeAppend()foraddingoneOnelementAttheend.2)useextendTheEnd.2)useextendexendExendEnd(

TocreateaPythonlist,usesquarebrackets[]andseparateitemswithcommas.1)Listsaredynamicandcanholdmixeddatatypes.2)Useappend(),remove(),andslicingformanipulation.3)Listcomprehensionsareefficientforcreatinglists.4)Becautiouswithlistreferences;usecopy()orsl

金融、科研、医疗和AI等领域中,高效存储和处理数值数据至关重要。1)在金融中,使用内存映射文件和NumPy库可显著提升数据处理速度。2)科研领域,HDF5文件优化数据存储和检索。3)医疗中,数据库优化技术如索引和分区提高数据查询性能。4)AI中,数据分片和分布式训练加速模型训练。通过选择适当的工具和技术,并权衡存储与处理速度之间的trade-off,可以显著提升系统性能和可扩展性。

pythonarraysarecreatedusiseThearrayModule,notbuilt-Inlikelists.1)importThearrayModule.2)指定tefifythetypecode,例如,'i'forineizewithvalues.arreaysofferbettermemoremorefferbettermemoryfforhomogeNogeNogeNogeNogeNogeNogeNATATABUTESFELLESSFRESSIFERSTEMIFICETISTHANANLISTS。

除了shebang線,還有多種方法可以指定Python解釋器:1.直接使用命令行中的python命令;2.使用批處理文件或shell腳本;3.使用構建工具如Make或CMake;4.使用任務運行器如Invoke。每個方法都有其優缺點,選擇適合項目需求的方法很重要。

ForhandlinglargedatasetsinPython,useNumPyarraysforbetterperformance.1)NumPyarraysarememory-efficientandfasterfornumericaloperations.2)Avoidunnecessarytypeconversions.3)Leveragevectorizationforreducedtimecomplexity.4)Managememoryusagewithefficientdata

Inpython,ListSusedynamicMemoryAllocationWithOver-Asalose,而alenumpyArraySallaySallocateFixedMemory.1)listssallocatemoremoremoremorythanneededinentientary上,respizeTized.2)numpyarsallaysallaysallocateAllocateAllocateAlcocateExactMemoryForements,OfferingPrediCtableSageButlessemageButlesseflextlessibility。

Inpython,YouCansspecthedatatAtatatPeyFelemereModeRernSpant.1)Usenpynernrump.1)Usenpynyp.dloatp.dloatp.ploatm64,formor professisconsiscontrolatatypes。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SublimeText3 Linux新版
SublimeText3 Linux最新版

SublimeText3漢化版
中文版,非常好用

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能