def from_checkpoint_directory(path): # type: (Path) -> MachineWithSingleNetwork configuration = np.load(path / 'experiment-configuration.npy', allow_pickle=True).item() # type: Any data_directory = configuration['args'].data_directory # type: str dataset = load_data(data_directory, shuffle=False, load_only_dicts=True) with tf.variable_scope(configuration['which_network']): raw_model = seq2seq_model(dataset.vocabulary_size, 50, 28, cell_type='LSTM', memory_dim=300, num_layers=4, dropout=0) gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.9) session = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)) best = MachineWithSingleNetwork.get_best_checkpoint_identifier(path) best = str(path / 'best' / 'saved-model-attn-{}'.format(best)) raw_model.load_parameters(session, best) return MachineWithSingleNetwork(configuration=configuration, dataset=dataset, raw_model=raw_model, tf_session=session)
best_checkpoint = None for checkpoint_name in os.listdir( os.path.join(args.checkpoint_directory, 'best')): if 'meta' in checkpoint_name: this_checkpoint = int(checkpoint_name[17:].split('.')[0]) if best_checkpoint is None or this_checkpoint > best_checkpoint: best_checkpoint = this_checkpoint print "Resuming at", best_checkpoint, "..." else: best_checkpoint = args.resume_at # Load data dataset = load_data(args.data_directory, shuffle=False, load_only_dicts=True) dictionary = dataset.get_tl_dictionary() # Build the network # scope = 'typo' if 'typo' in args.data_directory else 'ids' scope = 'typo' with tf.variable_scope(scope): seq2seq = model( dataset.vocabulary_size, args.embedding_dim, args.max_output_seq_len, cell_type=args.cell_type, memory_dim=args.memory_dim, num_layers=args.num_layers, dropout=0,