diff --git a/PaddleCV/PaddleDetection/slim/quantization/README.md b/PaddleCV/PaddleDetection/slim/quantization/README.md index ad178fd9e12fb6276e5c453fc129b24f285ce698..fe69186aef1896ea12f5a22edbb576e743cec875 100644 --- a/PaddleCV/PaddleDetection/slim/quantization/README.md +++ b/PaddleCV/PaddleDetection/slim/quantization/README.md @@ -44,7 +44,6 @@ step1: 设置gpu卡 export CUDA_VISIBLE_DEVICES=0 ``` step2: 开始训练 -``` 使用PaddleDetection提供的配置文件在用8卡进行训练: ``` diff --git a/PaddleCV/PaddleDetection/slim/quantization/compress.py b/PaddleCV/PaddleDetection/slim/quantization/compress.py index 7c4dbead703cf0d05a58e233d411acde985c6788..6e3156ac3902de572f37c14989a0b44226e9c8e9 100644 --- a/PaddleCV/PaddleDetection/slim/quantization/compress.py +++ b/PaddleCV/PaddleDetection/slim/quantization/compress.py @@ -239,6 +239,7 @@ def main(): eval_feed_list=test_feed, eval_func={'map': eval_func}, eval_fetch_list=[eval_fetch_list[0]], + prune_infer_model=[["image", "im_size"],["multiclass_nms_0.tmp_0"]], train_optimizer=None) com.config(FLAGS.slim_file) com.run() diff --git a/PaddleCV/PaddleDetection/slim/quantization/freeze.py b/PaddleCV/PaddleDetection/slim/quantization/freeze.py index 04271a4f2c691782654ce948466438246a4d3f55..85906fa8231f400a839b48647877c4791799351f 100644 --- a/PaddleCV/PaddleDetection/slim/quantization/freeze.py +++ b/PaddleCV/PaddleDetection/slim/quantization/freeze.py @@ -142,7 +142,7 @@ def main(): assert os.path.exists(FLAGS.model_path) infer_prog, feed_names, fetch_targets = fluid.io.load_inference_model( dirname=FLAGS.model_path, executor=exe, - model_filename='__model__', + model_filename='__model__.infer', params_filename='__params__') eval_keys = ['bbox', 'gt_box', 'gt_label', 'is_difficult'] diff --git a/PaddleSlim/classification/quantization/compress.py b/PaddleSlim/classification/quantization/compress.py index 4894684fabf3feed3b0ab179861ec921fd56884b..41b767885a1a0ce435df282126d7d78c33a66014 100644 --- a/PaddleSlim/classification/quantization/compress.py +++ b/PaddleSlim/classification/quantization/compress.py @@ -95,6 +95,7 @@ def compress(args): eval_fetch_list=val_fetch_list, teacher_programs=[], train_optimizer=opt, + prune_infer_model=[[image.name], [out.name]], distiller_optimizer=None) com_pass.config(args.config_file) com_pass.run() diff --git a/PaddleSlim/classification/quantization/freeze.py b/PaddleSlim/classification/quantization/freeze.py index 396875c7e1a54b56b5c985952ab4630c37824fc3..6e97e0243510facf477f70a1ea482ba1251e8013 100644 --- a/PaddleSlim/classification/quantization/freeze.py +++ b/PaddleSlim/classification/quantization/freeze.py @@ -53,20 +53,32 @@ def eval(args): val_program, feed_names, fetch_targets = fluid.io.load_inference_model(args.model_path, exe, - model_filename="__model__", + model_filename="__model__.infer", params_filename="__params__") val_reader = paddle.batch(reader.val(), batch_size=128) feeder = fluid.DataFeeder(place=place, feed_list=feed_names, program=val_program) results=[] for batch_id, data in enumerate(val_reader()): + image = [[d[0]] for d in data] + label = [[d[1]] for d in data] + feed_data = feeder.feed(image) + pred = exe.run(val_program, + feed=feed_data, + fetch_list=fetch_targets) + pred = np.array(pred[0]) + label = np.array(label) + sort_array = pred.argsort(axis=1) + top_1_pred = sort_array[:, -1:][:, ::-1] + top_1 = np.mean(label == top_1_pred) + top_5_pred = sort_array[:, -5:][:, ::-1] + acc_num = 0 + for i in range(len(label)): + if label[i][0] in top_5_pred[i]: + acc_num += 1 + top_5 = acc_num / len(label) + results.append([top_1, top_5]) - # top1_acc, top5_acc - result = exe.run(val_program, - feed=feeder.feed(data), - fetch_list=fetch_targets) - result = [np.mean(r) for r in result] - results.append(result) result = np.mean(np.array(results), axis=0) print("top1_acc/top5_acc= {}".format(result)) sys.stdout.flush()