Skip to content

Commit 56a28b0

Browse files
authored
Merge branch 'master' into mobilenetv3_segmentation
2 parents 462d59a + f16322b commit 56a28b0

18 files changed

+264
-319
lines changed

packaging/conda/build_vision.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,6 @@ for py_ver in "${DESIRED_PYTHON[@]}"; do
163163
rm -rf "$output_folder"
164164
mkdir "$output_folder"
165165

166-
if [[ "$py_ver" == 3.5 ]]; then
167-
export CONDA_TYPING_CONSTRAINT="- typing"
168-
else
169-
export CONDA_TYPING_CONSTRAINT=""
170-
fi
171-
172166
export VSTOOLCHAIN_PACKAGE=vs2017
173167

174168
# We need to build the compiler activation scripts first on Windows

packaging/pkg_helpers.bash

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,6 @@ setup_macos() {
143143
fi
144144
}
145145

146-
# set variable to determine whether the typing library needs to be built in
147-
setup_typing() {
148-
if [[ "$PYTHON_VERSION" == 3.5 ]]; then
149-
export CONDA_TYPING_CONSTRAINT="- typing"
150-
else
151-
export CONDA_TYPING_CONSTRAINT=""
152-
fi
153-
}
154146

155147
# Top-level entry point for things every package will need to do
156148
#
@@ -159,7 +151,6 @@ setup_env() {
159151
setup_cuda
160152
setup_build_version "$1"
161153
setup_macos
162-
setup_typing
163154
}
164155

165156
# Function to retry functions that sometimes timeout or have flaky failures

packaging/torchvision/meta.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ test:
5252
- scipy
5353
- av =8.0.1
5454
- ca-certificates
55-
{{ environ.get('CONDA_TYPING_CONSTRAINT') }}
5655

5756

5857
about:

references/detection/coco_eval.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,10 @@ def createIndex(self):
238238
def loadRes(self, resFile):
239239
"""
240240
Load result file and return a result api object.
241-
:param resFile (str) : file name of result file
242-
:return: res (obj) : result api object
241+
Args:
242+
resFile (str): file name of result file
243+
Returns:
244+
res (obj): result api object
243245
"""
244246
res = COCO()
245247
res.dataset['images'] = [img for img in self.dataset['images']]

references/segmentation/train.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,6 @@ def main(args):
133133
model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[args.gpu])
134134
model_without_ddp = model.module
135135

136-
if args.test_only:
137-
confmat = evaluate(model, data_loader_test, device=device, num_classes=num_classes)
138-
print(confmat)
139-
return
140-
141136
params_to_optimize = [
142137
{"params": [p for p in model_without_ddp.backbone.parameters() if p.requires_grad]},
143138
{"params": [p for p in model_without_ddp.classifier.parameters() if p.requires_grad]},
@@ -155,10 +150,16 @@ def main(args):
155150

156151
if args.resume:
157152
checkpoint = torch.load(args.resume, map_location='cpu')
158-
model_without_ddp.load_state_dict(checkpoint['model'])
159-
optimizer.load_state_dict(checkpoint['optimizer'])
160-
lr_scheduler.load_state_dict(checkpoint['lr_scheduler'])
161-
args.start_epoch = checkpoint['epoch'] + 1
153+
model_without_ddp.load_state_dict(checkpoint['model'], strict=not args.test_only)
154+
if not args.test_only:
155+
optimizer.load_state_dict(checkpoint['optimizer'])
156+
lr_scheduler.load_state_dict(checkpoint['lr_scheduler'])
157+
args.start_epoch = checkpoint['epoch'] + 1
158+
159+
if args.test_only:
160+
confmat = evaluate(model, data_loader_test, device=device, num_classes=num_classes)
161+
print(confmat)
162+
return
162163

163164
start_time = time.time()
164165
for epoch in range(args.start_epoch, args.epochs):
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

test/test_models.py

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ def get_available_video_models():
5959
"resnet101",
6060
"resnet152",
6161
"wide_resnet101_2",
62+
"deeplabv3_resnet50",
63+
"deeplabv3_resnet101",
64+
"fcn_resnet50",
65+
"fcn_resnet101",
6266
)
6367

6468

@@ -85,21 +89,53 @@ def _test_classification_model(self, name, input_shape, dev):
8589
self.assertEqual(out.shape[-1], 50)
8690

8791
def _test_segmentation_model(self, name, dev):
88-
# passing num_class equal to a number other than 1000 helps in making the test
89-
# more enforcing in nature
90-
model = models.segmentation.__dict__[name](num_classes=50, pretrained_backbone=False)
92+
set_rng_seed(0)
93+
# passing num_classes equal to a number other than 21 helps in making the test's
94+
# expected file size smaller
95+
model = models.segmentation.__dict__[name](num_classes=10, pretrained_backbone=False)
9196
model.eval().to(device=dev)
92-
input_shape = (1, 3, 300, 300)
97+
input_shape = (1, 3, 32, 32)
9398
# RNG always on CPU, to ensure x in cuda tests is bitwise identical to x in cpu tests
9499
x = torch.rand(input_shape).to(device=dev)
95-
out = model(x)
96-
self.assertEqual(tuple(out["out"].shape), (1, 50, 300, 300))
100+
out = model(x)["out"]
101+
102+
def check_out(out):
103+
prec = 0.01
104+
strip_suffix = f"_{dev}"
105+
try:
106+
# We first try to assert the entire output if possible. This is not
107+
# only the best way to assert results but also handles the cases
108+
# where we need to create a new expected result.
109+
self.assertExpected(out.cpu(), prec=prec, strip_suffix=strip_suffix)
110+
except AssertionError:
111+
# Unfortunately some segmentation models are flaky with autocast
112+
# so instead of validating the probability scores, check that the class
113+
# predictions match.
114+
expected_file = self._get_expected_file(strip_suffix=strip_suffix)
115+
expected = torch.load(expected_file)
116+
self.assertEqual(out.argmax(dim=1), expected.argmax(dim=1), prec=prec)
117+
return False # Partial validation performed
118+
119+
return True # Full validation performed
120+
121+
full_validation = check_out(out)
122+
97123
self.check_jit_scriptable(model, (x,), unwrapper=script_model_unwrapper.get(name, None))
98124

99125
if dev == torch.device("cuda"):
100126
with torch.cuda.amp.autocast():
101-
out = model(x)
102-
self.assertEqual(tuple(out["out"].shape), (1, 50, 300, 300))
127+
out = model(x)["out"]
128+
# See autocast_flaky_numerics comment at top of file.
129+
if name not in autocast_flaky_numerics:
130+
full_validation &= check_out(out)
131+
132+
if not full_validation:
133+
msg = "The output of {} could only be partially validated. " \
134+
"This is likely due to unit-test flakiness, but you may " \
135+
"want to do additional manual checks if you made " \
136+
"significant changes to the codebase.".format(self._testMethodName)
137+
warnings.warn(msg, RuntimeWarning)
138+
raise unittest.SkipTest(msg)
103139

104140
def _test_detection_model(self, name, dev):
105141
set_rng_seed(0)

0 commit comments

Comments
 (0)