help="test on old and augmented test datasets")
parser.add_argument('--finetune', default=False, type=lambda x: (str(x).lower() in ['true','1', 'yes']), \
    help="finetune mode")
parser.add_argument('--use_kfac', default=False, type=lambda x: (str(x).lower() in ['true','1', 'yes']), \
    help="usek fac true gradient")
parser.add_argument('--log', default='',
                    help="test log postfix")

if __name__ == '__main__':
    # Set the random seed for the whole graph
    tf.set_random_seed(230)
    # Load the parameters
    args = parser.parse_args()
    json_path = os.path.join(args.model_dir, 'params.json')
    assert os.path.isfile(json_path), "No json configuration file found at {}".format(json_path)
    params = Params(json_path)
    params.dict['loss_fn'] = args.loss_fn
    params.dict['collect'] = False
    params.dict['use_kfac'] = args.use_kfac
    params.dict['finetune'] = args.finetune  
    params.dict['training_keep_prob'] = 1.0
    # Load the parameters from the dataset, that gives the size etc. into params
    json_path = os.path.join(args.data_dir, 'dataset_params.json')
    assert os.path.isfile(json_path), "No json file found at {}, run build.py".format(json_path)
    params.update(json_path)
    # Set the logger
    set_logger(os.path.join(args.model_dir, 'test{}.log'.format(args.log)))
    # # Get paths for tfrecords
    dataset = 'test'
    if args.combine:
        params.dict['test_size'] = params.dict['test_size'] * 2
Beispiel #2
0
# usage: python main.py --restore_dir experiments/base_model/best_weights
parser.add_argument(
    '--restore_dir',
    default=None,  # experimens/base_model/best_weights
    help="Optional, directory containing weights to reload")

if __name__ == '__main__':
    tf.reset_default_graph()
    # Set the random seed for the whole graph for reproductible experiments
    tf.set_random_seed(230)
    # Load the parameters from the experiment params.json file in model_dir
    args = parser.parse_args()
    json_path = os.path.join(args.model_dir, 'params.json')
    assert os.path.isfile(
        json_path), "No json configuration file found at {}".format(json_path)
    params = Params(json_path)
    # print('params.mlp_sizes\n', params.mlp_sizes)
    # print('params.top_ks\n', params.top_ks)
    if params.mlp_sizes is None or len(params.mlp_sizes) == 0:
        logging.error(
            'mlp_sizes are not set correctly, at least one MLP layer is required'
        )
    params.dict['loss_fn'] = args.loss_fn

    # # Load the parameters from the dataset, that gives the size etc. into params
    json_path = os.path.join(args.data_dir, 'dataset_params.json')
    assert os.path.isfile(
        json_path
    ), "No json file found at {}, please run prepare_data.py".format(json_path)
    params.update(json_path)
    # Set the logger
Beispiel #3
0
                    default='data/mnist',
                    help="Directory containing the dataset")
parser.add_argument('--sprite_filename',
                    default='experiments/mnist_10k_sprite.png',
                    help="Sprite image for the projector")

if __name__ == '__main__':
    tf.reset_default_graph()
    tf.logging.set_verbosity(tf.logging.INFO)

    # Load the parameters from json file
    args = parser.parse_args()
    json_path = os.path.join(args.model_dir, 'params.json')
    assert os.path.isfile(
        json_path), "No json configuration file found at {}".format(json_path)
    params = Params(json_path)

    # Define the model
    tf.logging.info("Creating the model...")
    config = tf.estimator.RunConfig(
        tf_random_seed=230,
        model_dir=args.model_dir,
        save_summary_steps=params.save_summary_steps)
    estimator = tf.estimator.Estimator(model_fn, params=params, config=config)

    # EMBEDDINGS VISUALIZATION

    # Compute embeddings on the test set
    tf.logging.info("Predicting")
    predictions = estimator.predict(
        lambda: test_input_fn(args.data_dir, params))
Beispiel #4
0
parser.add_argument('--restore_dir', default=None,
          help="Optional, directory containing weights to reload before training")


if __name__ == '__main__':
  args = parser.parse_args()
  args.model_dir = os.path.join("experiments", args.data_dir, args.model_dir)
  if args.restore_dir is not None:
    args.restore_dir = os.path.join("experiments", args.data_dir, args.restore_dir)
  args.data_dir = os.path.join("data", args.data_dir)
  print(args)
  if not os.path.isdir(args.model_dir):
    os.makedirs(args.model_dir)
  
  # Load the parameters from the experiment params.json file in model_dir
  params = Params('params.json')
  # Load the parameters from the dataset, that gives the size etc. into params
  json_path = os.path.join(args.data_dir, 'dataset_params.json')
  assert os.path.isfile(json_path), "No json file found at {}, run build_vocab.py".format(json_path)
  params.update(json_path)
  
  # Set the random seed for the whole graph for reproductible experiments
  tf.set_random_seed(params.seed)

  # Save the params in model_dir
  json_path = os.path.join(args.model_dir, 'params.json')
  params.save(json_path)
  
  num_oov_buckets = params.num_oov_buckets # number of buckets for unknown words

  # Check that we are not overwriting some previous experiment
    help="usek fac true gradient")
