for frame in traceback.extract_stack():
InvalidArgumentError: The input of Op(Conv) should be a 4-D or 5-D Tensor. But received: input's dimension is 1, input's shape is [16].
[Hint: Expected in_dims.size() == 4 || in_dims.size() == 5 == true, but received in_dims.size() == 4 || in_dims.size() == 5:0 != true:1.] (at /paddle/paddle/fluid/operators/conv_op.cc:74)
[operator < conv2d > error]
代码是
import paddle
import paddleslim as slim
import numpy as np
paddle.enable_static()
USE_GPU = True
model = slim.models.MobileNet()
train_program = paddle.static.Program()
startup = paddle.static.Program()
with paddle.static.program_guard(train_program, startup):
image = paddle.static.data(
name='image', shape=[None, 1, 28, 28], dtype='float32')
label = paddle.static.data(name='label', shape=[None, 1], dtype='int64')
gt = paddle.reshape(label, [-1, 1])
out = model.net(input=image, class_dim=10)
cost = paddle.nn.functional.loss.cross_entropy(input=out, label=gt)
avg_cost = paddle.mean(x=cost)
acc_top1 = paddle.metric.accuracy(input=out, label=gt, k=1)
acc_top5 = paddle.metric.accuracy(input=out, label=gt, k=5)
opt = paddle.optimizer.Momentum(0.01, 0.9)
opt.minimize(avg_cost)
place = paddle.CUDAPlace(0) if USE_GPU else paddle.CPUPlace()
exe = paddle.static.Executor(place)
exe.run(startup)
val_program = train_program.clone(for_test=True)
slim.quant.quant_post_static(
executor=exe,
model_dir='./mod',
quantize_model_path='./model',
sample_generator=paddle.dataset.mnist.test(),
model_filename='model.pdmodel',
params_filename='model.pdiparams',
batch_nums=10)