Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions Omniglot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@
from MANN.Utils.Metrics import accuracy_instance
from MANN.Utils.tf_utils import update_tensor

def omniglot():
def omniglot(load_model=False):

sess = tf.InteractiveSession()
saver = tf.train.Saver()

input_ph = tf.placeholder(dtype=tf.float32, shape=(16,50,400)) #(batch_size, time, input_dim)
target_ph = tf.placeholder(dtype=tf.int32, shape=(16,50)) #(batch_size, time)(label_indices)
if(load_model):
ckpt = tf.train.get_checkpoint_state('./saved/')
if ckpt and ckpt.model_checkpoint_path:
saver.restore(sess, ckpt.model_checkpoint_path)
else:
print("No Checkpoint found, setting load to false")
load_model = False

##Global variables for Omniglot Problem
nb_reads = 4
Expand All @@ -26,6 +32,9 @@ def omniglot():
batch_size = 16
nb_samples_per_class = 10

input_ph = tf.placeholder(dtype=tf.float32, shape=(batch_size, nb_class * nb_samples_per_class, input_size)) #(batch_size, time, input_dim)
target_ph = tf.placeholder(dtype=tf.int32, shape=(batch_size, nb_class * nb_samples_per_class)) #(batch_size, time)(label_indices)

#Load Data
generator = OmniglotGenerator(data_folder='./data/omniglot', batch_size=batch_size, nb_samples=nb_class, nb_samples_per_class=nb_samples_per_class, max_rotation=0., max_shift=0., max_iter=None)
output_var, output_var_flatten, params = memory_augmented_neural_network(input_ph, target_ph, batch_size=batch_size, nb_class=nb_class, memory_shape=memory_shape, controller_size=controller_size, input_size=input_size, nb_reads=nb_reads)
Expand Down Expand Up @@ -74,8 +83,8 @@ def omniglot():
t0 = time.time()
all_scores, scores, accs = [],[],np.zeros(generator.nb_samples_per_class)


sess.run(tf.global_variables_initializer())
if(!load_model):
sess.run(tf.global_variables_initializer())

print 'Training the model'

Expand All @@ -102,6 +111,7 @@ def omniglot():
print(accs / 100.0)
print('Episode %05d: %.6f' % (i, np.mean(score)))
scores, accs = [], np.zeros(generator.nb_samples_per_class)
saver.save(sess, './saved/model.ckpt', global_step=i+1)


except KeyboardInterrupt:
Expand Down