def validate(self, data_provider, graph, epochs=35, verbose=True): if verbose: print "epochs: %d" % epochs with tf.Session(graph=graph, config=self.config) as sess: sess.run(self.init) stats, keys = initStats(epochs) runTimes = [] for e in range(epochs): (valid_error, valid_accuracy), runTime = getRunTime(lambda: validateEpoch( inputs=self.inputs, targets=self.targets, sess=sess, valid_data=data_provider, error=self.error, accuracy=self.accuracy, extraFeedDict={self.training: False}, keep_prob_keys=[self.keep_prob_input, self.keep_prob_hidden] )) runTimes.append(runTime) if verbose: print 'End epoch %02d (%.3f secs): err(valid)=%.2f, acc(valid)=%.2f, ' % \ (e + 1, runTime, valid_error, valid_accuracy) stats = gatherStats(e, 0., 0., valid_error, valid_accuracy, stats) if verbose: print return stats, keys, runTimes
def trainAndValidate(self, dataset_filename, logits_filename, graph, input_keep_prob, hidden_keep_prob, epochs=35, verbose=True): if verbose: print "epochs: %d" % epochs print "input_keep_prob: %f" % input_keep_prob print "hidden_keep_prob: %f" % hidden_keep_prob train_data, valid_data = self.loadAndGetDataProviders(dataset_filename=dataset_filename, logits_filename=logits_filename) with tf.Session(graph=graph, config=self.config) as sess: sess.run(self.init) stats, keys = initStats(epochs) for e in range(epochs): (train_error, train_accuracy), runTime = getRunTime( lambda: self.trainEpoch( inputs=self.inputs, targets=self.targets, sess=sess, train_data=train_data, train_step=self.train_step, error=self.error, accuracy=self.accuracy, extraFeedDict={ self.keep_prob_input: input_keep_prob, self.keep_prob_hidden: hidden_keep_prob, self.training: True }) ) # print 'End epoch %02d (%.3f secs): err(train)=%.2f acc(train)=%.2f' % (e+1, runTime, train_error,train_accuracy) if (e + 1) % 1 == 0: valid_error, valid_accuracy = validateEpoch( inputs=self.inputs, targets=self.targets, sess=sess, valid_data=valid_data, error=self.error, accuracy=self.accuracy, extraFeedDict={self.training: False}, keep_prob_keys=[self.keep_prob_input, self.keep_prob_hidden] ) # print((' ' * 27) + 'err(valid)={0:.2f} acc(valid)={1:.2f}'.format(valid_error, valid_accuracy)) if verbose: print 'End epoch %02d (%.3f secs):err(train)=%.2f,acc(train)=%.2f,err(valid)=%.2f,acc(valid)=%.2f, ' % \ (e + 1, runTime, train_error, train_accuracy, valid_error, valid_accuracy) stats = gatherStats(e, train_error, train_accuracy, valid_error, valid_accuracy, stats) if verbose: print return stats, keys
def trainAndValidate(self, train_data, valid_data, state_size, graph, epochs=35, verbose=True, logits_gathering_enabled=False, test_data=None): """onLogits(sess, logits, create_feed_dict, filename = 'msd-25-submission.csv')""" if verbose: print "epochs: %d" % epochs print "rnn steps: %d" % train_data.num_steps print "state size: %d" % state_size logits_dict = None max_valid_acc = 0. with tf.Session(graph=graph, config=self.config) as sess: sess.run(self.init) stats, keys = initStats(epochs) for e in range(epochs): (train_error, train_accuracy), runTime = getRunTime( lambda: self.trainEpoch(state_size=state_size, sess=sess, train_data=train_data, extraFeedDict={ self.training: True }) ) # if (e + 1) % 1 == 0: #better calc it always valid_error, valid_accuracy = self.validateEpoch( state_size=state_size, sess=sess, valid_data=valid_data, extraFeedDict={ self.training: False } ) if valid_accuracy > max_valid_acc: if logits_gathering_enabled: logits_dict, _, _ = self.getLogits( batch_size=self.batch_size, data_provider=valid_data, sess=sess, state_size=state_size ) if test_data is not None: self.createKaggleFile(batch_size=self.batch_size, data_provider=test_data, sess=sess, state_size=state_size) max_valid_acc = valid_accuracy if verbose: print 'End epoch %02d (%.3f secs): err(train)=%.2f, acc(train)=%.2f, err(valid)=%.2f, acc(valid)=%.2f, ' % \ (e + 1, runTime, train_error, train_accuracy, valid_error, valid_accuracy) stats = gatherStats(e, train_error, train_accuracy, valid_error, valid_accuracy, stats) if verbose: print if logits_gathering_enabled: return stats, keys, logits_dict else: return stats, keys
def trainAndValidate(self, train_data, valid_data, state_size, graph, num_steps, epochs=35, verbose=True): if verbose: print "epochs: %d" % epochs print "rnn steps: %d" % num_steps print "state size: %d" % state_size with tf.Session(graph=graph, config=self.config) as sess: sess.run(self.init) stats, keys = initStats(epochs) for e in range(epochs): (train_error, train_accuracy), runTime = getRunTime( lambda: self.trainEpoch(inputs=self.inputs, targets=self.targets, sess=sess, train_data=train_data, train_step=self.train_step, error=self.error, accuracy=self.accuracy)) if (e + 1) % 1 == 0: valid_error, valid_accuracy = validateEpoch( inputs=self.inputs, targets=self.targets, sess=sess, valid_data=valid_data, error=self.error, accuracy=self.accuracy) if verbose: print 'End epoch %02d (%.3f secs): err(train)=%.2f, acc(train)=%.2f, err(valid)=%.2f, acc(valid)=%.2f, ' % \ (e + 1, runTime, train_error, train_accuracy, valid_error, valid_accuracy) stats = gatherStats(e, train_error, train_accuracy, valid_error, valid_accuracy, stats) if verbose: print return stats, keys
def validate(self, data_provider, state_size, graph, epochs=35, verbose=True): """onLogits(sess, logits, create_feed_dict, filename = 'msd-25-submission.csv')""" if verbose: print "epochs: %d" % epochs print "rnn steps: %d" % data_provider.num_steps print "state size: %d" % state_size with tf.Session(graph=graph, config=self.config) as sess: sess.run(self.init) stats, keys = initStats(epochs) for e in range(epochs): (valid_error, valid_accuracy), runTime = getRunTime( lambda: self.validateEpoch(state_size=state_size, sess=sess, valid_data=data_provider)) if verbose: print 'End epoch %02d (%.3f secs): err(valid)=%.2f, acc(valid)=%.2f, ' % \ (e + 1, runTime, valid_error, valid_accuracy) stats = gatherStats(e, train_error=0., train_accuracy=0., valid_error=valid_error, valid_accuracy=valid_accuracy, stats=stats) if verbose: print return stats, keys
def trainAndValidate(graph, init, error, accuracy, inputs, targets, training, keep_probs, train_step, input_keep_prob, hidden_keep_prob, train_data, valid_data, epochs=35, verbose=True): if verbose: print "epochs: %d" % epochs print "input_keep_prob: %f" % input_keep_prob print "hidden_keep_prob: %f" % hidden_keep_prob keep_prob_dict = constructProbs(keep_probs, cur_input_prob=input_keep_prob, cur_hidden_prob=hidden_keep_prob) with tf.Session(graph=graph, config=config) as sess: sess.run(init) stats, keys = initStats(epochs) for e in range(epochs): (train_error, train_accuracy), runTime = getRunTime(lambda: trainEpoch( inputs, targets, sess, train_data, train_step, error, accuracy, extraFeedDict=merge_dicts(keep_prob_dict, {training: True}))) #print 'End epoch %02d (%.3f secs): err(train)=%.2f acc(train)=%.2f' % (e+1, runTime, train_error,train_accuracy) if (e + 1) % 1 == 0: valid_error, valid_accuracy = validateEpoch( inputs, targets, sess, valid_data, error, accuracy, extraFeedDict={training: False}, keep_prob_keys=keep_probs) #print((' ' * 27) + 'err(valid)={0:.2f} acc(valid)={1:.2f}'.format(valid_error, valid_accuracy)) if verbose: print 'End epoch %02d (%.3f secs): err(train)=%.2f, acc(train)=%.2f, err(valid)=%.2f, acc(valid)=%.2f, ' % ( e + 1, runTime, train_error, train_accuracy, valid_error, valid_accuracy) stats = gatherStats(e, train_error, train_accuracy, valid_error, valid_accuracy, stats) if verbose: print return stats, keys