Exemple #1
0
def load_test_model(opt, dummy_opt):
    shared_fields = None
    shared_model_opt = None
    models = []
    for model_path in opt.models:
        checkpoint = torch.load(model_path,
                                map_location=lambda storage, loc: storage)
        fields = load_fields_from_vocab(checkpoint['vocab'])

        model_opt = checkpoint['opt']

        for arg in dummy_opt:
            if arg not in model_opt:
                model_opt.__dict__[arg] = dummy_opt[arg]

        model = build_base_model(model_opt, fields, use_gpu(opt), checkpoint)
        model.eval()
        model.generator.eval()
        if shared_fields is None:
            shared_fields = fields
        if shared_model_opt is None:
            shared_model_opt = model_opt
        models.append(model)
    ensemble_model = EnsembleModel(models)
    return shared_fields, ensemble_model
def load_test_model(opt, dummy_opt, model_path=None):
    if model_path is None:
        model_path = opt.models[0]
    checkpoint = torch.load(model_path,
                            map_location=lambda storage, loc: storage)
    fields = load_fields_from_vocab(checkpoint['vocab'])

    model_opt = checkpoint['opt']

    for arg in dummy_opt:
        if arg not in model_opt:
            model_opt.__dict__[arg] = dummy_opt[arg]
    model = build_base_model(model_opt, fields, use_gpu(opt), checkpoint)
    model.eval()
    model.generator.eval()
    return fields, model