본문 바로가기
Network

[DNN] torchvision module 이용해서 resnet-dc5 구현하기

by pulluper 2023. 3. 21.
반응형

Resnet50 등에서 dc5 구현방법

 

dc5 모델이란?

https://github.com/facebookresearch/detectron2/blob/main/MODEL_ZOO.md

 

GitHub - facebookresearch/detectron2: Detectron2 is a platform for object detection, segmentation and other visual recognition t

Detectron2 is a platform for object detection, segmentation and other visual recognition tasks. - GitHub - facebookresearch/detectron2: Detectron2 is a platform for object detection, segmentation a...

github.com

 

ResNet conv5 에서 dilations 를 사용한것이란다 ! 

 

코드는 torchvision 이용했고

torchvision models.resnet50 등에 "replace_stride_with_dilation=[False, False, True]" params 추가

[Ture, True, True] 면 모든 downsample 안하는 bottleneck의 convs 들에게 dilations=2  

 

import torch
import torch.nn as nn
from torchvision.models import resnet50


if __name__ == '__main__':

    resnet50_wo_fc = nn.Sequential(*list(nn.ModuleList(resnet50(pretrained=True).children()))[:-2])
    resnet50dc5_wo_fc = nn.Sequential(*list(nn.ModuleList(resnet50(pretrained=True,
                                                                   replace_stride_with_dilation=[False, False, True]).children()))[:-2])

    img = torch.randn([2, 3, 1024, 1024])
    print(resnet50_wo_fc(img).size())
    print(resnet50dc5_wo_fc(img).size())

 

아무튼 Resnet50-DC5 는 위와같고 결과는 

 

첫번째 결과는 [2, 2048, 32, 32] (stride 32),

두번째 결과는 [2, 2048, 64, 64] (stride 16)

 

반응형

댓글