import tensorflow as tf from FaceAging import FaceAging from os import environ import argparse import model as M M.set_gpu('1') environ['TF_CPP_MIN_LOG_LEVEL'] = '3' def str2bool(v): if v.lower() in ('yes', 'true', 't', 'y', '1'): return True elif v.lower() in ('no', 'false', 'f', 'n', '0'): return False else: raise argparse.ArgumentTypeError('Boolean value expected.') parser = argparse.ArgumentParser(description='CAAE') parser.add_argument('--is_train', type=str2bool, default=True) parser.add_argument('--epoch', type=int, default=250, help='number of epochs') parser.add_argument('--dataset', type=str, default='UTKFace', help='training dataset name that stored in ./data') parser.add_argument('--savedir', type=str, default='save', help='dir of saving checkpoints and intermediate training results') parser.add_argument('--testdir', type=str, default='None', help='dir of testing images') parser.add_argument('--use_trained_model', type=str2bool, default=True, help='whether train from an existing model or from scratch') parser.add_argument('--use_init_model', type=str2bool, default=True, help='whether train from the init model if cannot find an existing model') FLAGS = parser.parse_args()
import tensorflow as tf from FaceAging import FaceAging from ops import * from scipy.misc import imread, imresize, imsave import model as M M.set_gpu('0') import os if not os.path.exists('./res/'): os.mkdir('./res/') sess = tf.Session() net = FaceAging(sess, is_training=False, size_batch=5) net.load_checkpoint() def generate(img, sample_gender, pref): for i in range(10): age = np.ones([len(img), 10], dtype=np.float32) age = age * -1. age[:, i] = 1. gen = net.session.run(net.G, feed_dict={ net.input_image: img, net.age: age, net.gender: sample_gender }) gen = gen + 1. gen = gen * 0.5
import network as N import numpy as np import model as M import tensorflow as tf import cv2 M.set_gpu('2') class recon(): def __init__(self, step): with tf.variable_scope('Input_holders'): self.inpholder = tf.placeholder(tf.float32, [None, step, 256, 256, 3]) self.step = step self.targetholder = tf.placeholder(tf.float32, [None, step, 256, 256, 3]) with tf.variable_scope('Head'): inp_split = tf.unstack(self.inpholder, axis=1) features = [] for i in range(len(inp_split)): features.append(N.conv_layers(inp_split[i], i != 0)) features = tf.stack(features, axis=1) lstm_out = M.SimpleLSTM(4 * 4 * 128).apply(features) with tf.variable_scope('Tail'): feat_split = tf.unstack(lstm_out, axis=1) # I try the last frame for now feat = feat_split[-1] A, C = N.deconv_layers(feat)
import AIM_gen import tensorflow as tf import numpy as np import model as M import cv2 M.set_gpu('3') aim_mod = AIM_gen.AIM_gen() # get data_reader import data_reader data_reader = data_reader.data_reader('outpt.txt') BSIZE = 32 ITER_PER_EPOC = 200000 // BSIZE EPOC = 50 MAX_ITER = ITER_PER_EPOC * EPOC ETA = M.ETA(MAX_ITER) ETA.start() for iteration in range(MAX_ITER + 1): img, age_fake, age = data_reader.get_train_batch(BSIZE) losses = aim_mod.train(img, age_fake, age, normalize=True) if iteration % 10 == 0: print('------ Iteration %d ---------' % iteration) aim_mod.display_losses(losses) print('ETA', ETA.get_ETA(iteration)) if iteration % 1000 == 0 and iteration > 0: aim_mod.save('%d.ckpt' % iteration)