def train(self):
data = Data(self.train_dat, self.train_lab)
batch_num = self.length/self.batch_size if self.length%self.batch_size == 0 else self.length/self.batch_size + 1
model = self.add_model()
with self.sess as sess:
tf.initialize_all_variables().run()
for ite in range(self.iterations):
print "Iteration {}".format(ite)
cost = 0.
pbar = pb.ProgressBar(widgets=[pb.Percentage(), pb.Bar(), pb.ETA()], maxval=batch_num).start()
for i in range(batch_num):
batch_x, batch_y = data.next_batch(self.batch_size)
c, _ = self.sess.run([model['loss'], model['optimizer']], feed_dict={model['train_x']:batch_x, model['train_y']:batch_y, model['p_keep_dens']:0.75})
cost += c / batch_num
pbar.update(i+1)
pbar.finish()
print ">>cost: {}".format(cost)
t_acc, d_acc = self.eval(model, 3000)
# early stop
if t_acc >= 0.995 and d_acc >= 0.995:
break
self.predict(model)
评论列表
文章目录