alias yolo_loss & yolo_box to paddle.vision. (#28520)

* alias yolo_loss & decode_yolo_box to paddle.vision. test=develop
musl/disable_test_yolov3_temporarily
Kaipeng Deng 5 years ago committed by GitHub
parent 4ceedec33d
commit f4c894a693
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -33,6 +33,7 @@ import six
import numpy as np
from functools import reduce
from ..data_feeder import convert_dtype, check_variable_and_dtype, check_type, check_dtype
from paddle.utils import deprecated
__all__ = [
'prior_box',
@ -998,6 +999,7 @@ def polygon_box_transform(input, name=None):
return output
@deprecated(since="2.0.0", update_to="paddle.vision.ops.yolo_loss")
@templatedoc(op_type="yolov3_loss")
def yolov3_loss(x,
gt_box,
@ -1127,6 +1129,7 @@ def yolov3_loss(x,
return loss
@deprecated(since="2.0.0", update_to="paddle.vision.ops.yolo_box")
@templatedoc(op_type="yolo_box")
def yolo_box(x,
img_size,

@ -18,6 +18,7 @@ import unittest
import numpy as np
from op_test import OpTest
import paddle
from paddle.fluid import core
@ -151,5 +152,44 @@ class TestYoloBoxOpScaleXY(TestYoloBoxOp):
self.scale_x_y = 1.2
class TestYoloBoxDygraph(unittest.TestCase):
def test_dygraph(self):
paddle.disable_static()
x = np.random.random([2, 14, 8, 8]).astype('float32')
img_size = np.ones((2, 2)).astype('int32')
x = paddle.to_tensor(x)
img_size = paddle.to_tensor(img_size)
boxes, scores = paddle.vision.ops.yolo_box(
x,
img_size=img_size,
anchors=[10, 13, 16, 30],
class_num=2,
conf_thresh=0.01,
downsample_ratio=8,
clip_bbox=True,
scale_x_y=1.)
assert boxes is not None and scores is not None
paddle.enable_static()
class TestYoloBoxStatic(unittest.TestCase):
def test_static(self):
x = paddle.static.data('x', [2, 14, 8, 8], 'float32')
img_size = paddle.static.data('img_size', [2, 2], 'int32')
boxes, scores = paddle.vision.ops.yolo_box(
x,
img_size=img_size,
anchors=[10, 13, 16, 30],
class_num=2,
conf_thresh=0.01,
downsample_ratio=8,
clip_bbox=True,
scale_x_y=1.)
assert boxes is not None and scores is not None
if __name__ == "__main__":
unittest.main()

@ -20,6 +20,7 @@ from scipy.special import logit
from scipy.special import expit
from op_test import OpTest
import paddle
from paddle.fluid import core
@ -281,5 +282,66 @@ class TestYolov3LossWithScaleXY(TestYolov3LossOp):
self.scale_x_y = 1.2
class TestYolov3LossDygraph(unittest.TestCase):
def test_dygraph(self):
paddle.disable_static()
x = np.random.random([2, 14, 8, 8]).astype('float32')
gt_box = np.random.random([2, 10, 4]).astype('float32')
gt_label = np.random.random([2, 10]).astype('int32')
x = paddle.to_tensor(x)
gt_box = paddle.to_tensor(gt_box)
gt_label = paddle.to_tensor(gt_label)
loss = paddle.vision.ops.yolo_loss(
x,
gt_box=gt_box,
gt_label=gt_label,
anchors=[10, 13, 16, 30],
anchor_mask=[0, 1],
class_num=2,
ignore_thresh=0.7,
downsample_ratio=8,
use_label_smooth=True,
scale_x_y=1.)
assert loss is not None
paddle.enable_static()
class TestYolov3LossStatic(unittest.TestCase):
def test_static(self):
x = paddle.static.data('x', [2, 14, 8, 8], 'float32')
gt_box = paddle.static.data('gt_box', [2, 10, 4], 'float32')
gt_label = paddle.static.data('gt_label', [2, 10], 'int32')
gt_score = paddle.static.data('gt_score', [2, 10], 'float32')
loss = paddle.vision.ops.yolo_loss(
x,
gt_box=gt_box,
gt_label=gt_label,
anchors=[10, 13, 16, 30],
anchor_mask=[0, 1],
class_num=2,
ignore_thresh=0.7,
downsample_ratio=8,
gt_score=gt_score,
use_label_smooth=True,
scale_x_y=1.)
assert loss is not None
loss = paddle.vision.ops.yolo_loss(
x,
gt_box=gt_box,
gt_label=gt_label,
anchors=[10, 13, 16, 30],
anchor_mask=[0, 1],
class_num=2,
ignore_thresh=0.7,
downsample_ratio=8,
use_label_smooth=True,
scale_x_y=1.)
assert loss is not None
if __name__ == "__main__":
unittest.main()

@ -24,6 +24,8 @@ from .datasets import *
from . import image
from .image import *
from . import ops
__all__ = models.__all__ \
+ transforms.__all__ \
+ datasets.__all__ \

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save