diff --git a/paddle/operators/iou_similarity_op.cc b/paddle/operators/iou_similarity_op.cc index 49e54a1a53c4df7450ec6159d7d58938593a2f06..6c1b99b46f288b9dea94727b23a2342137a33d27 100755 --- a/paddle/operators/iou_similarity_op.cc +++ b/paddle/operators/iou_similarity_op.cc @@ -44,11 +44,14 @@ class IOUSimilarityOpMaker : public framework::OpProtoAndCheckerMaker { IOUSimilarityOpMaker(OpProto *proto, OpAttrChecker *op_checker) : OpProtoAndCheckerMaker(proto, op_checker) { AddInput("X", - "(Tensor, default Tensor) " - "Box list X holds N boxes, each box is " - "represented as [xmin, ymin, xmax, ymax], the shape of X is [N, " - "4]. [xmin, ymin] is the lower left coordinate of the box, and " - "[xmax, ymax] is the right upper coordinate of the box."); + "(LoDTensor, default LoDTensor) " + "Box list X is a 2-D LoDTensor with shape [N, 4] holds N boxes, " + "each box is represented as [xmin, ymin, xmax, ymax], " + "the shape of X is [N, 4]. [xmin, ymin] is the lower left " + "coordinate of the box, and [xmax, ymax] is the right upper " + "coordinate of the box.This tensor can contain LoD information " + "to represent a batch of inputs. One instance of this batch can " + "contain different numbers of entities."); AddInput("Y", "(Tensor, default Tensor) " "Box list Y holds M boxes, each box is " @@ -56,14 +59,23 @@ class IOUSimilarityOpMaker : public framework::OpProtoAndCheckerMaker { "4]. [xmin, ymin] is the lower left coordinate of the box, and " "[xmax, ymax] is the right upper coordinate of the box."); - AddOutput( - "Out", - "(Tensor) The output of iou_similarity op, a tensor with shape [N, M] " - "representing pairwise iou scores."); + AddOutput("Out", + "(LoDTensor or Tensor, the lod is same as input X) The output of " + "iou_similarity op, a tensor with shape [N, M] " + "representing pairwise iou scores."); AddComment(R"DOC( IOU Similarity Operator. Computes intersection-over-union (IOU) between two box lists. + Box list 'X' should be a LoDTensor and 'Y' is a common Tensor, + boxes in 'Y' are shared by all input images. + Given two box A and B, the calculation of IOU is as follows: + +$$ +IOU(A, B) = +\frac{area(A\cap B)}{area(A)+area(B)-area(A\cap B)} +$$ + )DOC"); } }; diff --git a/paddle/operators/iou_similarity_op.cu b/paddle/operators/iou_similarity_op.cu index 526edaefeea98b0760832c6b24fcb2d38b3aa00e..fa5052624618c35875b241419946f69b776c81d4 100755 --- a/paddle/operators/iou_similarity_op.cu +++ b/paddle/operators/iou_similarity_op.cu @@ -12,7 +12,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#define EIGEN_USE_GPU #include "paddle/operators/iou_similarity_op.h" namespace ops = paddle::operators; diff --git a/paddle/operators/iou_similarity_op.h b/paddle/operators/iou_similarity_op.h index fa1b60ae34eeee2cf534607606568f527f1bd67b..f42e05b078b13f9b2f58b3bd544ba4bd881940da 100644 --- a/paddle/operators/iou_similarity_op.h +++ b/paddle/operators/iou_similarity_op.h @@ -71,9 +71,9 @@ template class IOUSimilarityKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { - const framework::Tensor* in_x = ctx.Input("X"); + const framework::LoDTensor* in_x = ctx.Input("X"); const framework::Tensor* in_y = ctx.Input("Y"); - framework::Tensor* out = ctx.Output("Out"); + framework::LoDTensor* out = ctx.Output("Out"); int x_n = in_x->dims()[0]; int y_n = in_y->dims()[0]; @@ -83,6 +83,8 @@ class IOUSimilarityKernel : public framework::OpKernel { platform::ForRange for_range( static_cast(ctx.device_context()), x_n); for_range(functor); + + out->set_lod(in_x->lod()); } }; // namespace operators diff --git a/python/paddle/v2/fluid/tests/test_iou_similarity_op.py b/python/paddle/v2/fluid/tests/test_iou_similarity_op.py index 694da618628f6f8986a50d62e8c4b144f298d8bd..128f2e4977195a563efcd26364cc6261da2dd685 100755 --- a/python/paddle/v2/fluid/tests/test_iou_similarity_op.py +++ b/python/paddle/v2/fluid/tests/test_iou_similarity_op.py @@ -38,5 +38,18 @@ class TestIOUSimilarityOp(OpTest): self.outputs = {'Out': self.output} +class TestIOUSimilarityOpWithLoD(TestIOUSimilarityOp): + def test_check_output(self): + self.check_output() + + def setUp(self): + super(TestIOUSimilarityOpWithLoD, self).setUp() + self.boxes1_lod = [[0, 1, 2]] + self.output_lod = [[0, 1, 2]] + + self.inputs = {'X': (self.boxes1, self.boxes1_lod), 'Y': self.boxes2} + self.outputs = {'Out': (self.output, self.output_lod)} + + if __name__ == '__main__': unittest.main()