示例#1
0
def get_image_agent(model_path):
    log_dir = Path(model_path).parent
    config = bzu.load_json(str(log_dir / 'config.json'))
    agent_args = config.get('agent_args', dict())
    model = image.ImagePolicyModelSS(**config['model_args'])
    model.load_state_dict(torch.load(str(model_path)))
    model.eval()
    agent_args['model'] = model
    return image.ImageAgent(**agent_args)
示例#2
0
def load_model(model_path):
''' Carica i pesi del modello preaddestrato e li inserisce nella classe PytorchClassifier, che fa da interfaccia tra modello e ART'''
    config = bzu.load_json('/'.join([model_path, 'config.json']))
    model_args = config['model_args']
    model_name = model_args['model']
    model_class = image.ImagePolicyModelSS
    model = model_class(**config['model_args'])
    model.load_state_dict(torch.load('/'.join([model_path, 'model-10.th'])))
    criterion = nn.CrossEntropyLoss()
    optimizer = optim.Adam(model.parameters(),lr=0.0001)
    classifier = PyTorchClassifier(model=model, loss=criterion,optimizer=optimizer, input_shape=(3, 160, 384),
    nb_classes=10,device_type='gpu')
    return classifier
示例#3
0
def load_model(model_path):

    config = bzu.load_json('/'.join([model_path, 'config.json']))
    model_args = config['model_args']
    model_name = model_args['model']
    model_class = image.ImagePolicyModelSS
    model = model_class(**config['model_args'])
    model.load_state_dict(torch.load('/'.join([model_path, 'model-10.th'])))
    criterion = nn.CrossEntropyLoss()
    optimizer = optim.Adam(model.parameters(),lr=0.0001)
    classifier = PyTorchClassifier(model=model, loss=criterion,optimizer=optimizer, input_shape=(3, 160, 184),
    nb_classes=10,device_type='gpu')
    return classifier
def run(model_path,
        port,
        suite,
        big_cam,
        seed,
        autopilot,
        resume,
        max_run=10,
        show=False):
    log_dir = model_path.parent
    config = bzu.load_json(str(log_dir / 'config.json'))

    total_time = 0.0

    for suite_name in get_suites(suite):
        tick = time.time()
        import pdb
        pdb.set_trace()
        benchmark_dir = log_dir / 'benchmark' / model_path.stem / (
            '%s_seed%d' % (suite_name, seed))
        benchmark_dir.mkdir(parents=True, exist_ok=True)

        with make_suite(suite_name, port=port, big_cam=big_cam) as env:
            agent_maker = _agent_factory_hack(model_path, config, autopilot)

            run_benchmark(agent_maker,
                          env,
                          benchmark_dir,
                          seed,
                          autopilot,
                          resume,
                          max_run=max_run,
                          show=show)

        elapsed = time.time() - tick
        total_time += elapsed

        print('%s: %.3f hours.' % (suite_name, elapsed / 3600))

    print('Total time: %.3f hours.' % (total_time / 3600))