def _test_dataset(): import sflow.py as py data = dataset_trainA(16) with tf.feeding() as (sess, coord): while not coord.should_stop(): py.plt.imshow(data.eval()) if not py.plot_pause(): break
def _test(): import sflow.py as py data = dataset(16) with tf.feeding() as (sess, coord): while not coord.should_stop(): d = sess.run(data) print(d.shape) py.plt.imshow(d) if not py.plt.plot_pause(): break
def train_test(): # model build data = helen.trainset(batch=16, threads=8) model = face_parse(data.image, data.label) optim = tf.train.AdamOptimizer(learning_rate=0.001) trainop = optim.minimize(model.loss) # train op tf.summary.scalar('loss', model.loss) # tf.summary_loss(model.losses) summary = tf.summary.merge_all() twriter = tf.summary.FileWriter('/tmp/face_parse/005') tf.global_variables_initializer().run() with tf.feeding() as (sess, coord): i = 0 while True: s, loss, _ = sess.run([summary, model.loss, trainop]) # loss = sess.run([model.loss, trainop]) print(loss) twriter.add_summary(s, i) i += 1
# remove background image bg = 1. - label[:, :, :, :1] image = image * bg return tf.dic(image=image, label=label) def label_to_rgb(label): """ utility for viewing label in a glance :param label: [b x h x w x 11] :return: [b x h x w x 3] """ pass if __name__ == '__main__': import sflow.tf as tf d = trainset(16) import matplotlib.pyplot as plt with tf.feeding() as (sess, coord): while not coord.should_stop(): out = sess.run(d) print(out.image.shape) print(out.label.shape) plt.imshow(out.image[0]) plt.show()