예제 #1
0
        for t in range(output.size(0)):
            for k in range(output.size(1)):
                print('{:.10g}'.format(float(output[t, k])),
                      file=fileout,
                      end=' ')
            print('', file=fileout)
        if add_boundary_blank:
            print('{:.10g}'.format(0.0), file=fileout, end=' ')
            for k in range(1, output.size(1)):
                print('{:.10g}'.format(-1e30), file=fileout, end=' ')
            print('', file=fileout)
        print(']', file=fileout)


if __name__ == '__main__':
    add_defaults('gpu')
    add_argument('--adaptive_pool_height',
                 type=int,
                 default=16,
                 help='Average adaptive pooling of the images before the '
                 'LSTM layers')
    add_argument('--lstm_hidden_size', type=int, default=128)
    add_argument('--lstm_num_layers', type=int, default=1)
    add_argument('--add_softmax', action='store_true')
    add_argument('--add_boundary_blank', action='store_true')
    add_argument('syms', help='Symbols table mapping from strings to integers')
    add_argument('img_dir', help='Directory containing word images')
    add_argument('gt_file', help='')
    add_argument('checkpoint', help='')
    add_argument('output', type=argparse.FileType('w'))
    args = args()
예제 #2
0
#!/usr/bin/env python

from __future__ import absolute_import

import argparse

import torch.nn as nn
from laia.models.htr.gated_crnn import GatedCRNN
from laia.common import ModelSaver
from laia.common.arguments import add_argument, args, add_defaults
from laia.common.arguments_types import NumberInClosedRange, TupleList, \
    str2bool
from laia.utils import SymbolsTable

if __name__ == '__main__':
    add_defaults('train_path')
    add_argument('num_input_channels',
                 type=NumberInClosedRange(int, vmin=1),
                 help='Number of channels of the input images')
    add_argument('syms',
                 type=argparse.FileType('r'),
                 help='Symbols table mapping from strings to integers')
    add_argument('--cnn_num_features',
                 type=NumberInClosedRange(int, vmin=1),
                 nargs='+',
                 default=[8, 16, 32, 64, 128],
                 help='Number of features in each convolutional layer')
    add_argument('--cnn_kernel_size',
                 type=TupleList(int, dimensions=2),
                 nargs='+',
                 default=[3, (2, 4), 3, (2, 4), 3],
예제 #3
0
from laia.engine.phoc_engine_wrapper import PHOCEngineWrapper
from laia.hooks import Hook, HookList, action
from laia.hooks.conditions import GEqThan, Highest
from laia.losses.dortmund_bce_loss import DortmundBCELoss
from laia.common.arguments import add_argument, add_defaults, args
from laia.utils.dortmund_image_to_tensor import DortmundImageToTensor

if __name__ == '__main__':
    add_defaults(
        'gpu',
        'max_epochs',
        'max_updates',
        'train_samples_per_epoch',
        'valid_samples_per_epoch',
        'seed',
        'train_path',
        # Override default values for these arguments, but use the
        # same help/checks:
        learning_rate=0.0001,
        momentum=0.9,
        iterations_per_update=10,
        show_progress_bar=True,
        use_distortions=True,
        weight_l2_penalty=0.00005)
    add_argument('--load_checkpoint',
                 type=str,
                 help='Path to the checkpoint to load.')
    add_argument('--continue_epoch', type=int)
    add_argument('--phoc_levels',
                 type=int,
                 default=[1, 2, 3, 4, 5],
                 nargs='+',
from laia.engine.feeders import ImageFeeder, ItemFeeder
from tqdm import tqdm
import pickle

import editdistance


def cer_score_dict(decoded, target, ids):
    cer_dict = {}
    for ref, hyp, x in zip(target, decoded, ids):
        cer_dict[x] = editdistance.eval(ref, hyp) / len(ref)
    return cer_dict


if __name__ == "__main__":
    add_defaults("batch_size", "gpu", "train_path", logging_level="WARNING")
    add_argument(
        "--syms",
        type=argparse.FileType("r"),
        help="Symbols table mapping from strings to integers",
    )
    add_argument("--img_dirs",
                 type=str,
                 nargs="+",
                 help="Directory containing word images")
    add_argument(
        "--txt_table",
        type=argparse.FileType("r"),
        help="Character transcriptions of each image.",
    )
    add_argument(
        for t in range(output.size(0)):
            for k in range(output.size(1)):
                print("{:.10g}".format(float(output[t, k])),
                      file=fileout,
                      end=" ")
            print("", file=fileout)
        if add_boundary_blank:
            print("{:.10g}".format(0.0), file=fileout, end=" ")
            for k in range(1, output.size(1)):
                print("{:.10g}".format(-1e30), file=fileout, end=" ")
            print("", file=fileout)
        print("]", file=fileout)


if __name__ == "__main__":
    add_defaults("gpu")
    add_argument(
        "--image_sequencer",
        type=str,
        default="avgpool-16",
        help="Average adaptive pooling of the images before the LSTM layers",
    )
    add_argument("--lstm_hidden_size", type=int, default=128)
    add_argument("--lstm_num_layers", type=int, default=1)
    add_argument("--add_softmax", action="store_true")
    add_argument("--add_boundary_blank", action="store_true")
    add_argument("syms", help="Symbols table mapping from strings to integers")
    add_argument("img_dir", help="Directory containing word images")
    add_argument("gt_file", help="")
    add_argument("checkpoint", help="")
    add_argument("output", type=argparse.FileType("w"))
예제 #6
0
from laia.hooks.conditions import Lowest, MultipleOf, GEqThan
from laia.common.arguments import add_argument, args, add_defaults
from laia.common.loader import (TrainerLoader, ModelLoader,
                                TrainerCheckpointLoader, ModelCheckpointLoader)
from laia.common.saver import (TrainerSaver, CheckpointSaver, RollingSaver,
                               ModelCheckpointSaver, TrainerCheckpointSaver)
from laia.utils import SymbolsTable, ImageToTensor, TextToTensor
from laia.utils.dortmund_image_to_tensor import DortmundImageToTensor
from torch.optim import SGD

if __name__ == '__main__':
    add_defaults('batch_size',
                 'learning_rate',
                 'gpu',
                 'max_epochs',
                 'train_path',
                 'train_samples_per_epoch',
                 'iterations_per_update',
                 momentum=0.9,
                 show_progress_bar=True)
    add_argument('fixed_height',
                 type=int,
                 help='Resize images to this fixed height size')
    add_argument('syms',
                 type=argparse.FileType('r'),
                 help='Symbols table mapping from strings to integers')
    add_argument('img_dir', help='Directory containing word images')
    add_argument('tr_txt_table',
                 type=argparse.FileType('r'),
                 help='Character transcriptions of each training image')
    add_argument('va_txt_table',