官方文档:https://www.paddlepaddle.org.cn/documentation/docs/zh/api_cn/layers_cn/conv2d_cn.html
示例:
import paddle.fluid as fluid
import numpy as np
data = fluid.data(name='data', shape=[-1, 3, 4, 4], dtype='float32')
param_attr = fluid.ParamAttr(name='conv2d.weight', \
initializer=fluid.initializer.Xavier(uniform=False), \
learning_rate=0.001)
res = fluid.layers.conv2d(input=data, num_filters=5, filter_size=3, act="relu", param_attr=param_attr)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
x = np.random.rand(2, 3, 4, 4).astype("float32")
print(x)
output = exe.run(feed={"data": x}, fetch_list=[res])
print(output)
结果:
[[[[0.5087496 0.7041155 0.803204 0.7463352 ]
[0.7735792 0.6693252 0.9050084 0.66902024]
[0.61370426 0.8947696 0.10490164 0.23426855]
[0.03776363 0.9701155 0.16354166 0.03877337]]
[[0.43141097 0.4325962 0.7552632 0.4175699 ]
[0.82959193 0.29775426 0.11804868 0.98603547]
[0.47543335 0.67431146 0.33452708 0.30459923]
[0.8601018 0.4596342 0.73562324 0.02880552]]
[[0.6077263 0.2229377 0.08738393 0.3110199 ]
[0.9336773 0.16735514 0.38200915 0.07737117]
[0.37466565 0.91293067 0.83331645 0.6757968 ]
[0.89134467 0.39544025 0.74072474 0.9375356 ]]]
[[[0.23173703 0.39239067 0.8614188 0.6754454 ]
[0.9554946 0.8584714 0.2632353 0.2825664 ]
[0.21315546 0.8459132 0.2556982 0.26026046]
[0.91332084 0.45665127 0.91489136 0.04556087]]
[[0.22302757 0.26607528 0.7861403 0.87475955]
[0.90069216 0.5976185 0.32480258 0.12278948]
[0.55071807 0.7877879 0.37637177 0.00199596]
[0.2452881 0.9161675 0.5198959 0.81285113]]
[[0.8335489 0.03425184 0.6305808 0.8300988 ]
[0.20777652 0.6059211 0.93811506 0.84582675]
[0.41290218 0.2219187 0.3509429 0.0840489 ]
[0.9862689 0.31428847 0.29119077 0.02785959]]]]
[array([[[[0. , 0. ],
[0. , 0. ]],
[[0.41131574, 0.31667483],
[0.58022946, 0.53619456]],
[[0. , 0. ],
[0. , 0. ]],
[[0.6091093 , 0.5029663 ],
[0.5317466 , 0.56629765]],
[[0. , 0. ],
[0. , 0. ]]],
[[[0. , 0. ],
[0. , 0. ]],
[[0.42338365, 0.20286646],
[0. , 0. ]],
[[0. , 0. ],
[0. , 0. ]],
[[0.09722605, 0.2907472 ],
[0.20087919, 0.14951111]],
[[0. , 0. ],
[0. , 0. ]]]], dtype=float32)]