Skip to content

Commit 38da685

Browse files
authored
Merge branch 'main' into please_dont_modify_this_branch_unless_you_are_just_merging_with_main__
2 parents d4e6817 + 229d852 commit 38da685

File tree

12 files changed

+83
-13
lines changed

12 files changed

+83
-13
lines changed

.github/workflows/prototype-tests-linux-gpu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
gpu-arch-type: cuda
2424
gpu-arch-version: "11.8"
2525
fail-fast: false
26-
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
26+
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
2727
with:
2828
repository: pytorch/vision
2929
runner: ${{ matrix.runner }}

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
gpu-arch-type: cuda
2727
gpu-arch-version: "11.8"
2828
fail-fast: false
29-
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
29+
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
3030
with:
3131
repository: pytorch/vision
3232
runner: ${{ matrix.runner }}
@@ -104,7 +104,7 @@ jobs:
104104
./.github/scripts/unittest.sh
105105
106106
onnx:
107-
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
107+
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
108108
with:
109109
repository: pytorch/vision
110110
test-infra-ref: main
@@ -135,7 +135,7 @@ jobs:
135135
echo '::endgroup::'
136136
137137
unittests-extended:
138-
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
138+
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
139139
if: contains(github.event.pull_request.labels.*.name, 'run-extended')
140140
with:
141141
repository: pytorch/vision

references/depth/stereo/utils/losses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def make_gaussian_kernel(kernel_size: int, sigma: float) -> torch.Tensor:
1313
y = torch.arange(kernel_size, dtype=torch.float32)
1414
x = x - (kernel_size - 1) / 2
1515
y = y - (kernel_size - 1) / 2
16-
x, y = torch.meshgrid(x, y)
16+
x, y = torch.meshgrid(x, y, indexing="ij")
1717
grid = (x**2 + y**2) / (2 * sigma**2)
1818
kernel = torch.exp(-grid)
1919
kernel = kernel / kernel.sum()

references/video_classification/train.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def main(args):
164164

165165
if args.cache_dataset and os.path.exists(cache_path):
166166
print(f"Loading dataset_train from {cache_path}")
167-
dataset, _ = torch.load(cache_path, weights_only=True)
167+
dataset, _ = torch.load(cache_path, weights_only=False)
168168
dataset.transform = transform_train
169169
else:
170170
if args.distributed:
@@ -201,7 +201,7 @@ def main(args):
201201

202202
if args.cache_dataset and os.path.exists(cache_path):
203203
print(f"Loading dataset_test from {cache_path}")
204-
dataset_test, _ = torch.load(cache_path, weights_only=True)
204+
dataset_test, _ = torch.load(cache_path, weights_only=False)
205205
dataset_test.transform = transform_test
206206
else:
207207
if args.distributed:
723 Bytes
Loading

test/test_backbone_utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import random
2+
from copy import deepcopy
23
from itertools import chain
34
from typing import Mapping, Sequence
45

@@ -322,3 +323,14 @@ def forward(self, x):
322323
out = model(self.inp)
323324
# And backward
324325
out["leaf_module"].float().mean().backward()
326+
327+
def test_deepcopy(self):
328+
# Non-regression test for https://github.com/pytorch/vision/issues/8634
329+
model = models.efficientnet_b3(weights=None)
330+
extractor = create_feature_extractor(model=model, return_nodes={"classifier.0": "out"})
331+
332+
extractor.eval()
333+
extractor.train()
334+
extractor = deepcopy(extractor)
335+
extractor.eval()
336+
extractor.train()

test/test_utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ def test_draw_boxes():
116116
assert_equal(img, img_cp)
117117

118118

