提交 db5f3295 编写于 作者: L Liufang Sang 提交者: whs

[PaddleSlim] save infer model for each epoch (#3570)

上级 4f7bf849
...@@ -44,7 +44,6 @@ step1: 设置gpu卡 ...@@ -44,7 +44,6 @@ step1: 设置gpu卡
export CUDA_VISIBLE_DEVICES=0 export CUDA_VISIBLE_DEVICES=0
``` ```
step2: 开始训练 step2: 开始训练
```
使用PaddleDetection提供的配置文件在用8卡进行训练: 使用PaddleDetection提供的配置文件在用8卡进行训练:
``` ```
......
...@@ -239,6 +239,7 @@ def main(): ...@@ -239,6 +239,7 @@ def main():
eval_feed_list=test_feed, eval_feed_list=test_feed,
eval_func={'map': eval_func}, eval_func={'map': eval_func},
eval_fetch_list=[eval_fetch_list[0]], eval_fetch_list=[eval_fetch_list[0]],
prune_infer_model=[["image", "im_size"],["multiclass_nms_0.tmp_0"]],
train_optimizer=None) train_optimizer=None)
com.config(FLAGS.slim_file) com.config(FLAGS.slim_file)
com.run() com.run()
......
...@@ -142,7 +142,7 @@ def main(): ...@@ -142,7 +142,7 @@ def main():
assert os.path.exists(FLAGS.model_path) assert os.path.exists(FLAGS.model_path)
infer_prog, feed_names, fetch_targets = fluid.io.load_inference_model( infer_prog, feed_names, fetch_targets = fluid.io.load_inference_model(
dirname=FLAGS.model_path, executor=exe, dirname=FLAGS.model_path, executor=exe,
model_filename='__model__', model_filename='__model__.infer',
params_filename='__params__') params_filename='__params__')
eval_keys = ['bbox', 'gt_box', 'gt_label', 'is_difficult'] eval_keys = ['bbox', 'gt_box', 'gt_label', 'is_difficult']
......
...@@ -95,6 +95,7 @@ def compress(args): ...@@ -95,6 +95,7 @@ def compress(args):
eval_fetch_list=val_fetch_list, eval_fetch_list=val_fetch_list,
teacher_programs=[], teacher_programs=[],
train_optimizer=opt, train_optimizer=opt,
prune_infer_model=[[image.name], [out.name]],
distiller_optimizer=None) distiller_optimizer=None)
com_pass.config(args.config_file) com_pass.config(args.config_file)
com_pass.run() com_pass.run()
......
...@@ -53,20 +53,32 @@ def eval(args): ...@@ -53,20 +53,32 @@ def eval(args):
val_program, feed_names, fetch_targets = fluid.io.load_inference_model(args.model_path, val_program, feed_names, fetch_targets = fluid.io.load_inference_model(args.model_path,
exe, exe,
model_filename="__model__", model_filename="__model__.infer",
params_filename="__params__") params_filename="__params__")
val_reader = paddle.batch(reader.val(), batch_size=128) val_reader = paddle.batch(reader.val(), batch_size=128)
feeder = fluid.DataFeeder(place=place, feed_list=feed_names, program=val_program) feeder = fluid.DataFeeder(place=place, feed_list=feed_names, program=val_program)
results=[] results=[]
for batch_id, data in enumerate(val_reader()): for batch_id, data in enumerate(val_reader()):
image = [[d[0]] for d in data]
# top1_acc, top5_acc label = [[d[1]] for d in data]
result = exe.run(val_program, feed_data = feeder.feed(image)
feed=feeder.feed(data), pred = exe.run(val_program,
feed=feed_data,
fetch_list=fetch_targets) fetch_list=fetch_targets)
result = [np.mean(r) for r in result] pred = np.array(pred[0])
results.append(result) 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])
result = np.mean(np.array(results), axis=0) result = np.mean(np.array(results), axis=0)
print("top1_acc/top5_acc= {}".format(result)) print("top1_acc/top5_acc= {}".format(result))
sys.stdout.flush() sys.stdout.flush()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册