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.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. """Postprocess for yolov3-resnet18"""
  16. import os
  17. import argparse
  18. import numpy as np
  19. from src.config import ConfigYOLOV3ResNet18
  20. from src.utils import metrics
  21. parser = argparse.ArgumentParser(description='Yolov3 postprocess')
  22. parser.add_argument("--batchsize", type=int, default=1, help="batchsize.")
  23. parser.add_argument("--anno_path", type=str, required=True, help="Annotation path.")
  24. parser.add_argument("--result_path", type=str, required=True, help="result files path.")
  25. args = parser.parse_args()
  26. if __name__ == '__main__':
  27. config = ConfigYOLOV3ResNet18()
  28. batchsize = args.batchsize
  29. anno_dict = {}
  30. for line in open(args.anno_path):
  31. line_list = line.split(' ')
  32. line_list[0] = line_list[0].split('/')[-1]
  33. anno_dict[line_list[0]] = line_list[1:]
  34. pred_data = []
  35. for key in anno_dict:
  36. result0 = os.path.join(args.result_path, key.split('.')[0] + '_0.bin')
  37. result1 = os.path.join(args.result_path, key.split('.')[0] + '_1.bin')
  38. output0 = np.fromfile(result0, np.float32).reshape(batchsize, 13860, 4)
  39. output1 = np.fromfile(result1, np.float32).reshape(batchsize, 13860, 2)
  40. anno_list = []
  41. for v in anno_dict[key]:
  42. v_list = v.split(',')
  43. anno_list.append(v_list)
  44. annotation = np.array(anno_list, np.int64)
  45. for batch_idx in range(batchsize):
  46. pred_data.append({"boxes": output0[batch_idx],
  47. "box_scores": output1[batch_idx],
  48. "annotation": annotation})
  49. precisions, recalls = metrics(pred_data)
  50. print("\n========================================\n")
  51. for i in range(config.num_classes):
  52. print("class {} precision is {:.2f}%, recall is {:.2f}%".format(i, precisions[i] * 100, recalls[i] * 100))