Ejemplo n.º 1
0
    config.restart = True

    # copy over new num_epochs and lr schedule
    config.num_epochs = given_config.num_epochs
    config.lr_schedule = given_config.lr_schedule

    if not hasattr(config, "kmeans_on_features"):
        config.kmeans_on_features = False

else:
    print("Config: %s" % config_to_str(config))

# Data, nets, optimisers -------------------------------------------------------

dataloader_original, dataloader_positive, dataloader_negative, \
dataloader_test = make_triplets_data(config)

train_dataloaders = [
    dataloader_original, dataloader_positive, dataloader_negative
]

net = archs.__dict__[config.arch](config)
if config.restart:
    model_path = os.path.join(config.out_dir, "latest_net.pytorch")
    taking_best = not os.path.exists(model_path)
    if taking_best:
        print("using best instead of latest")
        model_path = os.path.join(config.out_dir, "best_net.pytorch")

    net.load_state_dict(
        torch.load(model_path, map_location=lambda storage, loc: storage))
    assert config.model_ind == given_config.model_ind
    config.restart = True

    # copy over new num_epochs and lr schedule
    config.num_epochs = given_config.num_epochs
    config.lr_schedule = given_config.lr_schedule

    if not hasattr(config, "kmeans_on_features"):
        config.kmeans_on_features = False

else:
    print("Config: %s" % config_to_str(config))

# Data, nets, optimisers -------------------------------------------------------

dataloader_original, dataloader_positive, dataloader_negative, dataloader_test = make_triplets_data(
    config)

train_dataloaders = [
    dataloader_original, dataloader_positive, dataloader_negative
]

net = archs.__dict__[config.arch](config)
taking_best = None
if config.restart:
    model_path = os.path.join(config.out_dir, "latest_net.pytorch")
    taking_best = not os.path.exists(model_path)
    if taking_best:
        print("using best instead of latest")
        model_path = os.path.join(config.out_dir, "best_net.pytorch")

    net.load_state_dict(