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.

test07.py 2.7 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import sys
  2. import os
  3. import random
  4. sys.path.append("/home/shanwei-luo/userdata/mmdetection")
  5. from mmdet.apis import (async_inference_detector, inference_detector,
  6. init_detector, show_result_pyplot)
  7. class_AOI_name = {"bu_pi_pei":"1","fang_xiang_fan":"2","err.txt_c_not_f":"3", "shang_xi_bu_lia":"4"}
  8. config_file_1 = '/home/shanwei-luo/userdata/mmdetection/work_dirs/AD_dsxw_test61/AD_dsxw_test61.py'
  9. checkpoint_file_1 = '/home/shanwei-luo/userdata/mmdetection/work_dirs/AD_dsxw_test61/epoch_36.pth'
  10. model_1 = init_detector(config_file_1, checkpoint_file_1, device='cuda:0')
  11. dirs_path = '/home/shanwei-luo/userdata/datasets/dsxw_test_SMD12_2022_0301_0314_day/'
  12. dirs_name = os.listdir(dirs_path)
  13. for dir_name in dirs_name:
  14. imgs_ok_path = dirs_path+dir_name+"/ok/"
  15. imgs_ng_path = dirs_path+dir_name+"/ng/"
  16. imgs_ok = os.listdir(imgs_ok_path)
  17. imgs_ng = os.listdir(imgs_ng_path)
  18. count_label_ok = len(imgs_ok)
  19. count_label_ng = len(imgs_ng)
  20. #print(count_label_ok,count_label_ng)
  21. imgs_labels = []
  22. imgs_name = []
  23. for img in imgs_ok:
  24. img_name = img.split("@")
  25. if img_name[2] in class_AOI_name.keys():
  26. count_label_ok -= 1
  27. continue
  28. imgs_labels.append(0)
  29. imgs_name.append(imgs_ok_path+img)
  30. for img in imgs_ng:
  31. img_name = img.split("@")
  32. if img_name[2] in class_AOI_name.keys():
  33. count_label_ng -= 1
  34. continue
  35. imgs_labels.append(1)
  36. imgs_name.append(imgs_ng_path+img)
  37. #print(count_label_ok,count_label_ng, len(imgs_labels))
  38. #print("before infer")
  39. index = 0
  40. num = len(imgs_name)
  41. results_1 = []
  42. step = 256
  43. while index<num:
  44. index += step
  45. if index < num:
  46. results_1_tmp = inference_detector(model_1, imgs_name[index-step:index])
  47. else:
  48. results_1_tmp = inference_detector(model_1, imgs_name[index-step:num])
  49. results_1 += results_1_tmp
  50. #print("after infer")
  51. imgs_results_1 = []
  52. for result in results_1:
  53. res_predict = 0
  54. for i in result:
  55. for j in range(i.shape[0]):
  56. if i[j, 4]>0.015:
  57. res_predict = 1
  58. imgs_results_1.append(res_predict)
  59. count_ng = 0
  60. count_ok = 0
  61. for i in range(len(imgs_labels)):
  62. if imgs_labels[i]==0 and imgs_results_1[i]==0:
  63. count_ok += 1
  64. if imgs_labels[i]==1 and imgs_results_1[i]==1:
  65. count_ng += 1
  66. if imgs_labels[i]==1 and imgs_results_1[i]==0:
  67. print(imgs_name[i])
  68. print(count_label_ok,count_label_ng)
  69. print(count_ok/count_label_ok, count_ng/count_label_ng)

No Description

Contributors (3)