import datetime import torch from models.cnnlstm import CnnOcrModel from torch.autograd import Variable from torchvision import transforms from arabic import ArabicAlphabet from datautils import GroupedSampler, SortByWidthCollater from english import EnglishAlphabet from iam import IAMDataset from madcat import MadcatDataset from textutils import * import loggy logger = loggy.setup_custom_logger('root', "test_madcat_iam.py") def get_args(): parser = argparse.ArgumentParser(description="OCR Testing Script") parser.add_argument("--line-height", type=int, default=30, help="Input image line height") parser.add_argument("--hpad", type=int, default=0, help="Amount of horizontal padding to apply to left/right of input image (after resize)") parser.add_argument("--vpad", type=int, default=0, help="Amount of vertical padding to apply to top/bottom of input image (after resize)") parser.add_argument("--image-list", type=str, required=True, help="Specify list of images to decode") parser.add_argument("--snapshot", type=str, required=True, help="Path to snapshot from which we should initialize model weights") parser.add_argument("--model", type=str, default='CnnOcrModel', help="Model to use with the snapshot options") parser.add_argument("--lm-path", type=str, required=False, default="", help="path to LM dir containing TLG.fst, words.txt & units.txt")
import os import torch from torch.autograd import Variable from torch.utils.data import DataLoader import imagetransforms import loggy logger = loggy.setup_custom_logger('root', "train_cnn_lstm.py") from warpctc_pytorch import CTCLoss import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import datetime import time import shutil from ocr_dataset import OcrDataset from datautils import GroupedSampler, SortByWidthCollater from models.cnnlstm import CnnOcrModel from textutils import * import argparse from lr_scheduler import ReduceLROnPlateau def test_on_val(val_dataloader, model, criterion): start_val = time.time()