Skip to content

Commit

Permalink
ResNeXt101 λ²ˆμ—­ (#100)
Browse files Browse the repository at this point in the history
* ResNeXt101 λ²ˆμ—­
  • Loading branch information
HyunKyungHan authored Apr 2, 2023
1 parent c395c3e commit b576b52
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions nvidia_deeplearningexamples_resnext.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@ demo-model-link: https://huggingface.co/spaces/pytorch/ResNeXt101
---


### Model Description
### λͺ¨λΈ μ„€λͺ…

The ***ResNeXt101-32x4d*** is a model introduced in the [Aggregated Residual Transformations for Deep Neural Networks](https://arxiv.org/pdf/1611.05431.pdf) paper.
***ResNeXt101-32x4d***λŠ” [Aggregated Residual Transformations for Deep Neural Networks](https://arxiv.org/pdf/1611.05431.pdf) 논문에 μ†Œκ°œλœ λͺ¨λΈμž…λ‹ˆλ‹€.

It is based on regular ResNet model, substituting 3x3 convolutions inside the bottleneck block for 3x3 grouped convolutions.
이 λͺ¨λΈμ€ 일반적인 ResNet λͺ¨λΈμ— κΈ°λ°˜μ„ 두고 있으며 ResNet의 3x3 κ·Έλ£Ή ν•©μ„±κ³±(Grouped Convolution) 계측을 병λͺ© 블둝(Bottleneck Block) λ‚΄λΆ€μ˜ 3x3 ν•©μ„±κ³± κ³„μΈ΅μœΌλ‘œ λŒ€μ²΄ν•©λ‹ˆλ‹€.

This model is trained with mixed precision using Tensor Cores on Volta, Turing, and the NVIDIA Ampere GPU architectures. Therefore, researchers can get results 3x faster than training without Tensor Cores, while experiencing the benefits of mixed precision training. This model is tested against each NGC monthly container release to ensure consistent accuracy and performance over time.
ResNeXt101 λͺ¨λΈμ€ Volta, Turing 및 NVIDIA Ampere μ•„ν‚€ν…μ²˜μ—μ„œ Tensor Coreλ₯Ό μ‚¬μš©ν•˜μ—¬ ν˜Όν•© 정밀도(Mixed Precision) 방식<sup>[1]</sup>으둜 ν•™μŠ΅λ©λ‹ˆλ‹€. λ”°λΌμ„œ μ—°κ΅¬μžλ“€μ€ ν˜Όν•© 정밀도 ν•™μŠ΅μ˜ μž₯점을 κ²½ν—˜ν•˜λŠ” λ™μ‹œμ— Tensor Coresλ₯Ό μ‚¬μš©ν•˜μ§€ μ•Šμ„ λ•Œλ³΄λ‹€ κ²°κ³Όλ₯Ό 3λ°° λΉ λ₯΄κ²Œ 얻을 수 μžˆμŠ΅λ‹ˆλ‹€. 이 λͺ¨λΈμ€ μ‹œκ°„μ΄ 지남에도 지속적인 정확도와 μ„±λŠ₯을 μœ μ§€ν•˜κΈ° μœ„ν•΄ 월별 NGC μ»¨ν…Œμ΄λ„ˆ μΆœμ‹œμ— λŒ€ν•΄ ν…ŒμŠ€νŠΈλ˜κ³  μžˆμŠ΅λ‹ˆλ‹€.

We use [NHWC data layout](https://pytorch.org/tutorials/intermediate/memory_format_tutorial.html) when training using Mixed Precision.
ν˜Όν•© 정밀도 ν•™μŠ΅μ—λŠ” [NHWC 데이터 λ ˆμ΄μ•„μ›ƒ](https://pytorch.org/tutorials/intermediate/memory_format_tutorial.html)이 μ‚¬μš©λ©λ‹ˆλ‹€.

Note that the ResNeXt101-32x4d model can be deployed for inference on the [NVIDIA Triton Inference Server](https://github.com/NVIDIA/trtis-inference-server) using TorchScript, ONNX Runtime or TensorRT as an execution backend. For details check [NGC](https://ngc.nvidia.com/catalog/resources/nvidia:resnext_for_triton_from_pytorch)
ResNeXt101-32x4d λͺ¨λΈμ€ 좔둠을 μœ„ν•΄ TorchScript, ONNX Runtime λ˜λŠ” TensorRTλ₯Ό μ‹€ν–‰ λ°±μ—”λ“œλ‘œ μ‚¬μš©ν•˜κ³  [NVIDIA Triton Inference Server](https://github.com/NVIDIA/trtis-inference-server)에 배포할 수 μžˆμŠ΅λ‹ˆλ‹€. μžμ„Έν•œ λ‚΄μš©μ€ [NGC](https://catalog.ngc.nvidia.com/orgs/nvidia/resources/resnext_for_triton_from_pytorch)μ—μ„œ ν™•μΈν•˜μ„Έμš”.

#### Model architecture
#### λͺ¨λΈ ꡬ쑰

![ResNextArch](https://pytorch.org/assets/images/ResNeXtArch.png)

_Image source: [Aggregated Residual Transformations for Deep Neural Networks](https://arxiv.org/pdf/1611.05431.pdf)_
_이미지 좜처: Aggregated Residual Transformations for Deep Neural Networks](https://arxiv.org/pdf/1611.05431.pdf)_

Image shows difference between ResNet bottleneck block and ResNeXt bottleneck block.
μœ„μ˜ μ΄λ―Έμ§€λŠ” ResNet λͺ¨λΈμ˜ 병λͺ© 블둝과 ResNeXt λͺ¨λΈμ˜ 병λͺ© λΈ”λ‘μ˜ 차이λ₯Ό λ‚˜νƒ€λƒ…λ‹ˆλ‹€.

ResNeXt101-32x4d model's cardinality equals to 32 and bottleneck width equals to 4.
### Example
ResNeXt101-32x4d λͺ¨λΈμ˜ 카디널리티(Cardinality)λŠ” 32이고 병λͺ© λΈ”λ‘μ˜ WidthλŠ” 4μž…λ‹ˆλ‹€.
### μ˜ˆμ‹œ

In the example below we will use the pretrained ***ResNeXt101-32x4d*** model to perform inference on images and present the result.
μ•„λž˜ μ˜ˆμ‹œμ—μ„œ 사전 ν•™μŠ΅λœ ***ResNeXt101-32x4d***λͺ¨λΈμ„ μ‚¬μš©ν•˜μ—¬ 이미지듀에 λŒ€ν•œ 좔둠을 μ§„ν–‰ν•˜κ³  κ²°κ³Όλ₯Ό μ œμ‹œν•©λ‹ˆλ‹€.

To run the example you need some extra python packages installed. These are needed for preprocessing images and visualization.
μ˜ˆμ‹œλ₯Ό μ‹€ν–‰ν•˜λ €λ©΄ 좔가적인 파이썬 νŒ¨ν‚€μ§€λ“€μ΄ μ„€μΉ˜λ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€. 이 νŒ¨ν‚€μ§€λ“€μ€ 이미지 μ „μ²˜λ¦¬ 및 μ‹œκ°ν™”μ— ν•„μš”ν•©λ‹ˆλ‹€.
```python
!pip install validators matplotlib
```
Expand All @@ -64,15 +64,15 @@ device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cp
print(f'Using {device} for inference')
```

Load the model pretrained on IMAGENET dataset.
IMAGENET λ°μ΄ν„°μ…‹μœΌλ‘œ 사전 ν•™μŠ΅λœ λͺ¨λΈμ„ λΆˆλŸ¬μ˜΅λ‹ˆλ‹€.
```python
resneXt = torch.hub.load('NVIDIA/DeepLearningExamples:torchhub', 'nvidia_resneXt')
utils = torch.hub.load('NVIDIA/DeepLearningExamples:torchhub', 'nvidia_convnets_processing_utils')

resneXt.eval().to(device)
```

Prepare sample input data.
μƒ˜ν”Œ μž…λ ₯ 데이터λ₯Ό μ€€λΉ„ν•©λ‹ˆλ‹€.
```python
uris = [
'http://images.cocodataset.org/test-stuff2017/000000024309.jpg',
Expand All @@ -87,15 +87,15 @@ batch = torch.cat(
).to(device)
```

Run inference. Use `pick_n_best(predictions=output, n=topN)` helepr function to pick N most probably hypothesis according to the model.
좔둠을 μ‹œμž‘ν•©λ‹ˆλ‹€. 헬퍼 ν•¨μˆ˜ `pick_n_best(predictions=output, n=topN)`λ₯Ό μ‚¬μš©ν•΄ λͺ¨λΈμ— λŒ€ν•œ N개의 κ°€μž₯ κ°€λŠ₯성이 높은 가섀을 μ„ νƒν•©λ‹ˆλ‹€.
```python
with torch.no_grad():
output = torch.nn.functional.softmax(resneXt(batch), dim=1)

results = utils.pick_n_best(predictions=output, n=5)
```

Display the result.
κ²°κ³Όλ₯Ό 좜λ ₯ν•©λ‹ˆλ‹€.
```python
for uri, result in zip(uris, results):
img = Image.open(requests.get(uri, stream=True).raw)
Expand All @@ -106,15 +106,16 @@ for uri, result in zip(uris, results):

```

### Details
For detailed information on model input and output, training recipies, inference and performance visit:
[github](https://github.com/NVIDIA/DeepLearningExamples/tree/master/PyTorch/Classification/ConvNets/resnext101-32x4d)
and/or [NGC](https://ngc.nvidia.com/catalog/resources/nvidia:resnext_for_pytorch)
### 세뢀사항
λͺ¨λΈ μž…λ ₯ 및 좜λ ₯, ν•™μŠ΅ 방법, μΆ”λ‘  및 μ„±λŠ₯에 λŒ€ν•œ μžμ„Έν•œ λ‚΄μš©μ€ [github](https://github.com/NVIDIA/DeepLearningExamples/tree/master/PyTorch/Classification/ConvNets/resnext101-32x4d)μ΄λ‚˜ [NGC](https://catalog.ngc.nvidia.com/orgs/nvidia/resources/resnext_for_pytorch)μ—μ„œ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.


### References
### μ°Έκ³ λ¬Έν—Œ

- [Aggregated Residual Transformations for Deep Neural Networks](https://arxiv.org/pdf/1611.05431.pdf)
- [model on github](https://github.com/NVIDIA/DeepLearningExamples/tree/master/PyTorch/Classification/ConvNets/resnext101-32x4d)
- [model on NGC](https://ngc.nvidia.com/catalog/resources/nvidia:resnext_for_pytorch)
- [pretrained model on NGC](https://ngc.nvidia.com/catalog/models/nvidia:resnext101_32x4d_pyt_amp)


<a name="ν˜Όν•© 정밀도(Mixed Precision) 방식">[1]</a>: λΉ λ₯΄κ³  효율적인 처리λ₯Ό μœ„ν•΄ 16λΉ„νŠΈ λΆ€λ™μ†Œμˆ˜μ κ³Ό 32λΉ„νŠΈ λΆ€λ™μ†Œμˆ˜μ μ„ ν•¨κ»˜ μ‚¬μš©ν•΄ ν•™μŠ΅ν•˜λŠ” 방식.

0 comments on commit b576b52

Please sign in to comment.