batch_norm 层使用报错 Enforce failed. Expected ctx->GetInputDim("Scale")[0] == C, but received ctx->GetInputDim("Scale")[0]:0 != C:1
Created by: snowsteper
代码:
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
def nets():
x = fluid.layers.data(name='x', shape=[1], dtype='float32', lod_level=1)
re_shp = fluid.layers.reshape(x, shape=[-1, 1, 1, 3])
bat_nom = fluid.layers.batch_norm(re_shp, param_attr=fluid.param_attr.ParamAttr(initializer=fluid.initializer.ConstantInitializer(value=1.0)))
return re_shp, bat_nom
re_shp, bat_nom = nets()
a = fluid.create_lod_tensor(np.array([[1.1, 1.1, 1.1],[2.2, 2.2, 2.2],[3.3, 3.3, 3.3],[4.4, 4.4, 4.4]]).astype('float32'), [[1,1,1,1]], place)
fetch_vars = [re_shp, bat_nom]
results = exe.run(fluid.default_main_program(),
feed={'x':a},
fetch_list=fetch_vars,return_numpy=False)
print results
print np.array(results[0])
得到报错信息 paddle.fluid.core.EnforceNotMet: Enforce failed. Expected ctx->GetInputDim("Scale")[0] == C, but received ctx->GetInputDim("Scale")[0]:0 != C:1. at [/paddle/paddle/fluid/operators/batch_norm_op.cc:60]