Skip to content

Commit

Permalink
Fixed floor_divide deprecation warnings seen in pytest output (#3672)
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhat00155 authored Apr 16, 2021
1 parent 3926c90 commit 9778d26
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions test/test_datasets_samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])))
Expand All @@ -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])))
Expand All @@ -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])))
Expand Down
3 changes: 2 additions & 1 deletion torchvision/datasets/celeba.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/detection/retinanet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/detection/roi_heads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions torchvision/transforms/functional_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9778d26

Please sign in to comment.