未验证 提交 2445fef3 编写于 作者: R ruri 提交者: GitHub

Fix density sample (#21506)

上级 6ebf0f47
...@@ -1858,14 +1858,14 @@ def density_prior_box(input, ...@@ -1858,14 +1858,14 @@ def density_prior_box(input,
.. code-block:: python .. code-block:: python
#declarative mode #declarative mode
import paddle.fluid as fluid import paddle.fluid as fluid
import numpy as np import numpy as np
input = fluid.data(name="input", shape=[None,3,6,9]) input = fluid.data(name="input", shape=[None,3,6,9])
image = fluid.data(name="image", shape=[None,3,9,12]) image = fluid.data(name="image", shape=[None,3,9,12])
box, var = fluid.layers.density_prior_box( box, var = fluid.layers.density_prior_box(
input=input, input=input,
image=image, image=image,
densities=[4, 2, 1], densities=[4, 2, 1],
...@@ -1874,45 +1874,45 @@ def density_prior_box(input, ...@@ -1874,45 +1874,45 @@ def density_prior_box(input,
clip=True, clip=True,
flatten_to_2d=True) flatten_to_2d=True)
place = fluid.CPUPlace() place = fluid.CPUPlace()
exe = fluid.Executor(place) exe = fluid.Executor(place)
exe.run(fluid.default_startup_program()) 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")
box_out, var_out = exe.run( # prepare a batch of data
fluid.default_main_program(), 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, feed={"input":input_data,
"image":image_data}, "image":image_data},
fetch_list=[box,var], fetch_list=[box,var],
return_numpy=True) 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: #imperative mode
input = dg.to_variable(input_data) import paddle.fluid.dygraph as dg
image = dg.to_variable(image_data)
box, var = fluid.layers.density_prior_box( with dg.guard(place) as g:
input=input, input = dg.to_variable(input_data)
image=image, image = dg.to_variable(image_data)
densities=[4, 2, 1], box, var = fluid.layers.density_prior_box(
fixed_sizes=[32.0, 64.0, 128.0], input=input,
fixed_ratios=[1.], image=image,
clip=True) densities=[4, 2, 1],
fixed_sizes=[32.0, 64.0, 128.0],
print(box.shape) fixed_ratios=[1.],
# [6L, 9L, 21L, 4L] clip=True)
print(var.shape)
# [6L, 9L, 21L, 4L] # print(box.shape)
# [6L, 9L, 21L, 4L]
# print(var.shape)
# [6L, 9L, 21L, 4L]
""" """
helper = LayerHelper("density_prior_box", **locals()) helper = LayerHelper("density_prior_box", **locals())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册