help='the validation images path') parser.add_argument('--dropout_rate', default=0.5, help='dropout rate.') #0.5 parser.add_argument('--epoch', type=int, default=1600, help='number of epoches for training') #800 parser.add_argument('--batch_size', default=batch, help='batch size') args = parser.parse_args() device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") print('device: ', device) print("len CHARS: ", len(CHARS)) print('pow:', p) print('r:', r) print('mini:', mini) lprnet = LPRNet(class_num=len(CHARS), dropout_rate=args.dropout_rate, r=r) #mini/c lprnet.to(device) summary(lprnet, (3, resh, resw)) #lprnet_load=torch.load('weights/Final_LPRNet_model.pth', map_location=lambda storage, loc: storage.cuda) #lprnet.load_state_dict(lprnet_load['net_state_dict']) #lprnet.load_state_dict(torch.load('weights/Final_LPRNet_model.pth', map_location=lambda storage, loc: storage)) print("LPRNet loaded") print('LPRNet params: ', sum(p.numel() for p in lprnet.parameters())) STN = STNet(r=r, resw=resw, resh=resh) STN.to(device) #summary(STN, (3,24,94)) summary(STN, (3, resh, resw)) #STN_load=torch.load('weights/Final_LPRNet_model.pth', map_location=lambda storage, loc: storage.cuda) #STN.load_state_dict(torch.load('weights/Final_STN_model.pth', map_location=lambda storage, loc: storage)) print("STN loaded") print('STN params: ', sum(p.numel() for p in STN.parameters()))
for i, label in enumerate(pred_labels): lb = "" for i in label: lb += CHARS[i] labels.append(lb) return labels, np.array(pred_labels) if __name__ == '__main__': parser = argparse.ArgumentParser(description='LPR Demo') parser.add_argument("-image", help='image path', default='data/ccpd_weather/吉BTW976.jpg', type=str) args = parser.parse_args() device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") lprnet = LPRNet(class_num=len(CHARS), dropout_rate=0) lprnet.to(device) lprnet.load_state_dict(torch.load('weights/Final_LPRNet_model.pth', map_location=lambda storage, loc: storage)) lprnet.eval() STN = STNet() STN.to(device) STN.load_state_dict(torch.load('weights/Final_STN_model.pth', map_location=lambda storage, loc: storage)) STN.eval() print("Successful to build network!") since = time.time() image = cv2.imread(args.image) im = cv2.resize(image, (94, 24), interpolation=cv2.INTER_CUBIC) im = (np.transpose(np.float32(im), (2, 0, 1)) - 127.5)*0.0078125
for i in label: lb += CHARS[i] labels.append(lb) return labels, np.array(pred_labels) if __name__ == '__main__': parser = argparse.ArgumentParser(description='LPR Demo') parser.add_argument("-image", help='image path', default='data/ccpd_weather/吉BTW976.jpg', type=str) parser.add_argument("-lprnet_model", help='lprnet model', default='weights/Final_LPRNet_model.pth', type=str) parser.add_argument("-stn_model", help='stn model', default='weights/Final_STN_model.pth', type=str) args = parser.parse_args() device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") lprnet = LPRNet(class_num=len(CHARS), dropout_rate=0) lprnet.to(device) lprnet.load_state_dict(torch.load(args.lprnet_model, map_location=lambda storage, loc: storage)) lprnet.eval() STN = STNet() STN.to(device) STN.load_state_dict(torch.load(args.stn_model, map_location=lambda storage, loc: storage)) STN.eval() print("Successful to build network!") since = time.time() image = cv2.imread(args.image) im = cv2.resize(image, (94, 24), interpolation=cv2.INTER_CUBIC) im = (np.transpose(np.float32(im), (2, 0, 1)) - 127.5)*0.0078125
if __name__ == '__main__': parser = argparse.ArgumentParser( description='LPR Demo') # 00-D-112255 151-WX-694 parser.add_argument( "-image", help='image path', default= '/media/cbpm2016/D/liaolong/alpr/License_Plate_Detection_Pytorch/data/plate_test/152L393.png', type=str) args = parser.parse_args() device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") lprnet = LPRNet(class_num=len(CHARS), dropout_rate=0) lprnet.to(device) lprnet.load_state_dict( torch.load( '/media/cbpm2016/D/liaolong/alpr/License_Plate_Detection_Pytorch/LPRNet/saving_ckpt/lprnet_epoch_001200_model.ckpt' )['net_state_dict']) lprnet.eval() STN = STNet() STN.to(device) STN.load_state_dict( torch.load( '/media/cbpm2016/D/liaolong/alpr/License_Plate_Detection_Pytorch/LPRNet/saving_ckpt/stn_epoch_001200_model.ckpt' )['net_state_dict']) STN.eval()
parser.add_argument('--img_dirs_val', default="./data/validation", help='the validation images path') parser.add_argument('--dropout_rate', default=0.5, help='dropout rate.') parser.add_argument('--epoch', type=int, default=33, help='number of epoches for training') parser.add_argument('--batch_size', type=int, default=128, help='batch size') args = parser.parse_args() device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") lprnet = LPRNet(class_num=len(CHARS), dropout_rate=args.dropout_rate) lprnet.to(device) # load pretrained model # lprnet.load_state_dict(torch.load('weights/LPRNet_model_Init.pth', map_location=lambda storage, loc: storage)) # print("LPRNet loaded") def xavier(param): nn.init.xavier_uniform(param) def weights_init(m): for key in m.state_dict(): if key.split('.')[-1] == 'weight': if 'conv' in key: nn.init.kaiming_normal_(m.state_dict()[key], mode='fan_out') if 'bn' in key:
parser.add_argument('--img_dirs_train', default="data/plate_train", help='the training images path') parser.add_argument('--img_dirs_val', default="./data/validation", help='the validation images path') parser.add_argument('--dropout_rate', default=0.5, help='dropout rate.') parser.add_argument('--epoch', type=int, default=10000, help='number of epoches for training') parser.add_argument('--batch_size', default=24 * 4, help='batch size') args = parser.parse_args() device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") lprnet = LPRNet(class_num=len(CHARS), dropout_rate=args.dropout_rate) lprnet.to(device) lprnet.load_state_dict( torch.load('LPRNet/weights/LPRNet_model_Init.pth', map_location=lambda storage, loc: storage)) # lprnet.load_state_dict(torch.load('/media/cbpm2016/D/liaolong/alpr/License_Plate_Detection_Pytorch/saving_ckpt/lprnet_Iter_007200_model.ckpt')['net_state_dict']) print("LPRNet loaded") STN = STNet() STN.to(device) STN.load_state_dict( torch.load('LPRNet/weights/STN_model_Init.pth', map_location=lambda storage, loc: storage)) # STN.load_state_dict(torch.load('/media/cbpm2016/D/liaolong/alpr/License_Plate_Detection_Pytorch/saving_ckpt/stn_Iter_007200_model.ckpt')['net_state_dict']) print("STN loaded")
print('r:', r) dir = '/content/gdrive/MyDrive/個別研究/車牌/LPRNet3/test_lr_mini_saving_ckpt(1.1_2.5)/test_lr_mini_saving_ckpt(1.1_2.5-2)' # parser = argparse.ArgumentParser(description='LPR Evaluation') parser.add_argument('--img_size', default=(resw, resh), help='the image size') parser.add_argument('--img_dirs', default="data/test2", help='the images path') parser.add_argument('--dropout_rate', default=0.5, help='dropout rate.') parser.add_argument('--batch_size', default=1, help='batch size.') args = parser.parse_args() device = torch.device("cuda:0") # # device = torch.device("cpu")# print(device) lprnet = LPRNet(class_num=len(CHARS), dropout_rate=args.dropout_rate, r=r) lprnet.to(device) # lprnet.load_state_dict(torch.load('weights/Final_LPRNet_model.pth', map_location=lambda storage, loc: storage)) checkpoint = torch.load(dir + '/lprnet_Iter_150000_model.ckpt') # lprnet.load_state_dict(checkpoint['net_state_dict']) lprnet.eval() print("LPRNet loaded") torch.save(lprnet.state_dict(), 'weights/Final2_LPRNet_model.pth') STN = STNet(r=r, resw=resw, resh=resh) STN.to(device) # STN.load_state_dict(torch.load('weights/Final_STN_model.pth', map_location=lambda storage, loc: storage)) checkpoint = torch.load(dir + '/stn_Iter_150000_model.ckpt') # STN.load_state_dict(checkpoint['net_state_dict'])