Model architecture 설계를 위해 크게 3가지를 사용한다.
from detectron2.modeling import build_model
model = build_model(cfg) # returns a torch.nn.Module
앞에서 만들어진 model architecture에 pretrained weight를 입혀주는 단계 & 학습이 끝난 이후 save 하는 단계이다.
Load 과정에서 사용할 수 있는 Format은 pth와 pkl 파일 이다. 각각,
from detectron2.checkpoint import DetectionCheckpointer
# Checkpoint load 하는 단계, usually from cfg.MODEL.WEIGHTS
DetectionCheckpointer(model).load(file_path_or_url)
# Checkpoint save 하는 단계
checkpointer = DetectionCheckpointer(model, save_dir="output")
checkpointer.save("model_999") # save to output/model_999.pth
training 단계에서는 항상 EventStorage안에서 forward processing이 이뤄져야 한다.
from detectron2.utils.events import EventStorage
with EventStorage() as storage:
losses = model(inputs)
두가지 방법이 있다
model.eval()
with torch.no_grad():
outputs = model(inputs)
직접 해보자. 하나하나 설명하기에는 너무 많다. 핵심만 보자.
기본적으로 input은 list[dict] 형태로 되어 있고 각각의 dict는 하나의 image에 대한 정보를 담고 있다.
Dict는 다음과 같은 keys를 포함하고 있다.
Key value | Type | Description |
"image" | tensor | image (C, H, W) |
"height", "width" | image size in inference (즉, 항상 training에 사용한 사이즈와 같으 필요가 없음) | |
"instances" | instance object for training (including gt_boxes, gt_classes, gt_masks, gt_keypoints) | |
"sem_seg" | tensor[int] | semantic segmentation ground truth in (H, W) format. 값은 label (from 0) |
"proposals" | instance object only for Fas R-CNN style models |
직접 해보자. 하나하나 설명하기에는 너무 많다. 핵심만 보자.
Dict는 다음과 같은 keys를 포함하고 있다.
Key value |
Type | Description | |
"instances" | instance object (including “pred_boxes”, "scores", "pred_classes", “pred_masks”, “pred_keypoints”) |
||
"sem_seg" | tensor | semantic segmentation prediction (num_categories, H, W) | |
"proposals" | instance object (including “proposal_boxes” and “objectness_logits”) | ||
“panoptic_seg” | pred | segment id of each pixel | |
segments_info | segment information (including "id", "isthing", and "category_id") |
Conv Architecture 저장소 (0) | 2022.11.27 |
---|---|
Detectron2 활용법 (4) - Training and Evaluation (0) | 2022.10.14 |
Detectron2 활용법 (2) - Dataloader & Data Augmentation (0) | 2022.10.14 |
Detectron2 활용법 (1) - Dataset (0) | 2022.10.07 |
Yolov7 based Image Classification (0) | 2022.09.20 |
댓글 영역