Skip to content

Commit

Permalink
Merge from master
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterL1n committed Sep 17, 2021
2 parents 3951e1a + acab279 commit 7dd9984
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 58 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
name: Run Pytorch scripts
command: ./scripts/run_pytorch.sh
no_output_timeout: 1h
- store_test_results:
path: test-results


workflows:
version: 2
Expand Down
2 changes: 1 addition & 1 deletion pytorch_vision_alexnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ category: researchers
image: alexnet2.png
author: Pytorch Team
tags: [vision, scriptable]
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/alexnet.py
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/alexnet.py
github-id: pytorch/vision
featured_image_1: alexnet1.png
featured_image_2: alexnet2.png
Expand Down
25 changes: 16 additions & 9 deletions pytorch_vision_deeplabv3_resnet101.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
layout: hub_detail
background-class: hub-background
body-class: hub
title: Deeplabv3-ResNet101
summary: DeepLabV3 model with a ResNet-101 backbone
title: Deeplabv3
summary: DeepLabV3 models with ResNet-50, ResNet-101 and MobileNet-V3 backbones
category: researchers
image: deeplab2.png
author: Pytorch Team
tags: [vision, scriptable]
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/segmentation/deeplabv3.py
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/segmentation/deeplabv3.py
github-id: pytorch/vision
featured_image_1: deeplab1.png
featured_image_2: deeplab2.png
Expand All @@ -18,7 +18,10 @@ order: 1

```python
import torch
model = torch.hub.load('pytorch/vision:v0.10.0', 'deeplabv3_resnet101', pretrained=True)
model = torch.hub.load('pytorch/vision:v0.10.0', 'deeplabv3_resnet50', pretrained=True)
# or any of these variants
# model = torch.hub.load('pytorch/vision:v0.10.0', 'deeplabv3_resnet101', pretrained=True)
# model = torch.hub.load('pytorch/vision:v0.10.0', 'deeplabv3_mobilenet_v3_large', pretrained=True)
model.eval()
```

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

### Model Description

Deeplabv3-ResNet101 is constructed by a Deeplabv3 model with a ResNet-101 backbone.
Deeplabv3-ResNet is constructed by a Deeplabv3 model using a ResNet-50 or ResNet-101 backbone.
Deeplabv3-MobileNetV3-Large is constructed by a Deeplabv3 model using the MobileNetV3 large backbone.
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.

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

| Model structure | Mean IOU | Global Pixelwise Accuracy |
| ------------------- | ----------- | --------------------------|
| deeplabv3_resnet101 | 67.4 | 92.4 |
| Model structure | Mean IOU | Global Pixelwise Accuracy |
| ---------------------------- | ----------- | --------------------------|
| deeplabv3_resnet50 | 66.4 | 92.4 |
| deeplabv3_resnet101 | 67.4 | 92.4 |
| deeplabv3_mobilenet_v3_large | 60.3 | 91.2 |

### Resources

Expand Down
2 changes: 1 addition & 1 deletion pytorch_vision_densenet.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ category: researchers
image: densenet1.png
author: Pytorch Team
tags: [vision, scriptable]
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/densenet.py
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/densenet.py
github-id: pytorch/vision
featured_image_1: densenet1.png
featured_image_2: densenet2.png
Expand Down
16 changes: 10 additions & 6 deletions pytorch_vision_fcn_resnet101.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
layout: hub_detail
background-class: hub-background
body-class: hub
title: FCN-ResNet101
summary: Fully-Convolutional Network model with a ResNet-101 backbone
title: FCN
summary: Fully-Convolutional Network model with ResNet-50 and ResNet-101 backbones
category: researchers
image: fcn2.png
author: Pytorch Team
tags: [vision, scriptable]
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/segmentation/fcn.py
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/segmentation/fcn.py
github-id: pytorch/vision
featured_image_1: deeplab1.png
featured_image_2: fcn2.png
Expand All @@ -18,7 +18,9 @@ order: 10

