From 2445fef38642183297a422ae1d33c7ff0fdbcef1 Mon Sep 17 00:00:00 2001 From: ruri Date: Tue, 3 Dec 2019 15:41:54 +0800 Subject: [PATCH] Fix density sample (#21506) --- python/paddle/fluid/layers/detection.py | 76 ++++++++++++------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/python/paddle/fluid/layers/detection.py b/python/paddle/fluid/layers/detection.py index 25bada5cb39..226ab2c9293 100644 --- a/python/paddle/fluid/layers/detection.py +++ b/python/paddle/fluid/layers/detection.py @@ -1858,14 +1858,14 @@ def density_prior_box(input, .. code-block:: python - #declarative mode + #declarative mode - import paddle.fluid as fluid - import numpy as np + import paddle.fluid as fluid + import numpy as np - input = fluid.data(name="input", shape=[None,3,6,9]) - image = fluid.data(name="image", shape=[None,3,9,12]) - box, var = fluid.layers.density_prior_box( + input = fluid.data(name="input", shape=[None,3,6,9]) + image = fluid.data(name="image", shape=[None,3,9,12]) + box, var = fluid.layers.density_prior_box( input=input, image=image, densities=[4, 2, 1], @@ -1874,45 +1874,45 @@ def density_prior_box(input, clip=True, flatten_to_2d=True) - place = fluid.CPUPlace() - exe = fluid.Executor(place) - exe.run(fluid.default_startup_program()) - - # prepare a batch of data - input_data = np.random.rand(1,3,6,9).astype("float32") - image_data = np.random.rand(1,3,9,12).astype("float32") + place = fluid.CPUPlace() + exe = fluid.Executor(place) + exe.run(fluid.default_startup_program()) - box_out, var_out = exe.run( - fluid.default_main_program(), + # prepare a batch of data + input_data = np.random.rand(1,3,6,9).astype("float32") + image_data = np.random.rand(1,3,9,12).astype("float32") + + box_out, var_out = exe.run( + fluid.default_main_program(), feed={"input":input_data, - "image":image_data}, + "image":image_data}, fetch_list=[box,var], return_numpy=True) - - print(mask_out.shape) - # (1134, 4) - print(z_out.shape) - # (1134, 4) + # print(box_out.shape) + # (1134, 4) + # print(var_out.shape) + # (1134, 4) - #imperative mode - import paddle.fluid.dygraph as dg - with dg.guard(place) as g: - input = dg.to_variable(input_data) - image = dg.to_variable(image_data) - box, var = fluid.layers.density_prior_box( - input=input, - image=image, - densities=[4, 2, 1], - fixed_sizes=[32.0, 64.0, 128.0], - fixed_ratios=[1.], - clip=True) - - print(box.shape) - # [6L, 9L, 21L, 4L] - print(var.shape) - # [6L, 9L, 21L, 4L] + #imperative mode + import paddle.fluid.dygraph as dg + + with dg.guard(place) as g: + input = dg.to_variable(input_data) + image = dg.to_variable(image_data) + box, var = fluid.layers.density_prior_box( + input=input, + image=image, + densities=[4, 2, 1], + fixed_sizes=[32.0, 64.0, 128.0], + fixed_ratios=[1.], + clip=True) + + # print(box.shape) + # [6L, 9L, 21L, 4L] + # print(var.shape) + # [6L, 9L, 21L, 4L] """ helper = LayerHelper("density_prior_box", **locals()) -- GitLab