Refactoring the training

parent 004fe191
......@@ -9,17 +9,16 @@ Neural net work error rates analizer
import numpy
import bob.measure
from tensorflow.core.framework import summary_pb2
from scipy.spatial.distance import cosine
class ExperimentAnalizer:
class SoftmaxAnalizer:
"""
Analizer.
"""
def __init__(self, data_shuffler, machine, session):
"""
Use the CNN as feature extractor for a n-class classification
Softmax analizer
** Parameters **
......@@ -36,15 +35,26 @@ class ExperimentAnalizer:
self.machine = machine
self.session = session
"""
placeholder_data, placeholder_labels = data_shuffler.get_placeholders(name="validation")
graph = machine.compute_graph(placeholder_data)
loss_validation = self.loss(validation_graph, validation_placeholder_labels)
tf.scalar_summary('loss', loss_validation, name="validation")
tf.scalar_summary('accuracy', loss_validation, name="validation")
merged_validation = tf.merge_all_summaries()
"""
def __call__(self, graph=None):
validation_graph = self.compute_graph(self.data_shuffler, name="validation")
predictions = numpy.argmax(self.session.run(network,
feed_dict={data_node: data[:]}), 1)
return 100. * numpy.sum(predictions == labels) / predictions.shape[0]
def __call__(self):
data, labels = self.data_shuffler.get_batch()
......
......@@ -47,23 +47,27 @@ class BaseDataShuffler(object):
self.indexes = numpy.array(range(self.n_samples))
numpy.random.shuffle(self.indexes)
self.data_placeholder = None
self.label_placeholder = None
def get_placeholders_forprefetch(self, name=""):
"""
Returns a place holder with the size of your batch
"""
data = tf.placeholder(tf.float32, shape=tuple([None] + list(self.shape[1:])), name=name)
labels = tf.placeholder(tf.int64, shape=[None, ])
return data, labels
if self.data_placeholder is None:
self.data_placeholder = tf.placeholder(tf.float32, shape=tuple([None] + list(self.shape[1:])), name=name)
self.label_placeholder = tf.placeholder(tf.int64, shape=[None, ])
return self.data_placeholder, self.label_placeholder
def get_placeholders(self, name=""):
"""
Returns a place holder with the size of your batch
"""
data = tf.placeholder(tf.float32, shape=self.shape, name=name)
labels = tf.placeholder(tf.int64, shape=self.shape[0])
return data, labels
if self.data_placeholder is None:
self.data_placeholder = tf.placeholder(tf.float32, shape=self.shape, name=name)
self.label_placeholder = tf.placeholder(tf.int64, shape=self.shape[0])
return self.data_placeholder, self.label_placeholder
def get_genuine_or_not(self, input_data, input_labels, genuine=True):
......
......@@ -95,6 +95,7 @@ def main():
loss = BaseLoss(tf.nn.sparse_softmax_cross_entropy_with_logits, tf.reduce_mean)
trainer = Trainer(architecture=architecture, loss=loss, iterations=ITERATIONS)
trainer.train(train_data_shuffler, validation_data_shuffler)
#trainer.train(train_data_shuffler)
else:
mlp = MLP(10, hidden_layers=[15, 20])
loss = BaseLoss(tf.nn.sparse_softmax_cross_entropy_with_logits, tf.reduce_mean)
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment