예제 #1
0
logger = laia.common.logging.get_logger("laia.egs.washington.train_phoc")
laia.common.logging.get_logger("laia.hooks.conditions.multiple_of").setLevel(
    laia.common.logging.WARNING)

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,
        num_rolling_checkpoints=5,
        iterations_per_update=10,
        save_checkpoint_interval=5,
        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",
예제 #2
0
    for img_id, output in zip(img_ids, outputs):
        output = output.cpu()
        print(img_id, file=fileout)
        for t in range(output.size(0)):
            for k in range(output.size(1)):
                print(
                    "{:d}\t{:d}\t{:d}\t0,{:.10g},{:d}".format(
                        t, t + 1, k + 1, -float(output[t, k]), k + 1),
                    file=fileout,
                )
        print(output.size(0), 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("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()
        x = np.asarray(x, dtype=np.float32)
        x = dortmund_distort(x / 255.0)
        if x.shape != 3:
            x = np.expand_dims(x, axis=-1)
        x = np.transpose(x, (2, 0, 1))
        return torch.from_numpy(x)


if __name__ == "__main__":
    import matplotlib.pyplot as plt

    import laia.random
    from laia.data import TextImageFromTextTableDataset, ImageDataLoader
    from laia.plugins.arguments import add_argument, add_defaults, args

    add_defaults("seed")
    add_argument("--num_images",
                 type=int,
                 help="Show only this number of images")
    add_argument("--shuffle",
                 action="store_true",
                 help="Shuffle the list of images")
    add_argument("img_dir", help="Directory containing images")
    add_argument("txt_table", help="Transcriptions of each image")
    args = args()
    laia.random.manual_seed(args.seed)

    dataset = TextImageFromTextTableDataset(
        args.txt_table, args.img_dir, img_transform=DortmundImageToTensor())
    dataset_loader = ImageDataLoader(dataset=dataset,
                                     image_channels=1,