diff --git a/docs/model_contribute_guide.md b/docs/model_contribute_guide.md new file mode 100644 index 0000000..df79910 --- /dev/null +++ b/docs/model_contribute_guide.md @@ -0,0 +1,61 @@ +# Model Contributing Guide line +pytorch hub에 모델을 추가하는 Contributing 가이드라인 입니다. + +## 기여방법 +[PyTorch 한국어 모델 허브 사이트](https://pytorch.kr/hub/)에 새로운 모델을 추가하기 위한 기여 방법입니다 + +#### 1. 이슈 남기기 + +(매우 낮은 확률로) 해당 모델이 추가되는 중일 수 있으니, 작업을 진행하기 전에 [본 저장소에 이슈](https://github.com/PyTorchKorea/hub-kr/issues)를 검색하거나 새로 남겨주세요. + +해당 문제점에 대한 개선 사항이 이미 논의되었거나 진행 중인 Pull Request를 통해 해결 중일 수 있으니, 새로 이슈를 만드시기 전, 먼저 검색을 해주시기를 부탁드립니다. + +이후, 새로 남겨주신 이슈에서 저장소 관리자 및 다른 방문자들이 함께 문제점에 대해 토의하실 수 있습니다. (또는 이미 관련 이슈가 존재하지만 해결 중이지 않은 경우에는 덧글을 통해 기여를 시작함을 알려주세요.) + +#### 2. 저장소 복제하기 + +새로운 모델에 대한 설명을 추가하기 위해 저장소를 복제합니다. +저장소 복제가 처음이시라면 [GitHub의 저장소 복제 관련 도움말](https://help.github.com/en/github/getting-started-with-github/fork-a-repo)을 참조해주세요. + + +#### 3. ```hubconf.py``` 작성하기 + +```torch.hub.load```를 통하여 모델을 불러오기 위해서는 해당 모델의 저장소에 ```hubconf.py```가 추가되여야 합니다. + +```python +dependencies = ['torch'] + + +def model_name(*args, **kwargs): + """ + Docstring : torch.hub.help() 에 나타 날 부분 + """ + # 모델을 정의하고, 사전학습된 가중치를 모델에 불러옵니다 + model = load_model(pretrained = True, **kwargs) + return model +``` + +```hubconf.py``` 는 다음의 요소들을 가지고 있고, 조건들을 만족하여야 합니다. + +* ```dependencies``` : 모델을 불러오기 위해 필요한 패키지들을 작성해 두는 변수입니다. +* ```docstring``` : 모델을 사용하기 위하여 도움을 주는 문서입니다. ```torch.hub.help``` 를 통하여 출력 됩니다. +* entrypoint 함수들은 모델(nn.Module)이나 원할한 작업을 위한 서포트툴을 반환해야합니다. +* torch.hub.list로 보여지고 싶지 않은 함수들은 접두사에 ```_``` 문자를 붙여 나타나지 않게 할 수 있습니다. +* 사전학습된 가중치들을 불러오기 위해서 ```torch.hub.load_state_dict_from_url()``` 이용하여 url로 부터 불러올 수 있습니다. + +더 자세한 내용은 [torch.hub docs](https://pytorch.org/docs/master/hub.html#publishing-models)를 참고하시길 바랍니다. + +#### 4. 허브 문서 작성 + +복사한 hub kr에 ```__.md``` 의 형식으로 문서를 생성하고 다음의 [템플릿](https://github.com/PyTorchKorea/hub-kr/blob/master/docs/template.md)에 맞춰 작성합니다. + +#### 5. (내 컴퓨터에서) 결과 확인하기 + +저장소의 최상위 경로에서 `preview_hub.sh` 명령어를 이용하면 코드 실행 없이 `http://127.0.0.1:4000/` 로컬 주소를 활용하여 빌드 결과물을 빠르게 확인하실 수 있습니다. \ +이 과정에서 수정한 문서 상에서 발생하는 오류가 있다면 Markdown 문법을 참고하여 올바르게 고쳐주세요. + +#### 6. Pull Request 만들기 + +번역을 완료한 내용을 복제한 저장소에 Commit 및 Push하고, Pull Request를 남깁니다. \ +Pull Request를 만드시기 전에 이 문서에 포함된 [Pull Request 만들기](#Pull-Request-만들기) 부분을 반드시 읽어주세요. \ +만약 Pull Request 만들기가 처음이시라면 [GitHub의 Pull Request 소개 도움말](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests) 및 [복제한 저장소로부터 Pull Request 만들기 도움말](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork)을 참조해주세요 \ No newline at end of file diff --git a/pytorch_vision_ghostnet.md b/pytorch_vision_ghostnet.md index 693bd5b..781a165 100644 --- a/pytorch_vision_ghostnet.md +++ b/pytorch_vision_ghostnet.md @@ -23,15 +23,15 @@ model = torch.hub.load('huawei-noah/ghostnet', 'ghostnet_1x', pretrained=True) model.eval() ``` -All pre-trained models expect input images normalized in the same way, -i.e. mini-batches of 3-channel RGB images of shape `(3 x H x W)`, where `H` and `W` are expected to be at least `224`. -The images have to be loaded in to a range of `[0, 1]` and then normalized using `mean = [0.485, 0.456, 0.406]` -and `std = [0.229, 0.224, 0.225]`. +모든 사전 학습된 모델들은 입력 이미지가 동일한 방식으로 정규화 되는 것을 요구합니다. +다시 말해 `H`와 `W`가 적어도 `224`이고, `(3 x H x W)`의 shape를 가지는 3채널 RGB 이미지들의 미니배치를 말합니다. +이 이미지들은 `[0, 1]`의 범위로 로드되어야 하고, `mean = [0.485, 0.456, 0.406]` +과 `std = [0.229, 0.224, 0.225]`를 사용하여 정규화되어야 합니다. -Here's a sample execution. +여기서부터는 예시 코드 입니다. ```python -# Download an example image from the pytorch website +# pytorch 웹사이트에서 예시 이미지를 다운로드 import urllib url, filename = ("https://github.com/pytorch/hub/raw/master/images/dog.jpg", "dog.jpg") try: urllib.URLopener().retrieve(url, filename) @@ -39,7 +39,7 @@ except: urllib.request.urlretrieve(url, filename) ``` ```python -# sample execution (requires torchvision) +# 예시 코드 (torchvision 필요) from PIL import Image from torchvision import transforms input_image = Image.open(filename) @@ -50,51 +50,51 @@ preprocess = transforms.Compose([ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), ]) input_tensor = preprocess(input_image) -input_batch = input_tensor.unsqueeze(0) # create a mini-batch as expected by the model +input_batch = input_tensor.unsqueeze(0) # 모델에 맞추어 미니배치를 생성 -# move the input and model to GPU for speed if available +# 연산속도를 위해 input과 모델을 GPU에 로드 if torch.cuda.is_available(): input_batch = input_batch.to('cuda') model.to('cuda') with torch.no_grad(): output = model(input_batch) -# Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes +# 이미지넷 1000개의 클래스의 신뢰점수를 포함하는 (1000,) 의 텐서 print(output[0]) -# The output has unnormalized scores. To get probabilities, you can run a softmax on it. +# output은 정규화되지 않은 스코어로 얻어짐. 확률을 얻기 위해 소프트맥스를 사용할 수 있음 probabilities = torch.nn.functional.softmax(output[0], dim=0) print(probabilities) ``` ``` -# Download ImageNet labels +# 이미지넷의 라벨을 다운로드 !wget https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt ``` ``` -# Read the categories +# 카테고리를 읽음 with open("imagenet_classes.txt", "r") as f: categories = [s.strip() for s in f.readlines()] -# Show top categories per image +# 이미지 당 top 카테고리를 보여줌 top5_prob, top5_catid = torch.topk(probabilities, 5) for i in range(top5_prob.size(0)): print(categories[top5_catid[i]], top5_prob[i].item()) ``` -### Model Description +### 모델 설명 -The GhostNet architecture is based on an Ghost module structure which generate more features from cheap operations. Based on a set of intrinsic feature maps, a series of cheap operations are applied to generate many ghost feature maps that could fully reveal information underlying intrinsic features. Experiments conducted on benchmarks demonstrate that the superiority of GhostNet in terms of speed and accuracy tradeoff. +고스트넷 아키텍처는 다양한 특징 맵을 효율적인 연산으로 생성하는 고스트 모듈 구조로 이루어집니다. 고유한 특징 맵을 기반으로 한 효율적인 연산으로 추론에 기반이 되는 고유 특징들을 충분하게 드러내는 고스트 특징 맵을 생성합니다. 벤치마크에서 수행된 실험을 통해 속도와 정확도의 상충 관계에 관한 고스트넷의 우수성을 보여줍니다. -The corresponding accuracy on ImageNet dataset with pretrained model is listed below. +사전 학습된 모델을 사용한 ImageNet 데이터셋에 따른 정확도는 아래에 나열되어 있습니다. | Model structure | FLOPs | Top-1 acc | Top-5 acc | | --------------- | ----------- | ----------- | ----------- | | GhostNet 1.0x | 142M | 73.98 | 91.46 | -### References +### 참고 -You can read the full paper at this [link](https://arxiv.org/abs/1911.11907). +다음 [링크](https://arxiv.org/abs/1911.11907)에서 논문의 전체적인 내용에 대하여 읽을 수 있습니다. >@inproceedings{han2019ghostnet, > title={GhostNet: More Features from Cheap Operations},