Пример #1
0
def load_program_generator(path, model_type='PG+EE'):
    checkpoint = load_cpu(path)
    kwargs = checkpoint['program_generator_kwargs']
    state = checkpoint['program_generator_state']
    if model_type == 'FiLM':
        print('Loading FiLMGen from ' + path)
        kwargs = get_updated_args(kwargs, FiLMGen)
        model = FiLMGen(**kwargs)
    else:
        print('Loading PG from ' + path)
        model = Seq2Seq(**kwargs)
    model.load_state_dict(state)
    return model, kwargs
Пример #2
0
def load_program_generator(path, model_type="PG+EE"):
    checkpoint = load_cpu(path)
    kwargs = checkpoint["program_generator_kwargs"]
    state = checkpoint["program_generator_state"]
    if model_type == "FiLM":
        print("Loading FiLMGen from " + path)
        kwargs = get_updated_args(kwargs, FiLMGen)
        model = FiLMGen(**kwargs)
    else:
        print("Loading PG from " + path)
        model = Seq2Seq(**kwargs)
    model.load_state_dict(state)
    return model, kwargs
Пример #3
0
def load_program_generator(path, model_type='PG+EE'):
    checkpoint = load_cpu(path)
    kwargs = checkpoint['program_generator_kwargs']
    state = checkpoint['program_generator_state']
    if model_type == 'FiLM':
        print('Loading FiLMGen from ' + path)
        kwargs = get_updated_args(kwargs, FiLMGen)
        model = FiLMGen(**kwargs)
    else:
        print('Loading PG from ' + path)
        model = Seq2Seq(**kwargs)
    state_stemed = {}
    for k, v in state.iteritems():
        k_new = '.'.join(k.split('.')[1:])
        state_stemed[k_new] = v
    model.load_state_dict(state_stemed)
    return model, kwargs
Пример #4
0
def load_program_generator(path):
    checkpoint = load_cpu(path)
    model_type = checkpoint['args']['model_type']
    kwargs = checkpoint['program_generator_kwargs']
    state = checkpoint['program_generator_state']
    if model_type in ['FiLM', 'MAC', 'RelNet', 'Control-EE']:
        model = FiLMGen(**kwargs)
    elif model_type == 'PG+EE' or model_type == 'PG':
        if checkpoint['args']['ns_vqa']:
            model = Seq2seqParser(checkpoint['vocab'])
        else:
            model = Seq2SeqAtt(**kwargs)
    else:
        model = None
    if model is not None:
        model.load_state_dict(state)
    return model, kwargs
Пример #5
0
def load_program_generator(path, model_type='PG+EE'):
    checkpoint = load_cpu(path)
    kwargs = checkpoint['program_generator_kwargs']
    state = checkpoint['program_generator_state']
    if model_type == 'FiLM':
        print('Loading FiLMGen from ' + path)
        kwargs = get_updated_args(kwargs, FiLMGen)
        model = FiLMGen(**kwargs)
        new_state_dict = OrderedDict()
        for k, v in state.items():
            name = k[7:]  # remove `module.`
            new_state_dict[name] = v
        state = new_state_dict
    else:
        print('Loading PG from ' + path)
        model = Seq2Seq(**kwargs)
    model.load_state_dict(state)
    return model, kwargs
Пример #6
0
def load_program_generator(path):
    checkpoint = load_cpu(path)
    model_type = checkpoint['args']['model_type']
    kwargs = checkpoint['program_generator_kwargs']
    state = checkpoint['program_generator_state']
    if model_type in ['FiLM', 'MAC', 'RelNet']:
        kwargs = get_updated_args(kwargs, FiLMGen)
        model = FiLMGen(**kwargs)
    elif model_type == 'PG+EE':
        if kwargs.rnn_attention:
            model = Seq2SeqAtt(**kwargs)
        else:
            model = Seq2Seq(**kwargs)
    else:
        model = None
    if model is not None:
        model.load_state_dict(state)
    return model, kwargs