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]))) 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/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..5be5cd81853 100644 --- a/torchvision/models/detection/roi_heads.py +++ b/torchvision/models/detection/roi_heads.py @@ -266,7 +266,7 @@ def heatmaps_to_keypoints(maps, rois): pos = roi_map.reshape(num_keypoints, -1).argmax(dim=1) x_int = pos % w - y_int = (pos - x_int) // 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 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)