Unverified Commit 9778d267 authored by Prabhat Roy's avatar Prabhat Roy Committed by GitHub
Browse files

Fixed floor_divide deprecation warnings seen in pytest output (#3672)

parent 3926c905
......@@ -45,7 +45,7 @@ class Tester(unittest.TestCase):
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 @@ class Tester(unittest.TestCase):
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 @@ class Tester(unittest.TestCase):
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])))
......
......@@ -104,7 +104,8 @@ class CelebA(VisionDataset):
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(
......
......@@ -428,7 +428,7 @@ class RetinaNet(nn.Module):
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],
......
......@@ -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
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment