def creat_inference_graph(): images = tf.placeholder(dtype=tf.float32, shape=(None, 112, 112, 3), name='input_images') is_training_dropout = tf.constant(False, dtype=bool, shape=[], name='train_phase_dropout') is_training_bn = tf.constant(False, dtype=bool, shape=[], name='train_phase_bn') embds = get_embd(images, is_training_dropout, is_training_bn) embds = tf.identity(embds, 'embeddings') return embds
if __name__ == '__main__': args = get_args() if args.mode == 'build': print('building...') config = yaml.load(open(args.config_path)) images = tf.placeholder( dtype=tf.float32, shape=[None, config['image_size'], config['image_size'], 3], name='input_image') train_phase_dropout = tf.placeholder(dtype=tf.bool, shape=None, name='train_phase') train_phase_bn = tf.placeholder(dtype=tf.bool, shape=None, name='train_phase_last') embds, _ = get_embd(images, train_phase_dropout, train_phase_bn, config) print('done!') tf_config = tf.ConfigProto(allow_soft_placement=True) tf_config.gpu_options.allow_growth = True with tf.Session(config=tf_config) as sess: tf.global_variables_initializer().run() print('loading...') saver = tf.train.Saver(var_list=tf.trainable_variables()) saver.restore(sess, args.model_path) print('done!') batch_size = config['batch_size'] imgs, imgs_f, fns = load_image(args.read_path, config['image_size']) print('forward running...') embds_arr = run_embds(sess, imgs, batch_size, config['image_size'],
def inference(images, labels, is_training_dropout, is_training_bn, config): embds, end_points = get_embd(images, is_training_dropout, is_training_bn, config) logits = get_logits(embds, labels, config) end_points['logits'] = logits return embds, logits, end_points
def inference(images, labels, is_training_dropout, is_training_bn, config): embds = get_embd(images, is_training_dropout, is_training_bn) logits = get_logits(embds, labels, config) return embds, logits