Skip to content

Commit 7dd9984

Browse files
committed
Merge from master
2 parents 3951e1a + acab279 commit 7dd9984

17 files changed

+97
-58
lines changed

.circleci/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jobs:
2525
name: Run Pytorch scripts
2626
command: ./scripts/run_pytorch.sh
2727
no_output_timeout: 1h
28+
- store_test_results:
29+
path: test-results
30+
2831

2932
workflows:
3033
version: 2

pytorch_vision_alexnet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ category: researchers
88
image: alexnet2.png
99
author: Pytorch Team
1010
tags: [vision, scriptable]
11-
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/alexnet.py
11+
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/alexnet.py
1212
github-id: pytorch/vision
1313
featured_image_1: alexnet1.png
1414
featured_image_2: alexnet2.png

pytorch_vision_deeplabv3_resnet101.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
layout: hub_detail
33
background-class: hub-background
44
body-class: hub
5-
title: Deeplabv3-ResNet101
6-
summary: DeepLabV3 model with a ResNet-101 backbone
5+
title: Deeplabv3
6+
summary: DeepLabV3 models with ResNet-50, ResNet-101 and MobileNet-V3 backbones
77
category: researchers
88
image: deeplab2.png
99
author: Pytorch Team
1010
tags: [vision, scriptable]
11-
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/segmentation/deeplabv3.py
11+
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/segmentation/deeplabv3.py
1212
github-id: pytorch/vision
1313
featured_image_1: deeplab1.png
1414
featured_image_2: deeplab2.png
@@ -18,7 +18,10 @@ order: 1
1818

1919
```python
2020
import torch
21-
model = torch.hub.load('pytorch/vision:v0.10.0', 'deeplabv3_resnet101', pretrained=True)
21+
model = torch.hub.load('pytorch/vision:v0.10.0', 'deeplabv3_resnet50', pretrained=True)
22+
# or any of these variants
23+
# model = torch.hub.load('pytorch/vision:v0.10.0', 'deeplabv3_resnet101', pretrained=True)
24+
# model = torch.hub.load('pytorch/vision:v0.10.0', 'deeplabv3_mobilenet_v3_large', pretrained=True)
2225
model.eval()
2326
```
2427

