From ca288ef581a5d2a990270a9bcdee6fe1e960d00b Mon Sep 17 00:00:00 2001 From: Prabhat Roy Date: Wed, 14 Apr 2021 22:36:00 +0100 Subject: [PATCH 1/4] Fixed floor_divide deprecation warnings given by ============================= test session starts ============================== platform darwin -- Python 3.7.5, pytest-6.2.2, py-1.10.0, pluggy-0.13.1 rootdir: /Users/prabhatroy/Documents/pytorch/repos/vision collected 0 items ============================ no tests ran in 0.00s ============================= --- torchvision/models/detection/retinanet.py | 2 +- torchvision/models/detection/roi_heads.py | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/torchvision/models/detection/retinanet.py b/torchvision/models/detection/retinanet.py index c6fe8856a01..43b0d14dd5e 100644 --- a/torchvision/models/detection/retinanet.py +++ b/torchvision/models/detection/retinanet.py @@ -428,7 +428,7 @@ def postprocess_detections(self, head_outputs, anchors, image_shapes): scores_per_level, idxs = scores_per_level.topk(num_topk) topk_idxs = topk_idxs[idxs] - anchor_idxs = topk_idxs // num_classes + anchor_idxs = torch.div(topk_idxs, num_classes, rounding_mode='floor') labels_per_level = topk_idxs % num_classes boxes_per_level = self.box_coder.decode_single(box_regression_per_level[anchor_idxs], diff --git a/torchvision/models/detection/roi_heads.py b/torchvision/models/detection/roi_heads.py index ab6e87a86e0..1218b129ab7 100644 --- a/torchvision/models/detection/roi_heads.py +++ b/torchvision/models/detection/roi_heads.py @@ -261,14 +261,11 @@ def heatmaps_to_keypoints(maps, rois): height_correction = heights[i] / roi_map_height roi_map = F.interpolate( maps[i][:, None], size=(roi_map_height, roi_map_width), mode='bicubic', align_corners=False)[:, 0] - # roi_map_probs = scores_to_probs(roi_map.copy()) w = roi_map.shape[2] pos = roi_map.reshape(num_keypoints, -1).argmax(dim=1) x_int = pos % w - y_int = (pos - x_int) // w - # assert (roi_map_probs[k, y_int, x_int] == - # roi_map_probs[k, :, :].max()) + y_int = torch.div(pos - x_int, w, rounding_mode='floor') x = (x_int.float() + 0.5) * width_correction y = (y_int.float() + 0.5) * height_correction xy_preds[i, 0, :] = x + offset_x[i] From f1d9e327ab461af43f7621dd7fdb87304888b3b2 Mon Sep 17 00:00:00 2001 From: Prabhat Roy Date: Thu, 15 Apr 2021 12:19:18 +0100 Subject: [PATCH 2/4] Fixed floor_divide deprecation warning in test_datasets --- torchvision/datasets/celeba.py | 3 ++- torchvision/models/detection/roi_heads.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/torchvision/datasets/celeba.py b/torchvision/datasets/celeba.py index 5c202da05b9..56588aaef57 100644 --- a/torchvision/datasets/celeba.py +++ b/torchvision/datasets/celeba.py @@ -104,7 +104,8 @@ def __init__( self.bbox = bbox.data[mask] self.landmarks_align = landmarks_align.data[mask] self.attr = attr.data[mask] - self.attr = (self.attr + 1) // 2 # map from {-1, 1} to {0, 1} + # map from {-1, 1} to {0, 1} + self.attr = torch.div(self.attr + 1, 2, rounding_mode='floor') self.attr_names = attr.header def _load_csv( diff --git a/torchvision/models/detection/roi_heads.py b/torchvision/models/detection/roi_heads.py index 1218b129ab7..5be5cd81853 100644 --- a/torchvision/models/detection/roi_heads.py +++ b/torchvision/models/detection/roi_heads.py @@ -261,11 +261,14 @@ def heatmaps_to_keypoints(maps, rois): height_correction = heights[i] / roi_map_height roi_map = F.interpolate( maps[i][:, None], size=(roi_map_height, roi_map_width), mode='bicubic', align_corners=False)[:, 0] + # roi_map_probs = scores_to_probs(roi_map.copy()) w = roi_map.shape[2] pos = roi_map.reshape(num_keypoints, -1).argmax(dim=1) x_int = pos % w y_int = torch.div(pos - x_int, w, rounding_mode='floor') + # assert (roi_map_probs[k, y_int, x_int] == + # roi_map_probs[k, :, :].max()) x = (x_int.float() + 0.5) * width_correction y = (y_int.float() + 0.5) * height_correction xy_preds[i, 0, :] = x + offset_x[i] From 37afb85fb5c4b04dcfca0aeb31f8a654108a4f0f Mon Sep 17 00:00:00 2001 From: Prabhat Roy Date: Thu, 15 Apr 2021 13:06:17 +0100 Subject: [PATCH 3/4] Fixed floor_divide warning in test_datasets_samplers.py --- test/test_datasets_samplers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_datasets_samplers.py b/test/test_datasets_samplers.py index 87a4900489f..e76f4f9d007 100644 --- a/test/test_datasets_samplers.py +++ b/test/test_datasets_samplers.py @@ -45,7 +45,7 @@ def test_random_clip_sampler(self): sampler = RandomClipSampler(video_clips, 3) self.assertEqual(len(sampler), 3 * 3) indices = torch.tensor(list(iter(sampler))) - videos = indices // 5 + videos = torch.div(indices, 5, rounding_mode='floor') v_idxs, count = torch.unique(videos, return_counts=True) self.assertTrue(v_idxs.equal(torch.tensor([0, 1, 2]))) self.assertTrue(count.equal(torch.tensor([3, 3, 3]))) @@ -62,7 +62,7 @@ def test_random_clip_sampler_unequal(self): indices.remove(0) indices.remove(1) indices = torch.tensor(indices) - 2 - videos = indices // 5 + videos = torch.div(indices, 5, rounding_mode='floor') v_idxs, count = torch.unique(videos, return_counts=True) self.assertTrue(v_idxs.equal(torch.tensor([0, 1]))) self.assertTrue(count.equal(torch.tensor([3, 3]))) @@ -73,7 +73,7 @@ def test_uniform_clip_sampler(self): sampler = UniformClipSampler(video_clips, 3) self.assertEqual(len(sampler), 3 * 3) indices = torch.tensor(list(iter(sampler))) - videos = indices // 5 + videos = torch.div(indices, 5, rounding_mode='floor') v_idxs, count = torch.unique(videos, return_counts=True) self.assertTrue(v_idxs.equal(torch.tensor([0, 1, 2]))) self.assertTrue(count.equal(torch.tensor([3, 3, 3]))) From f16df9ade7e037618cd49885c808c44a7a15c87b Mon Sep 17 00:00:00 2001 From: Prabhat Roy Date: Thu, 15 Apr 2021 16:05:42 +0100 Subject: [PATCH 4/4] Fixed floor_divide warnings in test_transforms.py --- torchvision/transforms/functional_tensor.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/torchvision/transforms/functional_tensor.py b/torchvision/transforms/functional_tensor.py index ea96fed512f..156d49150bc 100644 --- a/torchvision/transforms/functional_tensor.py +++ b/torchvision/transforms/functional_tensor.py @@ -97,7 +97,7 @@ def convert_image_dtype(image: torch.Tensor, dtype: torch.dtype = torch.float) - # factor should be forced to int for torch jit script # otherwise factor is a float and image // factor can produce different results factor = int((input_max + 1) // (output_max + 1)) - image = image // factor + image = torch.div(image, factor, rounding_mode='floor') return image.to(dtype) else: # factor should be forced to int for torch jit script @@ -908,11 +908,13 @@ def _scale_channel(img_chan): hist = torch.bincount(img_chan.view(-1), minlength=256) nonzero_hist = hist[hist != 0] - step = nonzero_hist[:-1].sum() // 255 + step = torch.div(nonzero_hist[:-1].sum(), 255, rounding_mode='floor') if step == 0: return img_chan - lut = (torch.cumsum(hist, 0) + (step // 2)) // step + lut = torch.div( + torch.cumsum(hist, 0) + torch.div(step, 2, rounding_mode='floor'), + step, rounding_mode='floor') lut = torch.nn.functional.pad(lut, [1, 0])[:-1].clamp(0, 255) return lut[img_chan.to(torch.int64)].to(torch.uint8)