pmz-q / est_wassup_03

MIT License
1 stars 0 forks source link

est_wassup_03

Quick Start

1. Data ref

/images /train /anger /happy /test /anger /happy /labels /train /anger /happy /test /anger /happy

/images /train /test /labels /train /test ``` ### 2-5. tools/detect_face.py yolo detection weight 를 통해 이미지에서 얼굴 이미지만 crop 하여 데이터셋으로 저장합니다. 이러한 데이터셋을 cropped dataset 이라고 부릅니다. 만약, model 이 face 를 detect 하지 못할 경우, 해당 이미지는 데이터셋에서 제외됩니다. - `--dir-option`: ['train', 'val', 'test']: crop 할 데이터셋이 split 된 데이터셋인지 아닌지에 따라서 dir-option 을 지정해주면 됩니다. - `--src-data-path`: crop 할 데이터셋의 경로 - `--dst-data-path`: cropped dataset 이 저장될 경로 - `--weights-path`: yolo detection weight 의 경로 - `--target-size`: tuple: crop 될 이미지의 크기 - `--padding-option`: ['yolo', 'custom']: crop 된 이미지가 target-size 를 맞추기 위해 나머지 공간들을 채울 방범. yolo 의 경우, 배경을 추가로 넣습니다. custom 의 경우 검은색으로 채웁니다. - `--padding-scale`: float: target-size 안에서 padding 의 비율을 높이고자 할 때, 기본으로 0.8을 주고 있고, 0.7 이 recommended 입니다. ### 2-6. tools/sync_coco_annot_with_imgs.py images 폴더의 정보를 읽고 coco annotation 을 업데이트 합니다. - `--dir-option`: ['train', 'val', 'test']: sync 할 데이터셋이 split 된 데이터셋인지 아닌지에 따라서 dir-option 을 지정해주면 됩니다. - `--data-path`: sync 할 데이터셋의 경로 ## 3. Configs Train 과 inference 를 실행하기 위해선 config 파일을 생성해야 합니다. config 파일 샘플은 configs 폴더 내에 저장되어 있습니다. ### 3-1. info - `project_name`: 프로젝트의 이름: 학습 후 결과물을 저장할 때 사용됩니다. - `model_name`: 모델명: resnet50, resnet101, resnet152, yolo 중 하나를 선택하면 됩니다. - `model_task`: classification 혹은 detection 중 하나 선택하면 됩니다. - `data_root_dir`: 학습에 사용될 데이터셋의 경로 ### 3-2. train - `epochs`: epoch - `lr_scheduler`: coslr or steplr: NOTE: yolo 모델의 경우 coslr 만 지원합니다. - `lr_scheduler_params`: lr scheduler 에 kwargs 로 들어갑니다. - `batch`: batch-size - `imgsz`: int: 정사각형 이미지 - `device`: int: gpu device id: # if gpu is not available, enter cpu or mps - `optimizer`: optimizer - `optimizer_params`: optimizer params - `pretrained`: 학습에 사용될 weigth 경로 - `seed`: random seed - `dropout`: drop out ratio or 0.0 for no dropout ### 3-3. infer - `src_dir`: inference 를 진행할 이미지들이 담긴 폴더 - `pretrained`: infer 를 진행할 weight 의 경로 - `infer_task`: ['classification', 'detection']: weight 의 모델 task 에 따라서 결정됩니다. - `save_mode`: ["gray", "color", "heatmap"]: dlib 를 통한 landmark 정보 이미지 추출 시 사용됩니다. 컬러, 흑백 혹은 히트맵 저장 가능합니다. ```yaml info: # 프로젝트의 정보 project_name: project_1 model_name: resnet50 model_task: classification data_root_dir: abolute path train: epochs: 20 lr_scheduler: coslr lr_scheduler_params: # step_size: 2 # steplr params # gamma: 0.1 # steplr params # last_epoch: -1 # steplr params T_max: 10 eta_min: 0.000001 batch: 16 imgsz: 224 device: 0 optimizer: adamw # available optimizer = ['sgd', 'adam', 'adamw'] optimizer_params: lr: 0.001 weight_decay: 0.01 pretrained: abolute path # pretrained weight if wanted seed: 2024 dropout: 0.3 # 0.0 for no dropout conf: # object detection confidence threshold loss_fn: cross_entropy # ['cross_entropy'] infer: src_dir: abolute path pretrained: abolute path infer_type: "dlib" infer_task: "detection" save_mode: ["gray", "color", "heatmap"] ``` ## 4. Train ### 4-1. yolo detection yolo detection 모델로 학습을 진행합니다. config 에 `model_task` 가 `detection` 으로 지정되어있어야 합니다. config 에 `model_name` 이 `yolo` 로 지정되어있어야 합니다. `est_wassup_03/run.py` 를 실행합니다. - `-run`: ["train", "infer", "eval"]: "train" - `-type`: ["yolo", "coco"] - `-cfg`: config 의 경로 ### 4-2. yolo classification yolo classification 모델로 학습을 진행합니다. config 에 `model_task` 가 `classification` 으로 지정되어있어야 합니다. config 에 `model_name` 이 `yolo` 로 지정되어있어야 합니다. `est_wassup_03/run.py` 를 실행합니다. - `-run`: ["train", "infer", "eval"]: "train" - `-type`: ["yolo", "coco"]: "yolo" - `-cfg`: config 의 경로 ### 4-3. resnet50,resnet101,resnet152 classification resnet classification 모델로 학습을 진행합니다. config 에 `model_task` 가 `classification` 으로 지정되어있어야 합니다. config 에 `model_name` 이 `resnet50,resnet101,resnet152` 중 하나로 지정되어있어야 합니다. `est_wassup_03/run.py` 를 실행합니다. - `-run`: ["train", "infer", "eval"]: "train" - `-type`: ["yolo", "coco"]: "coco" - `-cfg`: config 의 경로 ### 4-4. posterv2 classification 4-4. posterv2 classification posterv2 classification 모델로 학습을 진행합니다. est_wassup_03/core/models/poster/main_poster.py 를 실행합니다. - `--data` : 데이터 소스 경로 - `--data_type`: 데이터셋 타입 (augmentation 방식에 차이가 있습니다) - `--checkpoint_path`: 데이터셋마다 학습한 weights 저장 경로 - `--best_checkpoint_path`: 3번의 best weights - `-j`, `--workers`: dataloader에 사용하는 worker 개수 - `--epochs` - `--start-epoch`: resume용 manual start epoch - `-b`, `--batch-size` - `--optimizer`: adamw, adam, sgd 중에서 선택 - `--lr`: learning rate - `--momentum` - `--wd`, `--weight-decay` - `-p`, `--print-freq` - `-e`, `--evaluate`: 테스트 셋에다가 evaluate할때 쓰는 모드 - `--beta`: argparser에만 있고 main함수에선 사용 안됨 - `--gpu`: gpu index ## 5. Inference ### 5-1. dlib face landmark 를 detection 하기위한 기능입니다. 다른 inference option 들과 다르게 coco annotation 데이터셋 구조의 데이터셋에서 가능합니다. `.dat` 파일이 필요합니다. # .dat file to predict landmarks # http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2 config 에 `infer` 안에 `pretrained` 를 `.bat` 파일의 경로로 지정해줍니다. config 에 `infer_type` 이 `dlib` 으로 지정되어있어야 합니다. config 에 `infer_task` 가 `detection` 으로 지정되어있어야 합니다. `est_wassup_03/run.py` 를 실행합니다. - `-run`: ["train", "infer", "eval"]: "infer" - `-type`: ["yolo", "coco"]: "coco" - `-cfg`: config 의 경로 ### 5-2. models config 에 `infer` 안에 `pretrained` 를 weight 의 경로로 지정해줍니다. config 에 `infer_type` 이 모델명으로 지정되어있어야 합니다. config 에 `infer_task` 가 `detection` 으로 지정되어있어야 합니다. `est_wassup_03/run.py` 를 실행합니다. - `-run`: ["train", "infer", "eval"]: "infer" - `-type`: ["yolo", "coco"] - `-cfg`: config 의 경로 ## 6. Results ### 6-1. yolo - `est_wassup_03/model_task/project_name/run_type/{1부터 순차적으로 증가하는 숫자}/` 에서 결과를 확인할 수 있습니다. ### 6-2. non-yolo - `est_wassup_03/model_task/project_name/run_type/{1부터 순차적으로 증가하는 숫자}/` 에서 결과를 확인할 수 있습니다. - Train extra results - tensorboard 를 활용하여 loss 그래프, accuracy 그래프, learning rate 그래프 등 확인할 수 있습니다. - results 폴더를 기준으로 tensorboard 실행하시면 됩니다. - `tensorboard --logdir={path_to_results}`