-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translate pytorch_vision_ghostnet #40
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,23 +23,23 @@ 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) | ||
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,) 의 텐서 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ImageNet Dataset은 데이터셋의 이름이니까 |
||
print(output[0]) | ||
# The output has unnormalized scores. To get probabilities, you can run a softmax on it. | ||
# output은 정규화되지 않은 스코어로 얻어짐. 확률을 얻기 위해 소프트맥스를 사용할 수 있음 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 완전한 문장에서 끝을 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분 같은 경우에는 의도적으로 주석은 "-ㅁ"로 본문은 "-다" 로 번역하였는데 하나로 통일 하는 것이 더 좋을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 제 의견을 드리자면 하나로 통일하는 것이 좋을 것 같습니다. 😄 |
||
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 카테고리를 보여줌 | ||
KyubumShin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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. | ||
고스트넷 아키텍처는 다양한 특징 맵을 효율적인 연산으로 생성하는 고스트 모듈 구조로 이루어집니다. 고유한 특징 맵을 기반으로 한 효율적인 연산으로 추론에 기반이 되는 고유 특징들을 충분하게 드러내는 고스트 특징 맵을 생성합니다. 벤치마크에서 수행된 실험을 통해 속도와 정확도의 상충 관계에 관한 고스트넷의 우수성을 보여줍니다. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
- 고유한 특징 맵을 기반으로 한 효율적인 연산으로 추론에 기반이 되는 고유 특징들을 충분하게 드러내는 고스트 특징 맵을 생성합니다.
+ 고스트넷은 내부적으로 특징맵을 가지고 있습니다.
+ 이 특징맵의 정보를 온전히 드러내기 위해 간단한 연산을 거쳐 고스트 특징맵을 다량으로 만들어냅니다. 처럼 번역하는 것은 어떨지 제안드립니다 :) |
||
|
||
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}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
excution
의 의미를 살려도 좋지 않을까 의견을 남겨봅니다.실행 예시 코드
혹은예시 실행 코드
와 같이 코드가 실행을 위한 것임을 밝혀도 좋을 것 같습니다.