코드 분석/MAT

MAT 환경설정 및 버그 리포트

상솜공방 2024. 1. 22. 22:58

1. 아나콘다 가상환경 생성

conda create -n MAT python=3.7

conda activate MAT

pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html

pip install -r requirements.txt

 

2. 커스텀 데이터셋 생성

git을 통해 MAT 폴더를 내려받은 후 ship_images 폴더를 붙여넣었다.

ship_images 폴더는 train, val 이미지가 담긴 데이터셋과, 훈련 과정의 로그 및 모델 pkl 파일이 담긴다.

 

3. 모델 훈련

python train.py \
--outdir='ship_images/output' \
--gpus=1 \
--batch=1 \
--metrics=fid36k5_full \
--data='ship_images/train' \
--data_val='ship_images/val' \
--dataloader=datasets.dataset_512.ImageFolderMaskDataset \
--mirror=True \
--cond=False \
--cfg=places512 \
--aug=noaug \
--generator=networks.mat.Generator \
--discriminator=networks.mat.Discriminator \
--loss=losses.loss.TwoStageLoss \
--pr=0.1 \
--pl=False \
--truncation=0.5 \
--style_mix=0.5 \
--ema=10 \
--lr=0.001

 

4. 오류 보고

val 이미지가 out of index bounds라고 하며 오류가 난다.

https://github.com/fenglinglwb/MAT/issues/62

 

An Inedxerror occurred in training · Issue #62 · fenglinglwb/MAT

Dear author, Thanks for your excellent work, well done! An error occurred in my training, as figure in follow: I don't upstand why it happened. I tested the loading data filenames and found that wh...

github.com

나와 동일한 오류가 발생한 사람의 글을 찾아보았으나, training_loop.py의 413~421줄을 주석처리 함으로써 모델의 성능을 평가하는 metric 부분을 호출하지 않는 방법으로 해결하였다. 그러나 근본적인 오류가 무엇인지 파악하고 싶다.

 

VSCode를 사용하여 디버깅 진행

1. 인터프리터 설정

ctrl + shift + p (혹은 F1)을 눌러 메뉴를 검색한 후, python: Select interpreter 검색.

아나콘다의 'MAT'를 설정.

 

2. launch.json 파일 생성

augments를 다음과 같이 json파일에 생성.

launch.json 파일 펼치기.

더보기
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "args": [
                "--outdir", "ship_images/output",
                "--gpus", "1",
                "--batch", "1",
                "--metrics", "fid36k5_full",
                "--data", "ship_images/train",
                "--data_val", "ship_images/val",
                "--dataloader", "datasets.dataset_512.ImageFolderMaskDataset",
                "--mirror", "True",
                "--cond", "False",
                "--cfg", "places512",
                "--aug", "noaug",
                "--generator", "networks.mat.Generator",
                "--discriminator", "networks.mat.Discriminator",
                "--loss", "losses.loss.TwoStageLoss",
                "--pr", "0.1",
                "--pl", "False",
                "--truncation", "0.5",
                "--style_mix", "0.5",
                "--ema", "10",
                "--lr", "0.001",
            ],
            "console": "integratedTerminal",
            "justMyCode": true
        }
    ]
}