```python
import torch
model = torch.hub.load('pytorch/vision:v0.10.0', 'fcn_resnet101', pretrained=True)
model = torch.hub.load('pytorch/vision:v0.10.0', 'fcn_resnet50', pretrained=True)
# or
# model = torch.hub.load('pytorch/vision:v0.10.0', 'fcn_resnet101', pretrained=True)
model.eval()
```

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

### Model Description

FCN-ResNet101 is constructed by a Fully-Convolutional Network model with a ResNet-101 backbone.
FCN-ResNet is constructed by a Fully-Convolutional Network model, using a ResNet-50 or a ResNet-101 backbone.
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.

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

| Model structure | Mean IOU | Global Pixelwise Accuracy |
| --------------- | ----------- | --------------------------|
| fcn_resnet50 | 60.5 | 91.4 |
| fcn_resnet101 | 63.7 | 91.9 |

### Resources
Expand Down
2 changes: 1 addition & 1 deletion pytorch_vision_googlenet.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ category: researchers
image: googlenet1.png
author: Pytorch Team
tags: [vision]
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/googlenet.py
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/googlenet.py
github-id: pytorch/vision
featured_image_1: googlenet1.png
featured_image_2: googlenet2.png
Expand Down
2 changes: 1 addition & 1 deletion pytorch_vision_inception_v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ category: researchers
image: inception_v3.png
author: Pytorch Team
tags: [vision, scriptable]
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/inception.py
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/inception.py
github-id: pytorch/vision
featured_image_1: inception_v3.png
featured_image_2: no-image
Expand Down
2 changes: 1 addition & 1 deletion pytorch_vision_mobilenet_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ category: researchers
image: mobilenet_v2_1.png
author: Pytorch Team
tags: [vision, scriptable]
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/mobilenet.py
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/mobilenet.py
github-id: pytorch/vision
featured_image_1: mobilenet_v2_1.png
featured_image_2: mobilenet_v2_2.png
Expand Down
2 changes: 1 addition & 1 deletion pytorch_vision_resnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ category: researchers
image: resnet.png
author: Pytorch Team
tags: [vision, scriptable]
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py
github-id: pytorch/vision
featured_image_1: resnet.png
featured_image_2: no-image
Expand Down
2 changes: 1 addition & 1 deletion pytorch_vision_resnext.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ category: researchers
image: resnext.png
author: Pytorch Team
tags: [vision, scriptable]
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py
github-id: pytorch/vision
featured_image_1: resnext.png
featured_image_2: no-image
Expand Down
2 changes: 1 addition & 1 deletion pytorch_vision_shufflenet_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ category: researchers
image: shufflenet_v2_1.png
author: Pytorch Team
tags: [vision, scriptable]
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/shufflenetv2.py
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/shufflenetv2.py
github-id: pytorch/vision
featured_image_1: shufflenet_v2_1.png
featured_image_2: shufflenet_v2_2.png
Expand Down
2 changes: 1 addition & 1 deletion pytorch_vision_squeezenet.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ category: researchers
image: squeezenet.png
author: Pytorch Team
tags: [vision, scriptable]
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/squeezenet.py
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/squeezenet.py
github-id: pytorch/vision
featured_image_1: squeezenet.png
featured_image_2: no-image
Expand Down
2 changes: 1 addition & 1 deletion pytorch_vision_vgg.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ category: researchers
image: vgg.png
author: Pytorch Team
tags: [vision, scriptable]
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/vgg.py
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/vgg.py
github-id: pytorch/vision
featured_image_1: vgg.png
featured_image_2: no-image
Expand Down
2 changes: 1 addition & 1 deletion pytorch_vision_wide_resnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ category: researchers
image: wide_resnet.png
author: Sergey Zagoruyko
tags: [vision, scriptable]
github-link: https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py
github-link: https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py
github-id: pytorch/vision
featured_image_1: wide_resnet.png
featured_image_2: no-image
Expand Down
2 changes: 2 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ conda activate base

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

conda install -y pytest

# Dependencies required to load models
conda install -y regex pillow tqdm boto3 requests numpy\
h5py scipy matplotlib unidecode ipython pyyaml
Expand Down
44 changes: 12 additions & 32 deletions scripts/run_pytorch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,20 @@
. ~/miniconda3/etc/profile.d/conda.sh
conda activate base

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