@@ -35,7 +38,7 @@ So, `output['out']` is of shape `(N, 21, H, W)`. More documentation can be found
3538
```python
3639
# Download an example image from the pytorch website
3740
import urllib
38-
url, filename = ("https://github.com/pytorch/hub/raw/master/images/dog.jpg", "dog.jpg")
41+
url, filename = ("https://github.com/pytorch/hub/raw/master/images/deeplab1.png", "deeplab1.png")
3942
try: urllib.URLopener().retrieve(url, filename)
4043
except: urllib.request.urlretrieve(url, filename)
4144
```
@@ -45,6 +48,7 @@ except: urllib.request.urlretrieve(url, filename)
4548
from PIL import Image
4649
from torchvision import transforms
4750
input_image = Image.open(filename)
51+
input_image = input_image.convert("RGB")
4852
preprocess = transforms.Compose([
4953
transforms.ToTensor(),
5054
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
@@ -86,14 +90,17 @@ plt.imshow(r)
8690

8791
### Model Description
8892

89-
Deeplabv3-ResNet101 is constructed by a Deeplabv3 model with a ResNet-101 backbone.
93+
Deeplabv3-ResNet is constructed by a Deeplabv3 model using a ResNet-50 or ResNet-101 backbone.
94+
Deeplabv3-MobileNetV3-Large is constructed by a Deeplabv3 model using the MobileNetV3 large backbone.
9095
The pre-trained model has been trained on a subset of COCO train2017, on the 20 categories that are present in the Pascal VOC dataset.
9196

9297
Their accuracies of the pre-trained models evaluated on COCO val2017 dataset are listed below.
9398

94-
| Model structure | Mean IOU | Global Pixelwise Accuracy |
95-
| ------------------- | ----------- | --------------------------|
96-
| deeplabv3_resnet101 | 67.4 | 92.4 |
99+
| Model structure | Mean IOU | Global Pixelwise Accuracy |
100+
| ---------------------------- | ----------- | --------------------------|
101+
| deeplabv3_resnet50 | 66.4 | 92.4 |
102+
| deeplabv3_resnet101 | 67.4 | 92.4 |
103+
| deeplabv3_mobilenet_v3_large | 60.3 | 91.2 |
97104

98105
### Resources
99106

pytorch_vision_densenet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ category: researchers
88
image: densenet1.png
99
author: Pytorch Team
1010
tags: [vision, scriptable]
11-
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/densenet.py
11+
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/densenet.py
1212
github-id: pytorch/vision
1313
featured_image_1: densenet1.png
1414
featured_image_2: densenet2.png

pytorch_vision_fcn_resnet101.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
layout: hub_detail
33
background-class: hub-background
44
body-class: hub
5-
title: FCN-ResNet101
6-
summary: Fully-Convolutional Network model with a ResNet-101 backbone
5+
title: FCN
6+
summary: Fully-Convolutional Network model with ResNet-50 and ResNet-101 backbones
77
category: researchers
88
image: fcn2.png
99
author: Pytorch Team
1010
tags: [vision, scriptable]
11-
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/segmentation/fcn.py
11+
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/segmentation/fcn.py
1212
github-id: pytorch/vision
1313
featured_image_1: deeplab1.png
1414
featured_image_2: fcn2.png
@@ -18,7 +18,9 @@ order: 10
1818

1919
```python
2020
import torch
21-
model = torch.hub.load('pytorch/vision:v0.10.0', 'fcn_resnet101', pretrained=True)
21+
model = torch.hub.load('pytorch/vision:v0.10.0', 'fcn_resnet50', pretrained=True)
22+
# or
23+
# model = torch.hub.load('pytorch/vision:v0.10.0', 'fcn_resnet101', pretrained=True)
2224
model.eval()
2325
```
2426

@@ -35,7 +37,7 @@ So, `output['out']` is of shape `(N, 21, H, W)`. More documentation can be found
3537
```python
3638
# Download an example image from the pytorch website
3739
import urllib
38-
url, filename = ("https://github.com/pytorch/hub/raw/master/images/dog.jpg", "dog.jpg")
40+
url, filename = ("https://github.com/pytorch/hub/raw/master/images/deeplab1.png", "deeplab1.png")
3941
try: urllib.URLopener().retrieve(url, filename)
4042
except: urllib.request.urlretrieve(url, filename)
4143
```
@@ -45,6 +47,7 @@ except: urllib.request.urlretrieve(url, filename)
4547
from PIL import Image
4648
from torchvision import transforms
4749
input_image = Image.open(filename)
50+
input_image = input_image.convert("RGB")
4851
preprocess = transforms.Compose([
4952
transforms.ToTensor(),
5053
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
@@ -85,13 +88,14 @@ plt.imshow(r)
8588

8689
### Model Description
8790

88-
FCN-ResNet101 is constructed by a Fully-Convolutional Network model with a ResNet-101 backbone.
91+
FCN-ResNet is constructed by a Fully-Convolutional Network model, using a ResNet-50 or a ResNet-101 backbone.
8992
The pre-trained models have been trained on a subset of COCO train2017, on the 20 categories that are present in the Pascal VOC dataset.
9093

9194
Their accuracies of the pre-trained models evaluated on COCO val2017 dataset are listed below.
9295

9396
| Model structure | Mean IOU | Global Pixelwise Accuracy |
9497
| --------------- | ----------- | --------------------------|
98+
| fcn_resnet50 | 60.5 | 91.4 |
9599
| fcn_resnet101 | 63.7 | 91.9 |
96100

97101
### Resources

pytorch_vision_googlenet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ category: researchers
88
image: googlenet1.png
99
author: Pytorch Team
1010
tags: [vision]
11-
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/googlenet.py
11+
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/googlenet.py
1212
github-id: pytorch/vision
1313
featured_image_1: googlenet1.png
1414
featured_image_2: googlenet2.png

pytorch_vision_inception_v3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ category: researchers
88
image: inception_v3.png
99
author: Pytorch Team
1010
tags: [vision, scriptable]
11-
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/inception.py
11+
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/inception.py
1212
github-id: pytorch/vision
1313
featured_image_1: inception_v3.png
1414
featured_image_2: no-image

pytorch_vision_mobilenet_v2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ category: researchers
88
image: mobilenet_v2_1.png
99
author: Pytorch Team
1010
tags: [vision, scriptable]
11-
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/mobilenet.py
11+
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/mobilenet.py
1212
github-id: pytorch/vision
1313
featured_image_1: mobilenet_v2_1.png
1414
featured_image_2: mobilenet_v2_2.png

pytorch_vision_resnet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ category: researchers
88
image: resnet.png
99
author: Pytorch Team
1010
tags: [vision, scriptable]
11-
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py
11+
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py
1212
github-id: pytorch/vision
1313
featured_image_1: resnet.png
1414
featured_image_2: no-image

pytorch_vision_resnext.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ category: researchers
88
image: resnext.png
99
author: Pytorch Team
1010
tags: [vision, scriptable]
11-
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py
11+
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py
1212
github-id: pytorch/vision
1313
featured_image_1: resnext.png
1414
featured_image_2: no-image

pytorch_vision_shufflenet_v2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ category: researchers
88
image: shufflenet_v2_1.png
99
author: Pytorch Team
1010
tags: [vision, scriptable]
11-
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/shufflenetv2.py
11+
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/shufflenetv2.py
1212
github-id: pytorch/vision
1313
featured_image_1: shufflenet_v2_1.png
1414
featured_image_2: shufflenet_v2_2.png

pytorch_vision_squeezenet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ category: researchers
88
image: squeezenet.png
99
author: Pytorch Team
1010
tags: [vision, scriptable]
11-
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/squeezenet.py
11+
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/squeezenet.py
1212
github-id: pytorch/vision
1313
featured_image_1: squeezenet.png
1414
featured_image_2: no-image

pytorch_vision_vgg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ category: researchers
88
image: vgg.png
99
author: Pytorch Team
1010
tags: [vision, scriptable]
11-
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/vgg.py
11+
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py
1212
github-id: pytorch/vision
1313
featured_image_1: vgg.png
1414
featured_image_2: no-image

pytorch_vision_wide_resnet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ category: researchers
88
image: wide_resnet.png
99
author: Sergey Zagoruyko
1010
tags: [vision, scriptable]
11-
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py
11+
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py
1212
github-id: pytorch/vision
1313
featured_image_1: wide_resnet.png
1414
featured_image_2: no-image

scripts/install.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ conda activate base
66

77
conda install -y pytorch torchvision torchaudio -c pytorch-nightly
88

9+
conda install -y pytest
10+
911
# Dependencies required to load models
1012
conda install -y regex pillow tqdm boto3 requests numpy\
1113
h5py scipy matplotlib unidecode ipython pyyaml

scripts/run_pytorch.sh

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,20 @@
22
. ~/miniconda3/etc/profile.d/conda.sh
33
conda activate base
44

5-
ALL_FILE=$(find *.md ! -name README.md)
6-
TEMP_PY="temp.py"
7-
CUDAS="nvidia"
5+
ALL_FILES=$(find *.md ! -name README.md)
6+
PYTHON_CODE_DIR="python_code"
87

9-
declare -i error_code=0
8+
mkdir $PYTHON_CODE_DIR
109

11-
for f in $ALL_FILE
10+
# Quick rundown: for each file we extract the python code that's within
11+
# the ``` markers and we put that code in a corresponding .py file in $PYTHON_CODE_DIR
12+
# Then we execute each of these python files with pytest in test_run_python_code.py
13+
for f in $ALL_FILES
1214
do
13-
echo "Running pytorch example in $f"
14-
# FIXME: NVIDIA models checkoints are on cuda
15-
if [[ $f = $CUDAS* ]]; then
16-
echo "...skipped due to cuda checkpoints."
17-
elif [[ $f = "pytorch_fairseq_translation"* ]]; then
18-
echo "...temporarily disabled"
19-
# FIXME: torch.nn.modules.module.ModuleAttributeError: 'autoShape' object has no attribute 'fuse'
20-
elif [[ $f = "ultralytics_yolov5"* ]]; then
21-
echo "...temporarily disabled"
22-
elif [[ $f = "huggingface_pytorch-transformers"* ]]; then
23-
echo "...temporarily disabled"
24-
elif [[ $f = "peterl1n_robustvideomatting"* ]]; then
25-
echo "...temporarily disabled"
26-
# FIXME: TypeError: compose() got an unexpected keyword argument 'strict'
27-
elif [[ $f = "pytorch_fairseq_roberta"* ]]; then
28-
echo "...temporarily disabled"
29-
# FIXME: rate limiting
30-
else
31-
sed -n '/^```python/,/^```/ p' < $f | sed '/^```/ d' > $TEMP_PY
32-
python $TEMP_PY
33-
error_code+=$?
34-
35-
if [ -f "$TEMP_PY" ]; then
36-
rm $TEMP_PY
37-
fi
38-
fi
15+
f_no_ext=${f%.md} # remove .md extension
16+
out_py=$PYTHON_CODE_DIR/$f_no_ext.py
17+
echo "Extracting Python code from $f into $out_py"
18+
sed -n '/^```python/,/^```/ p' < $f | sed '/^```/ d' > $out_py
3919
done
4020

41-
exit $error_code
21+
pytest --junitxml=test-results/junit.xml test_run_python_code.py -vv

test_run_python_code.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from subprocess import check_output, STDOUT, CalledProcessError
2+
import sys
3+
import pytest
4+
import glob
5+
6+
7+
PYTHON_CODE_DIR = "python_code"
8+
ALL_FILES = glob.glob(PYTHON_CODE_DIR + "/*.py")
9+
10+
11+
@pytest.mark.parametrize('file_path', ALL_FILES)
12+
def test_run_file(file_path):
13+
if 'nvidia' in file_path:
14+
# FIXME: NVIDIA models checkoints are on cuda
15+
pytest.skip("temporarily disabled")
16+
if 'pytorch_fairseq_translation' in file_path:
17+
pytest.skip("temporarily disabled")
18+
if 'ultralytics_yolov5' in file_path:
19+
# FIXME torch.nn.modules.module.ModuleAttributeError: 'autoShape' object has no attribute 'fuse
20+
pytest.skip("temporarily disabled")
21+
if 'huggingface_pytorch-transformers' in file_path:
22+
# FIXME torch.nn.modules.module.ModuleAttributeError: 'autoShape' object has no attribute 'fuse
23+
pytest.skip("temporarily disabled")
24+
if 'pytorch_fairseq_roberta' in file_path:
25+
pytest.skip("temporarily disabled")
26+
if 'robustvideomatting' in file_path:
27+
pytest.skip("temporarily disabled")
28+
29+
# We just run the python files in a separate sub-process. We really want a
30+
# subprocess here because otherwise we might run into package versions
31+
# issues: imagine script A that needs torchvivion 0.9 and script B that
32+
# needs torchvision 0.10. If script A is run prior to script B in the same
33+
# process, script B will still be run with torchvision 0.9 because the only
34+
# "import torchvision" statement that counts is the first one, and even
35+
# torchub sys.path shenanigans can do nothing about this. By creating
36+
# subprocesses we're sure that all file executions are fully independent.
37+
try:
38+
# This is inspired (and heavily simplified) from
39+
# https://github.com/cloudpipe/cloudpickle/blob/343da119685f622da2d1658ef7b3e2516a01817f/tests/testutils.py#L177
40+
out = check_output([sys.executable, file_path], stderr=STDOUT)
41+
print(out.decode())
42+
except CalledProcessError as e:
43+
raise RuntimeError(f"Script {file_path} errored with output:\n{e.output.decode()}")

0 commit comments

Comments
 (0)