所謂“復(fù)現(xiàn)”,不過是跑通了官方的代碼,以下僅為個(gè)人的一些經(jīng)驗(yàn)和理解,歡迎指正。
(其實(shí)僅作為個(gè)人學(xué)習(xí)使用,也歡迎交流)
首先貼出官方文獻(xiàn)和代碼:
官方文獻(xiàn):InternImage: Exploring Large-Scale Vision Foundation Models with Deformable Convolutions,鏈接:InternImage: Exploring Large-Scale Vision Foundation Models with Deformable Convolutions | Papers With Code官方Github代碼:GitHub - OpenGVLab/InternImage: [CVPR 2023 Highlight] InternImage: Exploring Large-Scale Vision Foundation Models with Deformable Convolutions
一、代碼復(fù)現(xiàn)
1、配置信息
????????Linux系統(tǒng)Ubuntu 9.4.0(在Windows上跑會出現(xiàn)各種各樣的問題,主要是包不兼容的問題),4卡,Cuda 11.1。
2、環(huán)境配置
????????下載了官方代碼解壓,得到以下文件:
????????進(jìn)入? ?./segmentation 文件夾下,用Notepad++軟件打開README.md文件,跟據(jù)上面的內(nèi)容配置環(huán)境。
3、數(shù)據(jù)集準(zhǔn)備
????????ADE20K數(shù)據(jù)集下載:
? ? ? ? 官網(wǎng)下載:ADE20K dataset (mit.edu),這里的訓(xùn)練測試只用到?ADEChallengeData2016?數(shù)據(jù)集(MIT Scene Parsing Challenge 2016)就可以了。這里再附上百度網(wǎng)盤下載鏈接:鏈接:https://pan.baidu.com/s/1VWVzoeIgzDbFgo_RXcQ_Mw?pwd=mv4j?提取碼:mv4j
? ? ? ? 關(guān)于數(shù)據(jù)集的介紹請看官網(wǎng),下面的訓(xùn)練和測試都是基于ADEChallengeData2016進(jìn)行。
4、測試(test.py部分)
? ? ? ? 將數(shù)據(jù)集上傳到Linux系統(tǒng),官方代碼默認(rèn)讀取路徑是 ./segmentation/data/ADEChallenge Data2016/... ,如果不想改代碼的話,就在 ./segmentation 文件夾下新建一個(gè) data 文件夾,然后把ADEChallengeData2016數(shù)據(jù)集加載到data文件夾下。數(shù)據(jù)集組織格式如下(官方代碼默認(rèn)):
---------------
|
|--ADEChallengeData2016
|
|--annotations
| |
| |--training
| | |
| | |--ADE_train_00000001.png
| | |--ADE_train_00000002.png
| | |--……
| |
| |--validation
| | |
| | |--ADE_val_00000001.png
| | |--ADE_val_00000002.png
| | |--……
|
|--images
| |
| |--training
| | |
| | |--ADE_train_00000001.png
| | |--ADE_train_00000002.png
| | |--……
| |
| |--validation
| | |
| | |--ADE_val_00000001.png
| | |--ADE_val_00000002.png
| | |--……
| |
????????若數(shù)據(jù)集放于其它路徑下,則需要通過修改代碼來進(jìn)行數(shù)據(jù)集的讀取,這里有兩種解決辦法:
? ? ? ? 方法一:修改test.py文件代碼。
? ? ? ? 找到讀取數(shù)據(jù)集的代碼行:
dataset = build_dataset(cfg.data.test) #建立數(shù)據(jù)集
? ? ? ? 在該代碼行前一行添加代碼:
cfg.data.test['data_root'] = 'E:/data/ADE20K/ADEChallengeData2016' #通過這個(gè)命令行改變測試集的位置,添加你的測試集路徑
dataset = build_dataset(cfg.data.test) #建立數(shù)據(jù)集
? ? ? ? 這樣修改之后,代碼就會跟據(jù)你指明的路徑讀取數(shù)據(jù),數(shù)據(jù)集的組織形式依舊如上面代碼塊所示。若更改組織形式,則需要指明圖片所在路徑和標(biāo)注文件所在路徑,如下面代碼所示:
cfg.data.test['data_root'] = 'E:/data/ADE20K/ADEChallengeData2016' #通過這個(gè)命令行改變測試集的位置,添加你的測試集路徑
cfg.data.test['img_dir'] = 'val/Images' #指向圖片文件的路徑,圖片文件的完整路徑為:cfg.data.test['data_root'] + cfg.data.test['img_dir']
cfg.data.test['ann_dir'] = 'val/Masks' #指向標(biāo)注文件的路徑,標(biāo)注文件的完整路徑為:cfg.data.test['data_root'] + cfg.data.test['ann_dir']
dataset = build_dataset(cfg.data.test) #建立數(shù)據(jù)集
? ? ? ?
????????方法二:通過修改數(shù)據(jù)讀取的底層文件實(shí)現(xiàn),參考:(64條消息) mmsegmentation教程1:自定義數(shù)據(jù)集、config文件修改、訓(xùn)練教程_AESA相控陣的博客-CSDN博客
? ? ? ? 模型參數(shù)(.pth文件)下載:GitHub - OpenGVLab/InternImage: [CVPR 2023 Highlight] InternImage: Exploring Large-Scale Vision Foundation Models with Deformable Convolutions
? ? ? ? 跟據(jù)你的模型需要,下載ckpt的鏈接文件并保存到你的文件中(即下文代碼的[your_wei ght_path])。
? ? ? ? 做到以上準(zhǔn)備之后,運(yùn)行以下代碼就可以查看模型在ADE20K數(shù)據(jù)集上的測試結(jié)果:
python test.py configs/ade20k/upernet_internimage_t_512_160k_ade20k.py [your_weight_path]/upernet_internimage_t_512_160k_ade20k.pth --eval mIoU
5、訓(xùn)練(train.py部分)
? ? ? ? 與第4部分類似,需要準(zhǔn)備數(shù)據(jù)集和修改數(shù)據(jù)讀取代碼,模型訓(xùn)練不需要下載模型參數(shù)文件。準(zhǔn)備好數(shù)據(jù)集和修改數(shù)據(jù)讀取代碼之后,運(yùn)行以下代碼(README.md)。
sh dist_train.sh configs/ade20k/upernet_internimage_t_512_160k_ade20k.py 8
????????可能會出現(xiàn)報(bào)錯(cuò),原因是 sh 命令被版本舍棄了(具體原因自己網(wǎng)上搜索)?將 sh 命令換為 bash 命令就可以了,即:文章來源:http://www.zghlxwxcb.cn/news/detail-624663.html
bash dist_train.sh configs/ade20k/upernet_internimage_t_512_160k_ade20k.py 8
????????文章來源地址http://www.zghlxwxcb.cn/news/detail-624663.html
到了這里,關(guān)于InternImage segmentation部分代碼復(fù)現(xiàn)及訓(xùn)練自己的數(shù)據(jù)集(一)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!