def eval_model(model_name, test_img_path, submit_path, save_flag=True): if os.path.exists(submit_path): shutil.rmtree(submit_path) os.mkdir(submit_path) device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") model = EAST(False).to(device) model.load_state_dict(torch.load(model_name)) model.eval() start_time = time.time() detect_dataset(model, device, test_img_path, submit_path) os.chdir(submit_path) res = subprocess.getoutput('zip -q submit.zip *.txt') res = subprocess.getoutput('mv submit.zip ../') os.chdir('../') res = subprocess.getoutput( 'python ./evaluate/script.py –g=./evaluate/gt.zip –s=./submit.zip') print(res) os.remove('./submit.zip') print('eval time is {}'.format(time.time() - start_time)) if not save_flag: shutil.rmtree(submit_path)
f.write(strResult) if args.vis: for bbox in boxes: # bbox = bbox / scale.repeat(int(len(bbox) / 2)) bbox = np.array(bbox,np.int) cv2.drawContours(orign_img, [bbox[:8].reshape(int(bbox.shape[0] / 2), 2)], -1, (0, 0, 255), 2) cv2.imwrite(vis_file, orign_img) if not args.is_test: f_score_new = getresult(output_path,args.gt_name) if __name__ == '__main__': device = torch.device("cuda") model = EAST() data_parallel = False # if torch.cuda.device_count() > 1: # model = nn.DataParallel(model) # data_parallel = True model.to(device) args.workspace = os.path.join(args.workspace, args.exp_name) args.resume = os.path.join(args.workspace,args.resume) print("loading pretrained model from ",args.resume) model.load_state_dict(torch.load(args.resume)) for ther in range(1,10): ther_ = ther*0.1 print("threshold:",ther_) test(model,args,ther_)
for box in boxes ]) with open( os.path.join( submit_path, 'res_' + os.path.basename(img_file).replace('.jpg', '.txt')), 'w') as f: f.writelines(seq) if __name__ == '__main__': img_path = '/data/data_weijiawu/Sence_Text_detection/Paper-ACCV/DomainAdaptive/ICDAR2015/EAST_v1/ICDAR15/Test/image/' model_path = '/data/data_weijiawu/Sence_Text_detection/Paper-ACCV/DomainAdaptive/ICDAR2015/EAST_v4/Model_save/model_epoch_1.pth' res_img = '/data/data_weijiawu/Sence_Text_detection/Paper-ACCV/DomainAdaptive/ICDAR2015/EAST_v1/ICDAR15/Test/submit/' device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") model = EAST().to(device) model.load_state_dict(torch.load(model_path)) model.eval() image_list = os.listdir(img_path) for one_image in tqdm(image_list): image_path = os.path.join(img_path, one_image) img = Image.open(image_path) output_path = os.path.join( "/home/wwj/workspace/Sence_Text_detection/Paper-ACCV/DomainAdaptive/ICDAR2013/EAST_v1/show/", one_image) img_show = cv2.imread(image_path) filename, file_ext = os.path.splitext(os.path.basename(one_image)) res_file = res_img + "res_" + filename + '.txt' boxes, score = detect(img, model, device)
epoch + 1, args.epoch_iter, i + 1, int(len(train_loader_source)), time.time() - start_time, loss.item())) # if i>4000 and i%1000==0: # f_score = test(epoch, model, args.t_eval_path, args.t_output_path, f_score, args.save_model) logger.info('epoch_loss is {:.8f}, epoch_time is {:.8f}'.format(epoch_loss / int(7200 / args.batch_size),time.time() - epoch_time)) logger.info(time.asctime(time.localtime(time.time()))) if __name__ == '__main__': args.workspace = os.path.join(args.workspace, args.exp_name) os.makedirs(args.workspace, exist_ok=True) logger = setup_logger(os.path.join(args.workspace, 'train_MSRA_log')) criterion = Loss() device = torch.device("cuda") model = EAST() # model = nn.DataParallel(model) data_parallel = False if torch.cuda.device_count() > 1: model = nn.DataParallel(model) data_parallel = True model.to(device) optimizer = torch.optim.Adam(model.parameters(), lr=args.lr) scheduler = lr_scheduler.MultiStepLR(optimizer, milestones=[150,220], gamma=0.1) # 先产生第一次的pseudo-label logger.info("loading pretrained model from "+args.resume) # model.load_state_dict(torch.load(args.resume)) trainset = MSRA_TD500(args.msra_data,args.hust_path,args.is_box_pseudo) train_loader_target = data.DataLoader(trainset, batch_size=args.batch_size,
# print(" best_f_score:", f_score) # print(" ---------------------------------------------------------") return f_score_new if __name__ == '__main__': train_img_path = os.path.abspath('/data/data_weijiawu/SynthText') train_gt_path = os.path.abspath('/data/data_weijiawu/SynthText/gt.mat') args.workspace = os.path.join(args.workspace, args.exp_name) os.makedirs(args.workspace, exist_ok=True) logger = setup_logger(os.path.join(args.workspace, 'train_synthtext_log')) criterion = Loss() device = torch.device("cuda") model = EAST() data_parallel = False if torch.cuda.device_count() > 1: model = nn.DataParallel(model) data_parallel = True model.to(device) optimizer = torch.optim.Adam(model.parameters(), lr=args.lr) scheduler = lr_scheduler.MultiStepLR(optimizer, milestones=[args.epoch_iter // 2], gamma=0.1) # 先产生第一次的pseudo-label # logger.info("loading pretrained model from ",args.resume) # model.load_state_dict(torch.load(args.resume)) trainset_ = SynthText(train_img_path, train_gt_path)
transforms.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225))]) score_map, geo_map, ignored_map = get_score_geo( img, vertices, labels, self.scale, self.length) return transform(img), score_map, geo_map, ignored_map if __name__ == "__main__": from network.model import EAST from torch import nn train_img_path = os.path.abspath( '/data/data_weijiawu/ICDAR17/train_image/') train_gt_path = os.path.abspath("/data/data_weijiawu/ICDAR17/train_gt/") device = torch.device("cuda") model = EAST() data_parallel = False if torch.cuda.device_count() > 1: model = nn.DataParallel(model) data_parallel = True model.to(device) trainset = ICDAR17(train_img_path, train_gt_path) train_loader = data.DataLoader(trainset, batch_size=2, shuffle=True, num_workers=10, drop_last=True) for i, (img, gt_score, gt_geo, ignored_map) in enumerate(train_loader): image_path = "/home/wwj/workspace/Sence_Text_detection/AAAI_EAST/Baseline/EAST_v1/show/image.jpg"
logger.info( " ---------------------------------------------------------") logger.info(" current f_score: {:.3f} best_f_score: {:.3f}".format( f_score_new, f_score)) logger.info( " ---------------------------------------------------------") return f_score if __name__ == '__main__': args.workspace = os.path.join(args.workspace, args.exp_name) os.makedirs(args.workspace, exist_ok=True) logger = setup_logger(os.path.join(args.workspace, 'train_icdar17_log')) criterion = Loss() device = torch.device("cuda") model = EAST() data_parallel = False if torch.cuda.device_count() > 1: model = nn.DataParallel(model) data_parallel = True model.to(device) optimizer = torch.optim.Adam(model.parameters(), lr=args.lr) scheduler = lr_scheduler.MultiStepLR(optimizer, milestones=[100, 200], gamma=0.1) # 先产生第一次的pseudo-label logger.info("loading pretrained model from " + args.resume) model.load_state_dict(torch.load(args.resume)) # target domain