Uses floor division operator for floor division
Summary:
Performing floor division using torch.div is no longer supported. This replaces div with floor division. See T68415128 for how this was reported.
Created from Diffusion's 'Open in Editor' feature.
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
+import torch
from torch.nn import functional as F
from detectron2.layers import paste_masks_in_image
@@ -25,7 +26,22 @@ def detector_postprocess(results, output_height, output_width, mask_threshold=0.
Returns:
Instances: the resized output from the model, based on the output resolution
"""
- scale_x, scale_y = (output_width / results.image_size[1], output_height / results.image_size[0])
+
+ # Converts integer tensors to float temporaries
+ # to ensure true division is performed when
+ # computing scale_x and scale_y.
+ if isinstance(output_width, torch.Tensor):
+ output_width_tmp = output_width.float()
+ else:
+ output_width_tmp = output_width
+
+ if isinstance(output_height, torch.Tensor):
+ output_height_tmp = output_height.float()
+ else:
+ output_height_tmp = output_height
+
+ scale_x, scale_y = (output_width_tmp / results.image_size[1],
+ output_height_tmp / results.image_size[0])
results = Instances((output_height, output_width), **results.get_fields())
if results.has("pred_boxes"):
