Ejemplo n.º 1
0
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
    data = torch.from_numpy(im).float().unsqueeze(0).to(device)  # torch.Size([1, 3, 24, 94]) 
    transfer = STN(data)
    preds = lprnet(transfer)
    preds = preds.cpu().detach().numpy()  # (1, 68, 18)
    
    labels, pred_labels = decode(preds, CHARS)
    print("model inference in {:2.3f} seconds".format(time.time() - since))
Ejemplo n.º 2
0
        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()

    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
    data = torch.from_numpy(im).float().unsqueeze(0).to(
        device)  # torch.Size([1, 3, 24, 94])
    transfer = STN(data)
    preds = lprnet(transfer)
    preds = preds.cpu().detach().numpy()  # (1, 68, 18)
    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
    data = torch.from_numpy(im).float().unsqueeze(0).to(device)  # torch.Size([1, 3, 24, 94]) 
    transfer = STN(data)
    preds = lprnet(transfer)
    preds = preds.cpu().detach().numpy()  # (1, 68, 18)
    
    labels, pred_labels = decode(preds, CHARS)
    print("model inference in {:2.3f} seconds".format(time.time() - since))
Ejemplo n.º 4
0
    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")

    dataset = LPRDataLoader([args.img_dirs_train], args.img_size)
    dataloader = DataLoader(dataset,
                            batch_size=args.batch_size,
                            shuffle=True,
                            num_workers=4,
                            collate_fn=collate_fn)
    print('training dataset loaded with length : {}'.format(len(dataset)))
    # print('validation dataset loaded with length : {}'.format(len(dataset['val'])))

    # define optimizer & loss
    optimizer = torch.optim.Adam([{