declare -i error_code=0
mkdir $PYTHON_CODE_DIR

for f in $ALL_FILE
# Quick rundown: for each file we extract the python code that's within
# the ``` markers and we put that code in a corresponding .py file in $PYTHON_CODE_DIR
# Then we execute each of these python files with pytest in test_run_python_code.py
for f in $ALL_FILES
do
echo "Running pytorch example in $f"
# FIXME: NVIDIA models checkoints are on cuda
if [[ $f = $CUDAS* ]]; then
echo "...skipped due to cuda checkpoints."
elif [[ $f = "pytorch_fairseq_translation"* ]]; then
echo "...temporarily disabled"
# FIXME: torch.nn.modules.module.ModuleAttributeError: 'autoShape' object has no attribute 'fuse'
elif [[ $f = "ultralytics_yolov5"* ]]; then
echo "...temporarily disabled"
elif [[ $f = "huggingface_pytorch-transformers"* ]]; then
echo "...temporarily disabled"
elif [[ $f = "peterl1n_robustvideomatting"* ]]; then
echo "...temporarily disabled"
# FIXME: TypeError: compose() got an unexpected keyword argument 'strict'
elif [[ $f = "pytorch_fairseq_roberta"* ]]; then
echo "...temporarily disabled"
# FIXME: rate limiting
else
sed -n '/^```python/,/^```/ p' < $f | sed '/^```/ d' > $TEMP_PY
python $TEMP_PY
error_code+=$?

if [ -f "$TEMP_PY" ]; then
rm $TEMP_PY
fi
fi
f_no_ext=${f%.md} # remove .md extension
out_py=$PYTHON_CODE_DIR/$f_no_ext.py
echo "Extracting Python code from $f into $out_py"
sed -n '/^```python/,/^```/ p' < $f | sed '/^```/ d' > $out_py
done

exit $error_code
pytest --junitxml=test-results/junit.xml test_run_python_code.py -vv
43 changes: 43 additions & 0 deletions test_run_python_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from subprocess import check_output, STDOUT, CalledProcessError
import sys
import pytest
import glob


PYTHON_CODE_DIR = "python_code"
ALL_FILES = glob.glob(PYTHON_CODE_DIR + "/*.py")


@pytest.mark.parametrize('file_path', ALL_FILES)
def test_run_file(file_path):
if 'nvidia' in file_path:
# FIXME: NVIDIA models checkoints are on cuda
pytest.skip("temporarily disabled")
if 'pytorch_fairseq_translation' in file_path:
pytest.skip("temporarily disabled")
if 'ultralytics_yolov5' in file_path:
# FIXME torch.nn.modules.module.ModuleAttributeError: 'autoShape' object has no attribute 'fuse
pytest.skip("temporarily disabled")
if 'huggingface_pytorch-transformers' in file_path:
# FIXME torch.nn.modules.module.ModuleAttributeError: 'autoShape' object has no attribute 'fuse
pytest.skip("temporarily disabled")
if 'pytorch_fairseq_roberta' in file_path:
pytest.skip("temporarily disabled")
if 'robustvideomatting' in file_path:
pytest.skip("temporarily disabled")

# We just run the python files in a separate sub-process. We really want a
# subprocess here because otherwise we might run into package versions
# issues: imagine script A that needs torchvivion 0.9 and script B that
# needs torchvision 0.10. If script A is run prior to script B in the same
# process, script B will still be run with torchvision 0.9 because the only
# "import torchvision" statement that counts is the first one, and even
# torchub sys.path shenanigans can do nothing about this. By creating
# subprocesses we're sure that all file executions are fully independent.
try:
# This is inspired (and heavily simplified) from
# https://github.com/cloudpipe/cloudpickle/blob/343da119685f622da2d1658ef7b3e2516a01817f/tests/testutils.py#L177
out = check_output([sys.executable, file_path], stderr=STDOUT)
print(out.decode())
except CalledProcessError as e:
raise RuntimeError(f"Script {file_path} errored with output:\n{e.output.decode()}")

0 comments on commit 7dd9984

Please sign in to comment.