PyTorch開源圖像分類工具箱MMClassification詳解
MMClassification是一個基于PyTorch的開源圖像分類工具箱,是OpenMMLab項目的一部分,源碼傳送門,最新發(fā)布版本為v0.23.2,License為Apache-2.0。它支持在Windows、Linux和Mac上運行。
1.安裝:使用conda安裝
(1).創(chuàng)建openmmlab虛擬環(huán)境:
conda create -n openmmlab python=3.8
conda activate openmmlab
(2).安裝PyTorch:這里PyTorch使用1.11.0版本,CUDA使用10.2版本,此CUDA版本對PyTorch各版本都支持
conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=10.2 -c pytorch
(3).安裝MMCV:MMCV有兩個版本,這里安裝帶CUDA的mmcv-full
1).mmcv-full: 完整版,包含所有的特性以及豐富的開箱即用的CUDA算子,安裝此版本需要較長時間。
2).mmcv:精簡版,不包含CUDA算子但包含其余所有特性和功能,類似MMCV 1.0之前的版本。
不要在同一個環(huán)境中安裝兩個版本,否則可能會遇到類似ModuleNotFound的錯誤。在安裝一個版本之前,需要先卸載另一個:
pip uninstall mmcv-full
pip uninstall mmcv
注意:這里mmcv-full使用1.5.3版本。CUDA版本和PyTorch版本與安裝PyTorch時保持一致
pip install mmcv-full==1.5.3 -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.11.0/index.html
(4).安裝MMClassification:沒有通過源碼安裝
pip install mmcls==0.23.2
2.測試:論文:《Very Deep Convolutional Networks for Large-Scale Image Recognition》
ImageNet數(shù)據(jù)集:是根據(jù)WordNet層次結(jié)構(gòu)組織的圖像數(shù)據(jù)集,ImageNet_1000_label中給出了1000類別中l(wèi)abel對應(yīng)的id值。
(1).下載模型(checkpoint):
def download_checkpoint(path, name, url): if os.path.isfile(path+name) == False: print("checkpoint(model) file does not exist, now download ...") subprocess.run(["wget", "-P", path, url]) path = "../../data/model/" checkpoint = "vgg19_batch256_imagenet_20210208-e6920e4a.pth" url = "https://download.openmmlab.com/mmclassification/v0/vgg/vgg19_batch256_imagenet_20210208-e6920e4a.pth" download_checkpoint(path, checkpoint, url)
(2).根據(jù)配置文件和checkpoint文件構(gòu)建模型:
config = "../../src/mmclassification/configs/vgg/vgg19_8xb32_in1k.py"
model = init_model(config, path+checkpoint, device)
(3).準(zhǔn)備測試圖像:原始圖像來自網(wǎng)絡(luò)
image_path = "../../data/image/" image_name = "6.jpg"
(4).進行推理:
result = inference_model(model, image) print(mmcv.dump(result, file_format='json', indent=4)) # show_result_pyplot(model, image, result)
執(zhí)行結(jié)果如下圖所示:
GitHub傳送門
到此這篇關(guān)于PyTorch開源圖像分類工具箱MMClassification詳解的文章就介紹到這了,更多相關(guān)PyTorch MMClassification內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python中輸入若干整數(shù)以逗號間隔實現(xiàn)統(tǒng)計每個整數(shù)出現(xiàn)次數(shù)
這篇文章主要介紹了Python中輸入若干整數(shù)以逗號間隔實現(xiàn)統(tǒng)計每個整數(shù)出現(xiàn)次數(shù)的相關(guān)資料,需要的小伙伴可以參考一下,希望對你有所幫助2022-04-04解決python調(diào)用自己文件函數(shù)/執(zhí)行函數(shù)找不到包問題
這篇文章主要介紹了解決python調(diào)用自己文件函數(shù)/執(zhí)行函數(shù)找不到包問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-06-06對python實現(xiàn)二維函數(shù)高次擬合的示例詳解
今天小編就為大家分享一篇對python實現(xiàn)二維函數(shù)高次擬合的示例詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-12-12