You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

postprocess.py 2.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright 2021 Huawei Technologies Co., Ltd
  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. # ============================================================================
  15. '''post process for 310 inference'''
  16. import os
  17. import argparse
  18. import numpy as np
  19. parser = argparse.ArgumentParser(description='fasterrcnn_export')
  20. parser.add_argument("--result_path", type=str, required=True, help="result file path")
  21. parser.add_argument("--label_file", type=str, required=True, help="label file")
  22. args = parser.parse_args()
  23. def read_label(label_file):
  24. f = open(label_file, "r")
  25. lines = f.readlines()
  26. img_label = {}
  27. for line in lines:
  28. img_id = line.split(":")[0]
  29. label = line.split(":")[1]
  30. img_label[img_id] = label
  31. return img_label
  32. def cal_acc(result_path, label_file):
  33. step = 0
  34. sum_a = 0
  35. img_label = read_label(label_file)
  36. files = os.listdir(result_path)
  37. for file in files:
  38. full_file_path = os.path.join(result_path, file)
  39. if os.path.isfile(full_file_path):
  40. result = np.fromfile(full_file_path, dtype=np.float32).reshape(1, 1000)
  41. pred = np.argmax(result, axis=1)
  42. step = step + 1
  43. if pred == int(img_label[file[:-6]]):
  44. sum_a = sum_a + 1
  45. print("========step:{}========".format(step))
  46. print("========sum:{}========".format(sum_a))
  47. accuracy = sum_a * 100.0 / step
  48. print("========accuracy:{}========".format(accuracy))
  49. if __name__ == "__main__":
  50. cal_acc(args.result_path, args.label_file)