Python影像辨識筆記(三十四):Transfer-Learning-Library: Domain Adaptation and Finetune

git https://github.com/thuml/Transfer-Learning-Library
cd Transfer-Learning-Library
pip install torch==1.7.1+cu92 torchvision==0.8.2+cu92 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.htmlpip install -r requirements.txt
# 新增以下名稱的資料夾,並在內部,建立2個txt檔案和1個資料夾。其中,建立的資料夾(image_folder)要包含欲訓練的圖片檔案(JPG, PNG..........)
Transfer-Learning-Library/data/datasetname/
# Transfer-Learning-Library/data/datasetname/image_folder/
# Transfer-Learning-Library/data/datasetname/datasetname_source.txt
# Transfer-Learning-Library/data/datasetname/datasetname_target.txt
datasetname_source.txt包含了所有要作為source domain的圖片資訊
datasetname_target.txt包含了所有要作為target domain的圖片資訊
# 圖片範例資訊格式如下:# 第一項路徑名稱;第二項是label名稱image_folder/123.jpg 0
image_folder/456.jpg 1
image_folder/789.jpg 2
# 如果圖片資料夾在其他顆硬碟或目錄,而且檔案很大該怎麼修改訓練的指令?要將datasetname_source.txt和datasetname_target.txt兩個檔案放到path/to/img_folder/當中path/to/img_folder/datasetname_source.txt
path/to/img_folder/datasetname_target.txt
CUDA_VISIBLE_DEVICES=0 python mcc.py path/to/img_folder -d Phison -s source -t target -a resnet18 --epochs 30 --seed 0 --temperature 2.5 --bottleneck-dim 2048 --log logs/mcc/Phison_c5_target
Transfer-Learning-Library/common/vision/datasets/datasetname.py
Transfer-Learning-Library/common/vision/datasets/__init__.pyfrom .imagelist import ImageList
from .office31 import Office31
from .officehome import OfficeHome
from .visda2017 import VisDA2017
from .officecaltech import OfficeCaltech
from .domainnet import DomainNet
from .aircrafts import Aircraft
from .cub200 import CUB200
from .stanford_cars import StanfordCars
from .stanford_dogs import StanfordDogs
from .coco70 import COCO70
from .oxfordpet import OxfordIIITPet
from .datasetname import datasetname #新增
__all__ = ['ImageList', 'Office31', 'OfficeHome', "VisDA2017", "OfficeCaltech", "DomainNet",
"Aircraft", "cub200", "StanfordCars", "StanfordDogs", "COCO70", "OxfordIIITPet", 'datasetname'] #新增
$ cd /Transfer-Learning-Library/examples/domain_adaptation/classification# -d中的datasetname要和datasetname.py中的class名稱一致
# /Transfer-Learning-Library/data/datasetname/是包含dataset的資料夾,裡面要包含datasetname_source.txt和datasetname_target.txt
$ CUDA_VISIBLE_DEVICES=0 python mcc.py /root/notebooks/Transfer-Learning-Library/data/datasetname/ -d datasetname -s source -t target -a resnet18 --epochs 30 --seed 0 --temperature 2.5 --bottleneck-dim 2048 --log logs/mcc/dataset_log_name## 指令說明
使用第0顆GPU,執行mcc.py,資料夾目錄/root/notebooks/Transfer-Learning-Library/data/datasetname/,使用datasetname.py中的datasetname method

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store