Machine Learning/Pytorch
[PyTorch] 2-4. Torch Hub
euphoria0-0
2020. 7. 14. 23:22
This article is based on the book "Deep Learning with PyTorch"
https://pytorch.org/deep-learning-with-pytorch
2. Pretrained Networks
- 이미지 레이블링 모델
- 새로운 이미지 생성 모델
- 이미지 캡셔닝 모델
- Torch Hub
2-4. Torch Hub
Torch Hub: 작성자가 GitHub에 모델을 배포(publish)하고 PyTorch가 이해가능한 인터페이스로 노출시키도록 하는 메터니즘
배포 시 hubconf.py 파일 필요
dependencies = ['torch', 'math'] # 의존하는 모듈
# 레포의 entry point에서 사용자에게 노출되는 함수
def some_entry_fn(*args, **kwargs):
model = build_some_model(*args, **kwargs)
return model
def another_entry_fn(*args, **kwargs):
model = build_another_model(*args, **kwargs)
return model
repo의 master branch와 가중치를 로컬 디렉토리(.torch/hub)로 다운로드하고 resnet18(레이어 18개인 ResNet)의 entry-point 함수를 실행한다
import torch
from torch import hub
resnet18_model = hub.load('pytorch/vision:master', # GihHub repo
'resnet18', # entry-point 함수 이름
pretrained=True)
이로부터 새로운 모델로 활용하는 등 잘 사용해보자!!