티스토리 뷰

https://github.com/IDEA-Research/DINO

 

GitHub - IDEA-Research/DINO: [ICLR 2023] Official implementation of the paper "DINO: DETR with Improved DeNoising Anchor Boxes f

[ICLR 2023] Official implementation of the paper "DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection" - GitHub - IDEA-Research/DINO: [ICLR 2023] Official impl...

github.com

DINO는 2023 년 4월 17일 기준 COCO test-dev Benchmark 에서 12위라는 높은 순위를 기록하고 있는 모델이다.

해당 모델은 DETR 을 베이스로 둔 후속 모델 중 하나로 볼 수 있다. 소개된 논문의 제목 또한 "DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection" 으로, 제목에도 DETR이 포함돼있다.

 

공개된지는 이미 몇개월이 지난 모델인데 미루고 미루다 한 번 돌려보았다.

 

미루었던 이유 중 하나는 CUDA operators 를 따로 컴파일까지 해야하는 번거로움이 있어서였다. 뭔가 빌드 과정에서 오류가 잔뜩 날 것 같은 두려움이 앞섰던것이다... 개인적으로 Native PyTorch operators 만으로 구현되는 모델이 좋다... 그래야 배포 과정에서 Onnxruntime, TensorRT 등의 다양한 Inference Engine에서 not supported ... 같은 에러를 볼 가능성이 적어지기 때문이다.

Compiling CUDA...?

당장 DINO 이슈에 CUDA를 검색해봐도 Compile에서 오류가 발생했다는 유저들이 많다.

그치만...! 성능이 너무 궁금했다. 현재(2023년 4월 17일) COCO test-dev Benchmark에서 1등을 달성한 InternImage 모델의 경우에도 DINO를 Detector로 사용하여 1등을 달성했고, 여러 최상위권 모델들이 DINO를 Detector로 한 경우가 많아서 돌려는 봐야겠다는 생각이 들었다.

설치

https://github.com/IDEA-Research/DINO#installation

 

GitHub - IDEA-Research/DINO: [ICLR 2023] Official implementation of the paper "DINO: DETR with Improved DeNoising Anchor Boxes f

[ICLR 2023] Official implementation of the paper "DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection" - GitHub - IDEA-Research/DINO: [ICLR 2023] Official impl...

github.com

위 단계를 따르되, PyTorch는 공식 홈페이지에있는 https://pytorch.org/ 에 있는 명령어를 이용해서 최신 버전을 다운로드 받았고 pycocotools가 제대로 설치가 안되어 requirements.txt를 수정해줬다.

cython
pycocotools
submitit
torch>=1.5.0
torchvision>=0.6.0
git+https://github.com/cocodataset/panopticapi.git#egg=panopticapi
scipy
termcolor
addict
yapf
timm

 

4. Compiling CUDA operators 단계(gpu driver version: 531.61, cuda version: 11.4, pytorch cuda version: 11.7)에서 딱히 빌드 오류는 없었고 python test.py 실행시 메모리가 부족해서 메모리 사이즈 에러는 발생했다. 어쨌든 작은 인풋 사이즈(D= 30, 32, 64, 71) 에서 돌아갔으니 빌드는 잘 된것이니 무시해줬다.

그런 다음  https://github.com/IDEA-Research/DINO#model-zoo 에 안내된 Google Drive 링크에서 아래의 pth 파일을 다운로드 받았다.

5scale swin이 config 폴더에 없어서 4scale_swin pth 파일을 받았다.

COCO 데이터셋 기준 58.0 AP를 기록한 Weights이다.

 

이제 https://github.com/IDEA-Research/DINO/blob/main/inference_and_visualization.ipynb 이거 따라서 py 파일로 다시 구현하고 돌려봤는데 안된다!

 

일단 py파일 내용은 아래와 같다.

 

import torch, json

from main import build_model_main
from util.slconfig import SLConfig
from util.visualizer import COCOVisualizer
from util import box_ops

model_config_path = "config/DINO/DINO_4scale_swin.py" # change the path of the model config file
model_checkpoint_path = "checkpoint0029_4scale_swin.pth" # change the path of the model checkpoint
# See our Model Zoo section in README.md for more details about our pretrained models.

args = SLConfig.fromfile(model_config_path) 
args.device = 'cuda' 
model, criterion, postprocessors = build_model_main(args)
checkpoint = torch.load(model_checkpoint_path, map_location='cpu')
model.load_state_dict(checkpoint['model'])
_ = model.eval()

# load coco names
with open('util/coco_id2name.json') as f:
    id2name = json.load(f)
    id2name = {int(k):v for k,v in id2name.items()}
    
from PIL import Image
import datasets.transforms as T

image = Image.open("./figs/idea.jpg").convert("RGB") # load image

# transform images
transform = T.Compose([
    T.RandomResize([800], max_size=1333),
    T.ToTensor(),
    T.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])
image, _ = transform(image, None)

# predict images
output = model.cuda()(image[None].cuda())
output = postprocessors['bbox'](output, torch.Tensor([[1.0, 1.0]]).cuda())[0]

# visualize outputs
thershold = 0.3 # set a thershold

vslzr = COCOVisualizer()

scores = output['scores']
labels = output['labels']
boxes = box_ops.box_xyxy_to_cxcywh(output['boxes'])
select_mask = scores > thershold

box_label = [id2name[int(item)] for item in labels[select_mask]]
pred_dict = {
    'boxes': boxes[select_mask],
    'size': torch.Tensor([image.shape[1], image.shape[2]]),
    'box_label': box_label
}
vslzr.visualize(image, pred_dict, savedir=None, dpi=100)

 

2개의 에러

https://github.com/IDEA-Research/DINO/pull/184

 

Add exception handling code for windows os and inference task by developer0hye · Pull Request #184 · IDEA-Research/DINO

It is related to #43 and #68.

github.com

PR 날려서 고쳐놨다.

1. PermissionError

PermissionError: [Errno 13] Permission denied: 'C:\\Users\\yonghye\\AppData\\Local\\Temp\\tmp4ypiuwgb\\tmpfsiyzo4j.py'

util/slconfig.py 에서 temp_config_file.close()를 추가적으로 호출해주면된다.

https://github.com/IDEA-Research/DINO/issues/43

 

PermissionError: [Errno 13] Permission denied: 'C:\\Users\\20825\\AppData\\Local\\Temp\\tmpt11h2ul9\\tmp2fdhjty4.py' · Issue #4

thanks for your greate work. Recently, I wanted to train my own dataset bash scripts/DINO_train.sh COCODIR The result error: Not using distributed mode Loading config file from config/DINO/DINO_4sc...

github.com

2. AttributeError: 'ConfigDict' object has no attribute 'backbone_dir'

models/dino/backbone.py에서 pretrained 백본을 load하는 부분을 주석 처리하면 된다.

 

위 부분을 모두 수정해주고 실행해보면 잘 출력되는 것을 확인할 수 있다.

 

AP 60 넘는 Weights 은 어디있나요?

https://github.com/IDEA-Research/detrex 이 프로젝트에 있다고한다.

 

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함