parser.add_argument('--log', default='',
                    help="train log postfix")

if __name__ == '__main__':
    # Train the model  
    tf.reset_default_graph()
    # Set the random seed for the whole graph for reproductible experiments
    tf.set_random_seed(230)
    # Load the parameters from the experiment params.json file in model_dir
    args = parser.parse_args()
    json_path = os.path.join(args.model_dir, 'params.json')
    assert os.path.isfile(json_path), "No json configuration file found at {}".format(json_path)
    # Set the logger
    set_logger(os.path.join(args.model_dir, 'collect{}.log'.format(args.log)))
    params = Params(json_path)
    params.dict['loss_fn'] = args.loss_fn
    params.dict['collect'] = True
    params.dict['finetune'] = args.finetune
    params.dict['use_kfac'] = args.use_kfac
    # Load the parameters from the dataset, that gives the size etc. into params
    json_path = os.path.join(args.data_dir, 'dataset_params.json')
    assert os.path.isfile(json_path), "No json file found at {}, \
    please generate tfrecords".format(json_path)
    params.update(json_path)
    global_epoch = 0
    args.restore_dir = 'best_weights'
    path_train_tfrecords = os.path.join(args.data_dir, 'train-{}'.format(args.train_range) + args.tfrecords_filename)
    path_sample_train_tfrecords = os.path.join(args.data_dir, 'sample' + args.tfrecords_filename)    
    training_files = glob.glob(path_train_tfrecords)
    if args.train_range == '[0-4]':
    # Write parameters in json file
    json_path = os.path.join(model_dir, 'params.json')
    params.save(json_path)

    # Launch training with this config
    cmd = "{python} train.py --model_dir {model_dir} --data_dir {data_dir}".format(python=PYTHON,
            model_dir=model_dir, data_dir=data_dir)
    print(cmd)
    check_call(cmd, shell=True)


if __name__ == "__main__":
    # Load the "reference" parameters from parent_dir json file
    args = parser.parse_args()
    json_path = os.path.join(args.parent_dir, 'params.json')
    assert os.path.isfile(json_path), "No json configuration file found at {}".format(json_path)
    params = Params(json_path)

    # Perform hypersearch over one parameter
    learning_rates = [1e-4, 1e-3, 1e-2]
   

    for learning_rate in learning_rates:
        # Modify the relevant parameter in params
        params.learning_rate = learning_rate
     

        # Launch job (name has to be unique)
        job_name = "learning_rate_{}".format(learning_rate)
        launch_training_job(args.parent_dir, args.data_dir, job_name, params)
Beispiel #7
0
parser.add_argument(
    '--restore_from',
    default=None,
    help=
    "Optional, directory or file containing weights to reload before training")

if __name__ == '__main__':
    # Set the random seed for the whole graph for reproductible experiments
    tf.set_random_seed(0)

    # Load the parameters from json file
    args = parser.parse_args()
    json_path = os.path.join(args.model_dir, 'params.json')
    assert os.path.isfile(
        json_path), "No json configuration file found at {}".format(json_path)
    params = Params(json_path)

    # Check that we are not overwriting some previous experiment
    # Comment these lines if you are developing your model and don't care about overwritting
    model_dir_has_best_weights = os.path.isdir(
        os.path.join(args.model_dir, "best_weights"))
    overwritting = model_dir_has_best_weights and args.restore_from is None
    assert not overwritting, "Weights found in model_dir, aborting to avoid overwrite"

    # Set the logger
    set_logger(os.path.join(args.model_dir, 'train.log'))

    # Create the input data pipeline
    logging.info("Creating the datasets...")
    data_dir = args.data_dir
    train_data_dir = os.path.join(data_dir, "train")
Beispiel #8
0
                    help="Directory containing the dataset")
parser.add_argument(
    '--restore_from',
    default='best_weights',
    help="Subdirectory of model dir or file containing the weights")

if __name__ == '__main__':
    # Set the random seed for the whole graph
    tf.set_random_seed(230)

    # Load the parameters
    args = parser.parse_args()
    json_path = os.path.join(args.model_dir, 'params.json')
    assert os.path.isfile(
        json_path), "No json configuration file found at {}".format(json_path)
    params = Params(json_path)

    # Load the parameters from the dataset, that gives the size etc. into params
    json_path = os.path.join(args.data_dir, 'dataset_params.json')
    assert os.path.isfile(
        json_path), "No json file found at {}, run build.py".format(json_path)
    params.update(json_path)

    # Set the logger
    set_logger(os.path.join(args.model_dir, 'evaluate.log'))

    # Get paths for vocabularies and dataset
    path_eval_x = os.path.join(args.data_dir, 'dev.x')
    path_eval_y = os.path.join(args.data_dir, 'dev.y')

    # Create the input data pipeline