Tencent / PocketFlow

An Automatic Model Compression (AutoMC) framework for developing smaller and faster AI applications.
https://pocketflow.github.io
Other
2.79k stars 490 forks source link

Question about export_chn_pruned_tflite_model.py #315

Closed chaow94 closed 5 years ago

chaow94 commented 5 years ago

I follow tutorial,train pretrained models

./scripts/run_local.sh nets/resnet_at_cifar10_run.py

pruned weight

./scripts/run_local.sh nets/resnet_at_cifar10_run.py \ --learner channel \ --batch_size_eval 64 \ --cp_uniform_preserve_ratio 0.5 \ --cp_prune_option uniform \ --resnet_size 20 and convert prune weight (which is models/best_model.ckpt*) to .tflite:

python tools/conversion/export_chn_pruned_tflite_model.py --model_dir models/ --enbl_chn_prune True

However, I find that:

INFO:tensorflow:models/model_transformed.pb generated INFO:tensorflow:input: import/net_input:0 / output: import/net_output:0 INFO:tensorflow:outputs from the .pb model: [[0.05446765 0.03244423 0.16720814 0.39245573 0.03620378 0.10002795 0.03975614 0.04592538 0.03278159 0.09872936]] INFO:tensorflow:time consumption of .pb model: 10.04 ms INFO:tensorflow:models/model_transformed.pb -> models/model_transformed.tflite INFO:tensorflow:models/model_transformed.tflite generated INFO:tensorflow:input details: [{'name': 'net_input', 'index': 170, 'shape': array([ 1, 32, 32, 3], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0)}] INFO:tensorflow:output details: [{'name': 'net_output', 'index': 171, 'shape': array([ 1, 10], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0)}] INFO:tensorflow:outputs from the .tflite model: [[nan nan nan nan nan nan nan nan nan nan]] INFO:tensorflow:time consumption of .tflite model: 9.85 ms

outputs from the *.tflite model are nan.

chaow94 commented 5 years ago

自己来说下解决方案:

--learner channel

调用的剪枝只会存下训练时的模型,但是呢由于 resnet20 存在 BN 层,因此预测时结果会不对,改用

--learner chn-pruned-gpu

这样使用 models_cpg_eval 下的模型就没啥问题了

吐槽下, learners\channel_pruning\learner.py 写的可能是有问题,没有保存 eval 模型吧