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.

get_score_csv.py 2.6 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import sys
  2. import os
  3. import random
  4. import numpy as np
  5. import shutil
  6. sys.path.append("/home/shanwei-luo/userdata/mmdetection")
  7. from mmdet.apis import (async_inference_detector, inference_detector,
  8. init_detector, show_result_pyplot)
  9. import argparse
  10. import pandas as pd
  11. #python get_score_csv.py --config_file /home/shanwei-luo/teamdata/anomaly_detection_active_learning/model/work_dirs/AD_dsxw_test66_06_10/AD_dsxw_test66_06_10.py --checkpoint_file /home/shanwei-luo/teamdata/anomaly_detection_active_learning/model/work_dirs/AD_dsxw_test66_06_10/latest.pth --images_path /home/shanwei-luo/teamdata/anomaly_detection_active_learning/data0422/unlabel_11_12/images/ --test_batch_size 128 --result_path test_unlabel_11_12.csv
  12. def parse_args():
  13. parser = argparse.ArgumentParser(description='get best threshold')
  14. parser.add_argument('--config_file', help='config')
  15. parser.add_argument('--checkpoint_file', help='checkpoint')
  16. parser.add_argument('--images_path', help='images')
  17. parser.add_argument('--test_batch_size', help='images')
  18. parser.add_argument('--result_path', help='result_path')
  19. args = parser.parse_args()
  20. return args
  21. args = parse_args()
  22. config_file_1 = args.config_file
  23. checkpoint_file_1 = args.checkpoint_file
  24. img_path = args.images_path
  25. model_1 = init_detector(config_file_1, checkpoint_file_1, device='cuda:0')
  26. imgs = os.listdir(img_path)
  27. imgs_name = []
  28. for img in imgs:
  29. imgs_name.append(img_path+img)
  30. print(len(imgs_name))
  31. print("before infer")
  32. index = 0
  33. num = len(imgs_name)
  34. results_1 = []
  35. results_feat = []
  36. step = int(args.test_batch_size)
  37. while index<num:
  38. index += step
  39. if index < num:
  40. results_1_tmp, results_feat_tmp = inference_detector(model_1, imgs_name[index-step:index], feat=True)
  41. else:
  42. results_1_tmp, results_feat_tmp = inference_detector(model_1, imgs_name[index-step:num], feat=True)
  43. results_1 += results_1_tmp
  44. results_feat += results_feat_tmp
  45. print(len(results_1))
  46. print("after infer")
  47. result_score = []
  48. for result in results_1:
  49. max_v = 0
  50. for i in result:
  51. for j in range(i.shape[0]):
  52. if max_v < i[j, 4]:
  53. max_v = i[j, 4]
  54. result_score.append(max_v)
  55. '''np_result = np.array(result_score)
  56. print(np_result.shape)
  57. np.save('/home/shanwei-luo/userdata/datasets/PCBA_dataset_v15_MLOPS/result.npy', np_result)'''
  58. result_path = args.result_path
  59. dataframe = pd.DataFrame({'Image_Name':imgs,'score':result_score, 'feature':results_feat, "model_name":"cascade_mlops_baseline"})
  60. dataframe.to_csv(result_path)

No Description

Contributors (1)