119+
@pytest.mark.skipif(PILLOW_VERSION < (10, 1), reason="The reference image is only valid for PIL >= 10.1")
120+
def test_draw_boxes_with_coloured_labels():
121+
img = torch.full((3, 100, 100), 255, dtype=torch.uint8)
122+
labels = ["a", "b", "c", "d"]
123+
colors = ["green", "#FF00FF", (0, 255, 0), "red"]
124+
label_colors = ["green", "red", (0, 255, 0), "#FF00FF"]
125+
result = utils.draw_bounding_boxes(img, boxes, labels=labels, colors=colors, fill=True, label_colors=label_colors)
126+
127+
path = os.path.join(
128+
os.path.dirname(os.path.abspath(__file__)), "assets", "fakedata", "draw_boxes_different_label_colors.png"
129+
)
130+
expected = torch.as_tensor(np.array(Image.open(path))).permute(2, 0, 1)
131+
assert_equal(result, expected)
132+
133+
119134
@pytest.mark.parametrize("fill", [True, False])
120135
def test_draw_boxes_dtypes(fill):
121136
img_uint8 = torch.full((3, 100, 100), 255, dtype=torch.uint8)

torchvision/datasets/lsun.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __len__(self) -> int:
5555

5656

5757
class LSUN(VisionDataset):
58-
"""`LSUN <https://www.yf.io/p/lsun>`_ dataset.
58+
"""`LSUN <https://paperswithcode.com/dataset/lsun>`_ dataset.
5959
6060
You will need to install the ``lmdb`` package to use this dataset: run
6161
``pip install lmdb``

torchvision/models/feature_extraction.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import copy
12
import inspect
23
import math
34
import re
@@ -10,7 +11,7 @@
1011
import torch
1112
import torchvision
1213
from torch import fx, nn
13-
from torch.fx.graph_module import _copy_attr
14+
from torch.fx.graph_module import _CodeOnlyModule, _copy_attr, _USER_PRESERVED_ATTRIBUTES_KEY
1415

1516

1617
__all__ = ["create_feature_extractor", "get_graph_node_names"]
@@ -330,6 +331,40 @@ def train(self, mode=True):
330331
self.graph = self.eval_graph
331332
return super().train(mode=mode)
332333

334+
def _deepcopy_init(self):
335+
# See __deepcopy__ below
336+
return DualGraphModule.__init__
337+
338+
def __deepcopy__(self, memo):
339+
# Same as the base class' __deepcopy__ from pytorch, with minor
340+
# modification to account for train_graph and eval_graph
341+
# https://github.com/pytorch/pytorch/blob/f684dbd0026f98f8fa291cab74dbc4d61ba30580/torch/fx/graph_module.py#L875
342+
#
343+
# This is using a bunch of private stuff from torch, so if that breaks,
344+
# we'll likely have to remove this, along with the associated
345+
# non-regression test.
346+
res = type(self).__new__(type(self))
347+
memo[id(self)] = res
348+
fake_mod = _CodeOnlyModule(copy.deepcopy(self.__dict__, memo))
349+
self._deepcopy_init()(res, fake_mod, fake_mod.__dict__["train_graph"], fake_mod.__dict__["eval_graph"])
350+
351+
extra_preserved_attrs = [
352+
"_state_dict_hooks",
353+
"_load_state_dict_pre_hooks",
354+
"_load_state_dict_post_hooks",
355+
"_replace_hook",
356+
"_create_node_hooks",
357+
"_erase_node_hooks",
358+
]
359+
for attr in extra_preserved_attrs:
360+
if attr in self.__dict__:
361+
setattr(res, attr, copy.deepcopy(self.__dict__[attr], memo))
362+
res.meta = copy.deepcopy(getattr(self, "meta", {}), memo)
363+
if _USER_PRESERVED_ATTRIBUTES_KEY in res.meta:
364+
for attr_name, attr in res.meta[_USER_PRESERVED_ATTRIBUTES_KEY].items():
365+
setattr(res, attr_name, attr)
366+
return res
367+
333368

334369
def create_feature_extractor(
335370
model: nn.Module,

torchvision/models/googlenet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def eager_outputs(self, x: Tensor, aux2: Tensor, aux1: Optional[Tensor]) -> Goog
171171

172172
def forward(self, x: Tensor) -> GoogLeNetOutputs:
173173
x = self._transform_input(x)
174-
x, aux1, aux2 = self._forward(x)
174+
x, aux2, aux1 = self._forward(x)
175175
aux_defined = self.training and self.aux_logits
176176
if torch.jit.is_scripting():
177177
if not aux_defined:

0 commit comments

Comments
 (0)