Skip to content

Commit d355c7b

Browse files
authored
Merge branch 'main' into proto-bbox-rotate
2 parents 33e497c + fdd3aab commit d355c7b

File tree

135 files changed

+4735
-7165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+4735
-7165
lines changed

.circleci/config.yml

Lines changed: 23 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.circleci/config.yml.in

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,14 @@ commands:
155155
install_prototype_dependencies:
156156
steps:
157157
- pip_install:
158-
args: iopath git+https://github.com/pytorch/data
159-
descr: Install prototype dependencies
158+
args: iopath
159+
descr: Install third-party dependencies
160+
- pip_install:
161+
args: -r https://raw.githubusercontent.com/pytorch/data/main/requirements.txt
162+
descr: Install torchdata build dependencies
163+
- pip_install:
164+
args: --no-build-isolation git+https://github.com/pytorch/data
165+
descr: Install torchdata from source
160166

161167
# Most of the test suite is handled by the `unittest` jobs, with completely different workflow and setup.
162168
# This command can be used if only a selection of tests need to be run, for ad-hoc files.
@@ -360,19 +366,28 @@ jobs:
360366
resource_class: xlarge
361367
steps:
362368
- checkout
363-
- download_model_weights:
364-
extract_roots: torchvision/prototype/models
365369
- install_torchvision
366370
- install_prototype_dependencies
367371
- pip_install:
368372
args: scipy pycocotools h5py
369373
descr: Install optional dependencies
370-
- run:
371-
name: Enable prototype tests
372-
command: echo 'export PYTORCH_TEST_WITH_PROTOTYPE=1' >> $BASH_ENV
373374
- run_tests_selective:
374375
file_or_dir: test/test_prototype_*.py
375376

377+
unittest_extended:
378+
docker:
379+
- image: circleci/python:3.7
380+
resource_class: xlarge
381+
steps:
382+
- checkout
383+
- download_model_weights
384+
- install_torchvision
385+
- run:
386+
name: Enable extended tests
387+
command: echo 'export PYTORCH_TEST_WITH_EXTENDED=1' >> $BASH_ENV
388+
- run_tests_selective:
389+
file_or_dir: test/test_extended_*.py
390+
376391
binary_linux_wheel:
377392
<<: *binary_common
378393
docker:
@@ -1109,6 +1124,7 @@ workflows:
11091124
- unittest_torchhub
11101125
- unittest_onnx
11111126
- unittest_prototype
1127+
- unittest_extended
11121128
{{ unittest_workflows() }}
11131129

11141130
cmake:

