params_analysis.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. #Licensed under the Apache License, Version 2.0 (the "License");
  4. #you may not use this file except in compliance with the License.
  5. #You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. #Unless required by applicable law or agreed to in writing, software
  10. #distributed under the License is distributed on an "AS IS" BASIS,
  11. #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. #See the License for the specific language governing permissions and
  13. #limitations under the License.
  14. import argparse
  15. import os
  16. # 选择使用0号卡
  17. os.environ['CUDA_VISIBLE_DEVICES'] = '0'
  18. import paddlex as pdx
  19. def params_analysis(model_dir, dataset, batch_size, save_file):
  20. # 加载模型
  21. model = pdx.load_model(model_dir)
  22. # 定义验证所用的数据集
  23. eval_dataset = pdx.datasets.VOCDetection(
  24. data_dir=dataset,
  25. file_list=os.path.join(dataset, 'val_list.txt'),
  26. label_list=os.path.join(dataset, 'labels.txt'),
  27. transforms=model.eval_transforms)
  28. pdx.slim.prune.analysis(
  29. model,
  30. dataset=eval_dataset,
  31. batch_size=batch_size,
  32. save_file=save_file)
  33. if __name__ == '__main__':
  34. parser = argparse.ArgumentParser(description=__doc__)
  35. parser.add_argument(
  36. "--model_dir",
  37. default="./output/yolov3_mobilenetv3/best_model",
  38. type=str,
  39. help="The model path.")
  40. parser.add_argument(
  41. "--dataset",
  42. default="./aluminum_inspection",
  43. type=str,
  44. help="The model path.")
  45. parser.add_argument("--batch_size", default=8, type=int, help="Batch size")
  46. parser.add_argument(
  47. "--save_file",
  48. default="./sensitivities.data",
  49. type=str,
  50. help="The sensitivities file path.")
  51. args = parser.parse_args()
  52. params_analysis(args.model_dir, args.dataset, args.batch_size,
  53. args.save_file)