cal_sensitivities_file.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 cal_sensitivies_file(model_dir, dataset, 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.cal_params_sensitivities(
  29. model, save_file, eval_dataset, batch_size=8)
  30. if __name__ == '__main__':
  31. parser = argparse.ArgumentParser(description=__doc__)
  32. parser.add_argument(
  33. "--model_dir",
  34. default="./output/yolov3_mobilenet/best_model",
  35. type=str,
  36. help="The model path.")
  37. parser.add_argument(
  38. "--dataset", default="./insect_det", type=str, help="The model path.")
  39. parser.add_argument(
  40. "--save_file",
  41. default="./sensitivities.data",
  42. type=str,
  43. help="The sensitivities file path.")
  44. args = parser.parse_args()
  45. cal_sensitivies_file(args.model_dir, args.dataset, args.save_file)