diff --git a/test/test_onnx.py b/test/test_onnx.py index a8f7b25fa84..54a4e385a8d 100644 --- a/test/test_onnx.py +++ b/test/test_onnx.py @@ -76,20 +76,6 @@ def to_numpy(tensor): else: raise - @unittest.skip("Disable test until Split w/ zero sizes is implemented in ORT") - def test_new_empty_tensor(self): - class Module(torch.nn.Module): - def __init__(self): - super(Module, self).__init__() - self.conv2 = ops.misc.ConvTranspose2d(16, 33, (3, 5)) - - def forward(self, input2): - return self.conv2(input2) - - input = torch.rand(0, 16, 10, 10) - test_input = torch.rand(0, 16, 20, 20) - self.run_model(Module(), [(input, ), (test_input,)], do_constant_folding=False) - def test_nms(self): boxes = torch.rand(5, 4) boxes[:, 2:] += torch.rand(5, 2) diff --git a/test/test_ops.py b/test/test_ops.py index 68e6a5d2825..1a83b4cf246 100644 --- a/test/test_ops.py +++ b/test/test_ops.py @@ -449,15 +449,6 @@ def test_autocast(self): self.test_nms_cuda(dtype=dtype) -class NewEmptyTensorTester(unittest.TestCase): - def test_new_empty_tensor(self): - input = torch.tensor([2., 2.], requires_grad=True) - new_shape = [3, 3] - out = torch.ops.torchvision._new_empty_tensor_op(input, new_shape) - assert out.size() == torch.Size([3, 3]) - assert out.dtype == input.dtype - - class DeformConvTester(OpTester, unittest.TestCase): def expected_fn(self, x, weight, offset, mask, bias, stride=1, padding=0, dilation=1): stride_h, stride_w = _pair(stride) diff --git a/torchvision/csrc/ops/new_empty_tensor_op.cpp b/torchvision/csrc/ops/new_empty_tensor_op.cpp deleted file mode 100644 index e2de544be0a..00000000000 --- a/torchvision/csrc/ops/new_empty_tensor_op.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "new_empty_tensor_op.h" - -#include -#include - -namespace vision { -namespace ops { - -namespace { - -class NewEmptyTensorOp : public torch::autograd::Function { - public: - static torch::autograd::variable_list forward( - torch::autograd::AutogradContext* ctx, - const torch::autograd::Variable& input, - const c10::List& new_shape) { - ctx->saved_data["shape"] = input.sizes(); - std::vector shape(new_shape.begin(), new_shape.end()); - return {input.new_empty(shape, at::TensorOptions())}; - } - - static torch::autograd::variable_list backward( - torch::autograd::AutogradContext* ctx, - const torch::autograd::variable_list& grad_output) { - // Use data saved in forward - auto shape = ctx->saved_data["shape"].toIntList(); - auto out = forward(ctx, grad_output[0], shape); - return {out[0], at::Tensor()}; - } -}; - -} // namespace - -at::Tensor new_empty_tensor( - const at::Tensor& input, - const c10::List& shape) { - return NewEmptyTensorOp::apply(input, shape)[0]; -} - -TORCH_LIBRARY_FRAGMENT(torchvision, m) { - m.def("_new_empty_tensor_op", &new_empty_tensor); -} - -} // namespace ops -} // namespace vision diff --git a/torchvision/csrc/ops/new_empty_tensor_op.h b/torchvision/csrc/ops/new_empty_tensor_op.h deleted file mode 100644 index 6f22cfecda9..00000000000 --- a/torchvision/csrc/ops/new_empty_tensor_op.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include -#include "../macros.h" - -namespace vision { -namespace ops { - -VISION_API at::Tensor new_empty_tensor( - const at::Tensor& input, - const c10::List& shape); - -} // namespace ops -} // namespace vision diff --git a/torchvision/ops/__init__.py b/torchvision/ops/__init__.py index bd82a0d5ed9..0ec189dbc2a 100644 --- a/torchvision/ops/__init__.py +++ b/torchvision/ops/__init__.py @@ -1,6 +1,5 @@ from .boxes import nms, batched_nms, remove_small_boxes, clip_boxes_to_image, box_area, box_iou, generalized_box_iou from .boxes import box_convert -from .new_empty_tensor import _new_empty_tensor from .deform_conv import deform_conv2d, DeformConv2d from .roi_align import roi_align, RoIAlign from .roi_pool import roi_pool, RoIPool @@ -19,7 +18,7 @@ 'deform_conv2d', 'DeformConv2d', 'nms', 'batched_nms', 'remove_small_boxes', 'clip_boxes_to_image', 'box_convert', 'box_area', 'box_iou', 'generalized_box_iou', 'roi_align', 'RoIAlign', 'roi_pool', - 'RoIPool', '_new_empty_tensor', 'ps_roi_align', 'PSRoIAlign', 'ps_roi_pool', + 'RoIPool', 'ps_roi_align', 'PSRoIAlign', 'ps_roi_pool', 'PSRoIPool', 'MultiScaleRoIAlign', 'FeaturePyramidNetwork', 'sigmoid_focal_loss' ] diff --git a/torchvision/ops/_register_onnx_ops.py b/torchvision/ops/_register_onnx_ops.py index 22240b8b2b7..02013844aac 100644 --- a/torchvision/ops/_register_onnx_ops.py +++ b/torchvision/ops/_register_onnx_ops.py @@ -38,18 +38,7 @@ def roi_pool(g, input, rois, spatial_scale, pooled_height, pooled_width): pooled_shape_i=(pooled_height, pooled_width), spatial_scale_f=spatial_scale) return roi_pool, None - @parse_args('v', 'is') - def new_empty_tensor_op(g, input, shape): - dtype = input.type().scalarType() - if dtype is None: - dtype = 'Float' - dtype = scalar_type_to_onnx.index(cast_pytorch_to_onnx[dtype]) - shape = g.op("Constant", value_t=torch.tensor(shape)) - return g.op("ConstantOfShape", shape, - value_t=torch.tensor([0], dtype=scalar_type_to_pytorch_type[dtype])) - from torch.onnx import register_custom_op_symbolic register_custom_op_symbolic('torchvision::nms', symbolic_multi_label_nms, _onnx_opset_version) register_custom_op_symbolic('torchvision::roi_align', roi_align, _onnx_opset_version) register_custom_op_symbolic('torchvision::roi_pool', roi_pool, _onnx_opset_version) - register_custom_op_symbolic('torchvision::_new_empty_tensor_op', new_empty_tensor_op, _onnx_opset_version) diff --git a/torchvision/ops/new_empty_tensor.py b/torchvision/ops/new_empty_tensor.py deleted file mode 100644 index e964e7a7e15..00000000000 --- a/torchvision/ops/new_empty_tensor.py +++ /dev/null @@ -1,15 +0,0 @@ -import torch -from torch.jit.annotations import List -from torch import Tensor - - -def _new_empty_tensor(x: Tensor, shape: List[int]) -> Tensor: - """ - Arguments: - input (Tensor): input tensor - shape List[int]: the new empty tensor shape - - Returns: - output (Tensor) - """ - return torch.ops.torchvision._new_empty_tensor_op(x, shape)