pred.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import logging
  2. logging.basicConfig(
  3. format='%(asctime)s [%(levelname)s] - %(message)s',
  4. level=logging.INFO)
  5. import os
  6. from vi_cls.cls_pred import cls_pred
  7. from config import config
  8. class eval(cls_pred):
  9. def __init__(self, cfg, args=None):
  10. cls_pred.__init__(self, cfg, args)
  11. self.pred_class = None
  12. #------------------------------------------------------------------------------
  13. # Predict Image Files
  14. #------------------------------------------------------------------------------
  15. def before_pred_file(self, img_file):
  16. split_num = 1
  17. # if img_file.find('100X') > 0 or img_file.find('100x') > 0:
  18. # split_num = 4
  19. # elif img_file.find('200X') > 0 or img_file.find('200x') > 0:
  20. # split_num = 2
  21. # elif img_file.find('500X') > 0 or img_file.find('500x') > 0:
  22. # split_num = 1
  23. # elif img_file.find('1000X') > 0 or img_file.find('1000x') > 0:
  24. # split_num = 1
  25. self.set_arg('splits_num', split_num)
  26. def after_pred_file(self, det_dict):
  27. self.pred_class = ''
  28. if len(det_dict) > 0:
  29. dets = sorted(det_dict.items(), lambda x, y : cmp(x[1], y[1]), reverse=True)
  30. self.pred_class = dets[0][0]
  31. def get_pred_result_text(self, det_dict, im_inp):
  32. return self.pred_class
  33. if __name__ == '__main__':
  34. cfg = config()
  35. e = eval(cfg)
  36. e.set_arg('img_dir', e._args.img_dir)
  37. e.set_arg('gray_image', 'True')
  38. e.set_arg('resize_w', 224)
  39. e.set_arg('resize_h', 224)
  40. e.set_arg('crop_w', 224)
  41. e.set_arg('crop_h', 224)
  42. e.pred_file()