.circleci/unittest/linux/scripts/install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ else
2121
fi
2222
echo "Using CUDA $CUDA_VERSION as determined by CU_VERSION"
2323
version="$(python -c "print('.'.join(\"${CUDA_VERSION}\".split('.')[:2]))")"
24-
cudatoolkit="cudatoolkit=${version}"
24+
cudatoolkit="nvidia::cudatoolkit=${version}"
2525
fi
2626

2727
case "$(uname -s)" in
@@ -33,7 +33,7 @@ printf "Installing PyTorch with %s\n" "${cudatoolkit}"
3333
if [ "${os}" == "MacOSX" ]; then
3434
conda install -y -c "pytorch-${UPLOAD_CHANNEL}" "pytorch-${UPLOAD_CHANNEL}"::pytorch "${cudatoolkit}" pytest
3535
else
36-
conda install -y -c "pytorch-${UPLOAD_CHANNEL}" "pytorch-${UPLOAD_CHANNEL}"::pytorch[build="*${version}*"] "${cudatoolkit}" pytest
36+
conda install -y -c "pytorch-${UPLOAD_CHANNEL}" -c nvidia "pytorch-${UPLOAD_CHANNEL}"::pytorch[build="*${version}*"] "${cudatoolkit}" pytest
3737
fi
3838

3939
printf "* Installing torchvision\n"

android/test_app/make_assets.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import torch
2-
import torchvision
32
from torch.utils.mobile_optimizer import optimize_for_mobile
3+
from torchvision.models.detection import (
4+
fasterrcnn_mobilenet_v3_large_320_fpn,
5+
FasterRCNN_MobileNet_V3_Large_320_FPN_Weights,
6+
)
47

58
print(torch.__version__)
69

7-
model = torchvision.models.detection.fasterrcnn_mobilenet_v3_large_320_fpn(
8-
pretrained=True, box_score_thresh=0.7, rpn_post_nms_top_n_test=100, rpn_score_thresh=0.4, rpn_pre_nms_top_n_test=150
10+
model = fasterrcnn_mobilenet_v3_large_320_fpn(
11+
weights=FasterRCNN_MobileNet_V3_Large_320_FPN_Weights.DEFAULT,
12+
box_score_thresh=0.7,
13+
rpn_post_nms_top_n_test=100,
14+
rpn_score_thresh=0.4,
15+
rpn_pre_nms_top_n_test=150,
916
)
1017

1118
model.eval()

docs/source/models.rst

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -98,58 +98,6 @@ You can construct a model with random weights by calling its constructor:
9898
convnext_large = models.convnext_large()
9999
100100
We provide pre-trained models, using the PyTorch :mod:`torch.utils.model_zoo`.
101-
These can be constructed by passing ``pretrained=True``:
102-
103-
.. code:: python
104-
105-
import torchvision.models as models
106-
resnet18 = models.resnet18(pretrained=True)
107-
alexnet = models.alexnet(pretrained=True)
108-
squeezenet = models.squeezenet1_0(pretrained=True)
109-
vgg16 = models.vgg16(pretrained=True)
110-
densenet = models.densenet161(pretrained=True)
111-
inception = models.inception_v3(pretrained=True)
112-
googlenet = models.googlenet(pretrained=True)
113-
shufflenet = models.shufflenet_v2_x1_0(pretrained=True)
114-
mobilenet_v2 = models.mobilenet_v2(pretrained=True)
115-
mobilenet_v3_large = models.mobilenet_v3_large(pretrained=True)
116-
mobilenet_v3_small = models.mobilenet_v3_small(pretrained=True)
117-
resnext50_32x4d = models.resnext50_32x4d(pretrained=True)
118-
wide_resnet50_2 = models.wide_resnet50_2(pretrained=True)
119-
mnasnet = models.mnasnet1_0(pretrained=True)
120-
efficientnet_b0 = models.efficientnet_b0(pretrained=True)
121-
efficientnet_b1 = models.efficientnet_b1(pretrained=True)
122-
efficientnet_b2 = models.efficientnet_b2(pretrained=True)
123-
efficientnet_b3 = models.efficientnet_b3(pretrained=True)
124-
efficientnet_b4 = models.efficientnet_b4(pretrained=True)
125-
efficientnet_b5 = models.efficientnet_b5(pretrained=True)
126-
efficientnet_b6 = models.efficientnet_b6(pretrained=True)
127-
efficientnet_b7 = models.efficientnet_b7(pretrained=True)
128-
efficientnet_v2_s = models.efficientnet_v2_s(pretrained=True)
129-
efficientnet_v2_m = models.efficientnet_v2_m(pretrained=True)
130-
efficientnet_v2_l = models.efficientnet_v2_l(pretrained=True)
131-
regnet_y_400mf = models.regnet_y_400mf(pretrained=True)
132-
regnet_y_800mf = models.regnet_y_800mf(pretrained=True)
133-
regnet_y_1_6gf = models.regnet_y_1_6gf(pretrained=True)
134-
regnet_y_3_2gf = models.regnet_y_3_2gf(pretrained=True)
135-
regnet_y_8gf = models.regnet_y_8gf(pretrained=True)
136-
regnet_y_16gf = models.regnet_y_16gf(pretrained=True)
137-
regnet_y_32gf = models.regnet_y_32gf(pretrained=True)
138-
regnet_x_400mf = models.regnet_x_400mf(pretrained=True)
139-
regnet_x_800mf = models.regnet_x_800mf(pretrained=True)
140-
regnet_x_1_6gf = models.regnet_x_1_6gf(pretrained=True)
141-
regnet_x_3_2gf = models.regnet_x_3_2gf(pretrained=True)
142-
regnet_x_8gf = models.regnet_x_8gf(pretrained=True)
143-
regnet_x_16gf = models.regnet_x_16gf(pretrainedTrue)
144-
regnet_x_32gf = models.regnet_x_32gf(pretrained=True)
145-
vit_b_16 = models.vit_b_16(pretrained=True)
146-
vit_b_32 = models.vit_b_32(pretrained=True)
147-
vit_l_16 = models.vit_l_16(pretrained=True)
148-
vit_l_32 = models.vit_l_32(pretrained=True)
149-
convnext_tiny = models.convnext_tiny(pretrained=True)
150-
convnext_small = models.convnext_small(pretrained=True)
151-
convnext_base = models.convnext_base(pretrained=True)
152-
convnext_large = models.convnext_large(pretrained=True)
153101

154102
Instancing a pre-trained model will download its weights to a cache directory.
155103
This directory can be set using the `TORCH_HOME` environment variable. See
@@ -517,15 +465,13 @@ a model with random weights by calling its constructor:
517465
resnext101_32x8d = models.quantization.resnext101_32x8d()
518466
shufflenet_v2_x0_5 = models.quantization.shufflenet_v2_x0_5()
519467
shufflenet_v2_x1_0 = models.quantization.shufflenet_v2_x1_0()
520-
shufflenet_v2_x1_5 = models.quantization.shufflenet_v2_x1_5()
521-
shufflenet_v2_x2_0 = models.quantization.shufflenet_v2_x2_0()
522468
523469
Obtaining a pre-trained quantized model can be done with a few lines of code:
524470

525471
.. code:: python
526472
527473
import torchvision.models as models
528-
model = models.quantization.mobilenet_v2(pretrained=True, quantize=True)
474+
model = models.quantization.mobilenet_v2(weights=MobileNet_V2_QuantizedWeights.IMAGENET1K_QNNPACK_V1, quantize=True)
529475
model.eval()
530476
# run the model with quantized inputs and weights
531477
out = model(torch.rand(1, 3, 224, 224))

examples/cpp/hello_world/trace_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
HERE = osp.dirname(osp.abspath(__file__))
77
ASSETS = osp.dirname(osp.dirname(HERE))
88

9-
model = torchvision.models.resnet18(pretrained=False)
9+
model = torchvision.models.resnet18()
1010
model.eval()
1111

1212
traced_model = torch.jit.script(model)

gallery/plot_optical_flow.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import torch
2020
import matplotlib.pyplot as plt
2121
import torchvision.transforms.functional as F
22-
import torchvision.transforms as T
2322

2423

2524
plt.rcParams["savefig.bbox"] = "tight"
@@ -88,24 +87,19 @@ def plot(imgs, **imshow_kwargs):
8887
# reduce the image sizes for the example to run faster. Image dimension must be
8988
# divisible by 8.
9089

90+
from torchvision.models.optical_flow import Raft_Large_Weights
9191

92-
def preprocess(batch):
93-
transforms = T.Compose(
94-
[
95-
T.ConvertImageDtype(torch.float32),
96-
T.Normalize(mean=0.5, std=0.5), # map [0, 1] into [-1, 1]
97-
T.Resize(size=(520, 960)),
98-
]
99-
)
100-
batch = transforms(batch)
101-
return batch
92+
weights = Raft_Large_Weights.DEFAULT
93+
transforms = weights.transforms()
10294

10395

104-
# If you can, run this example on a GPU, it will be a lot faster.
105-
device = "cuda" if torch.cuda.is_available() else "cpu"
96+
def preprocess(img1_batch, img2_batch):
97+
img1_batch = F.resize(img1_batch, size=[520, 960])
98+
img2_batch = F.resize(img2_batch, size=[520, 960])
99+
return transforms(img1_batch, img2_batch)
100+
106101

107-
img1_batch = preprocess(img1_batch).to(device)
108-
img2_batch = preprocess(img2_batch).to(device)
102+
img1_batch, img2_batch = preprocess(img1_batch, img2_batch)
109103

110104
print(f"shape = {img1_batch.shape}, dtype = {img1_batch.dtype}")
111105

@@ -121,7 +115,10 @@ def preprocess(batch):
121115

122116
from torchvision.models.optical_flow import raft_large
123117

124-
model = raft_large(pretrained=True, progress=False).to(device)
118+
# If you can, run this example on a GPU, it will be a lot faster.
119+
device = "cuda" if torch.cuda.is_available() else "cpu"
120+
121+
model = raft_large(weights=Raft_Large_Weights.DEFAULT, progress=False).to(device)
125122
model = model.eval()
126123

127124
list_of_flows = model(img1_batch.to(device), img2_batch.to(device))
@@ -182,10 +179,9 @@ def preprocess(batch):
182179
# from torchvision.io import write_jpeg
183180
# for i, (img1, img2) in enumerate(zip(frames, frames[1:])):
184181
# # Note: it would be faster to predict batches of flows instead of individual flows
185-
# img1 = preprocess(img1[None]).to(device)
186-
# img2 = preprocess(img2[None]).to(device)
182+
# img1, img2 = preprocess(img1, img2)
187183

188-
# list_of_flows = model(img1_batch, img2_batch)
184+
# list_of_flows = model(img1.to(device), img1.to(device))
189185
# predicted_flow = list_of_flows[-1][0]
190186
# flow_img = flow_to_image(predicted_flow).to("cpu")
191187
# output_folder = "/tmp/" # Update this to the folder of your choice

gallery/plot_repurposing_annotations.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,14 @@ def show(imgs):
139139
# Here is demo with a Faster R-CNN model loaded from
140140
# :func:`~torchvision.models.detection.fasterrcnn_resnet50_fpn`
141141

142-
from torchvision.models.detection import fasterrcnn_resnet50_fpn
142+
from torchvision.models.detection import fasterrcnn_resnet50_fpn, FasterRCNN_ResNet50_FPN_Weights
143143

144-
model = fasterrcnn_resnet50_fpn(pretrained=True, progress=False)
144+
weights = FasterRCNN_ResNet50_FPN_Weights.DEFAULT
145+
model = fasterrcnn_resnet50_fpn(weights=weights, progress=False)
145146
print(img.size())
146147

147-
img = F.convert_image_dtype(img, torch.float)
148+
tranforms = weights.transforms()
149+
img = tranforms(img)
148150
target = {}
149151
target["boxes"] = boxes
150152
target["labels"] = labels = torch.ones((masks.size(0),), dtype=torch.int64)

gallery/plot_scripted_tensor_transforms.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,16 @@ def show(imgs):
8585
# Let's define a ``Predictor`` module that transforms the input tensor and then
8686
# applies an ImageNet model on it.
8787

88-
from torchvision.models import resnet18
88+
from torchvision.models import resnet18, ResNet18_Weights
8989

9090

9191
class Predictor(nn.Module):
9292

9393
def __init__(self):
9494
super().__init__()
95-
self.resnet18 = resnet18(pretrained=True, progress=False).eval()
96-
self.transforms = nn.Sequential(
97-
T.Resize([256, ]), # We use single int value inside a list due to torchscript type restrictions
98-
T.CenterCrop(224),
99-
T.ConvertImageDtype(torch.float),
100-
T.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
101-
)
95+
weights = ResNet18_Weights.DEFAULT
96+
self.resnet18 = resnet18(weights=weights, progress=False).eval()
97+
self.transforms = weights.transforms()
10298

10399
def forward(self, x: torch.Tensor) -> torch.Tensor:
104100
with torch.no_grad():

0 commit comments

Comments
 (0)