def __init__(self, config_file): self.config_file_path = config_file # ----- CharNet configuration and initialization ----- cfg.merge_from_file(config_file) cfg.freeze() print(cfg) self.charnet = CharNet() self.charnet.load_state_dict(torch.load(cfg.WEIGHT)) self.charnet.eval() if torch.cuda.is_available(): print("[*] Using cuda!") self.charnet.cuda()
cv2.putText(img_word_ins, '{}'.format(word_ins.text), (word_bbox[0], word_bbox[1]), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1) return img_word_ins if __name__ == '__main__': parser = argparse.ArgumentParser(description="Test") parser.add_argument("config_file", help="path to config file", type=str) parser.add_argument("image_dir", type=str) parser.add_argument("results_dir", type=str) args = parser.parse_args() cfg.merge_from_file(args.config_file) cfg.freeze() print(cfg) charnet = CharNet() charnet.load_state_dict(torch.load(cfg.WEIGHT)) charnet.eval() charnet.cuda() for im_name in tqdm(sorted(os.listdir(args.image_dir))): #print("Processing {}...".format(im_name)) im_file = os.path.join(args.image_dir, im_name) im_original = cv2.imread(im_file) im, scale_w, scale_h, original_w, original_h = resize( im_original, size=cfg.INPUT_SIZE)
return img_word_ins if __name__ == '__main__': parser = argparse.ArgumentParser(description="Test") config_file='../configs/icdar2015_hourglass88.yaml' image_dir='../../data/Cello_Vietnamese_TestSet' results_dir='../../data/res_charnet' # parser.add_argument("config_file", help="path to config file", type=str, default=config_file) # parser.add_argument("image_dir", type=str, default=image_dir) # parser.add_argument("results_dir", type=str, default=results_dir) # # args = parser.parse_args() cfg.merge_from_file(config_file) cfg.freeze() print(cfg) charnet = CharNet() charnet.load_state_dict(torch.load(cfg.WEIGHT)) charnet.eval() charnet.cuda() for im_name in sorted(os.listdir(image_dir)): print("Processing {}...".format(im_name)) im_file = os.path.join(image_dir, im_name) im_original = cv2.imread(im_file) im, scale_w, scale_h, original_w, original_h = resize(im_original, size=cfg.INPUT_SIZE) with torch.no_grad():
from torch.autograd import Variable import threading from queue import Queue import src.models.Models as Net from models.multi_tasks import ELANetV3_modified_sigapore from src.fun_makedecision import fun_detection_TrafficViolation from src.model_inference_ObjectDetect_Elanet import detect from src.model_inference_Segmentation import evaluateModel, evaluateModel_models from src.fun_plotfunction import plot_ROI, plot_bbox_Violation, plot_bbox from src.fun_modify_seg import fun_intergate_seg_LaneandRoad from src.violation import save_violation, createFolder from charnet.config import cfg from charnet.modeling.model import CharNet #################### 載入偵測車牌charnet的cfg&Model ####################### cfg.merge_from_file("./configs/icdar2015_hourglass88.yaml") cfg.freeze() charnet = CharNet() charnet.load_state_dict(torch.load(cfg.WEIGHT)) charnet.eval() #################### 載入偵測車牌charnet的cfg&Model ####################### os.environ["CUDA_VISIBLE_DEVICES"] = "0" device = torch.device("cuda" if torch.cuda.is_available() else "cpu") print('GPU:', device) # load segmentation model filepath_model_seg_LaneLine = './models/ESPNet_Line_mytransfrom_full_256_512_weights_epoch_131.pth' filepath_model_seg_road = './models/ESPNet_road_mytransfrom_full_256_512_weights_epoch_41.pth' # Load Object Detection model checkpoint_path = './models/od_NoPretrain/BEST_checkpoint.pth.tar' video_path = '../../data/(Front)IPCamera_20200305095701_p000.avi'