Beispiel #1
0
def build_encoder(image, is_training):

    context = tf.identity(efficientnet_builder.build_model_base(
        image, 'efficientnet-' + flags.model, is_training),
                          name='context')

    return context
Beispiel #2
0
def _get_efficientnet(images_tensor,
                      model_name: str,
                      training=True,
                      model_ckpt: str = None):
    """
    Get efficientnet
    Args:
        images_tensor: input tensor
        model_name: name of model
        training: bool if it is for training
        model_ckpt: checkpoint file of model

    Returns:
        efficientnet feature extractor

    """
    with tf.variable_scope("Preprocess"):
        images_tensor = tf.cast(images_tensor, dtype=tf.float32)
        images_tensor -= tf.constant(efficientnet_builder.MEAN_RGB,
                                     shape=[1, 1, 3],
                                     dtype=images_tensor.dtype)
        images_tensor /= tf.constant(efficientnet_builder.STDDEV_RGB,
                                     shape=[1, 1, 3],
                                     dtype=images_tensor.dtype)

    features, _ = efficientnet_builder.build_model_base(images_tensor,
                                                        model_name=model_name,
                                                        training=training)

    if model_ckpt:
        saver = tf.train.Saver()
        sess = K.get_session()
        saver.restore(sess, model_ckpt)

    return features
Beispiel #3
0
def build_model(features, is_training):
    """Build model with input features."""
    features -= tf.constant(MEAN_RGB, shape=[1, 1, 3], dtype=features.dtype)
    features /= tf.constant(STDDEV_RGB, shape=[1, 1, 3], dtype=features.dtype)
    out, _ = efficientnet_builder.build_model_base(features, model_name,
                                                   is_training)
    return out
Beispiel #4
0
 def build_model():
     endpoints, _ = efficientnet_builder.build_model_base(
         features,
         model_name=FLAGS.model_name,
         training=is_training,
         override_params=override_params,
         # model_dir=FLAGS.model_dir
     )
     return endpoints
Beispiel #5
0
import efficientnet_builder
from tensorflow.keras.layers import Input

input_size = 224
input_image = Input(shape=(input_size, input_size, 3))

features, endpoints = efficientnet_builder.build_model_base(input_image,
                                                            'efficientnet-b0',
                                                            training=False)
Beispiel #6
0
    """

    # input as panda
    #input_name = 'panda'
    input_name = 'labrador'
    import imageio
    images = imageio.imread("%s.jpg" % input_name)
    images = np.reshape(images,
                        (1, images.shape[0], images.shape[1], images.shape[2]))
    images = images.astype(np.float32)
    print(images.shape, images.dtype)

    images = tf.convert_to_tensor(images)
    print(images.shape, images.dtype)
    model_name = 'efficientnet-b0'
    features, endpoints = efficientnet_builder.build_model_base(
        images=images, model_name=model_name, training=True)

    print(type(features))
    print(type(endpoints))

    endpoint_tensors = []
    for i in range(1, 6):
        endpoint_tensors.append(endpoints['reduction_%d' % i])

    endpoint_numpys = []

    sess = tf.Session()
    with sess.as_default():
        init = tf.global_variables_initializer()
        sess.run(init)
        features_numpy = features.eval()
Beispiel #7
0
    imga=np.reshape(imga,[1,56,56,3])
    test=np.concatenate([test,imga],axis=0)
test=2*(test/255-0.5)

input_x=tf.placeholder(tf.float32,[batch_size,224,224,3],name='input_x')
low=tf.placeholder(tf.float32,[batch_size,56,56,3],name='low')
global_step=tf.Variable(0,trainable=False,name='global_step')
start_learning_rate=0.0001
learning_rate=tf.train.exponential_decay(start_learning_rate,global_step=global_step,decay_steps=10000,decay_rate=0.87,staircase=False)
learning_rate1=tf.train.exponential_decay(start_learning_rate,global_step=global_step,decay_steps=10000,decay_rate=0.87,staircase=False)
beta1=0.9
beta2=0.999
real=input_x
fake=generator(low,reuse=False)
all_im=tf.concat([real,fake],axis=0)
features,endpoints=efficientnet_builder.build_model_base(all_im,'efficientnet-b4',training=False)
picture=tf.multiply(tf.add(tf.divide(fake,2),0.5),255,name='picture')

noise=PSNR(real,fake)
all_feature=endpoints['reduction_5']
real_feature=all_feature[0:2]
fake_feature=all_feature[2:4]

d_loss,g_loss,content_loss=inference_loss(real,fake,real_feature,fake_feature)
loss=tf.add(tf.add(d_loss,g_loss),content_loss)
dop,gop,cop=model_optimizer(d_loss,g_loss,content_loss,learning_rate1,learning_rate,beta1,beta2,global_step)
init=tf.global_variables_initializer()
tf.get_collection("nodes")
tf.add_to_collection("nodes",input_x)
tf.add_to_collection("nodes",picture)
saver=tf.train.Saver()
Beispiel #8
0
# Change the print info level
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import efficientnet_builder
import numpy as np
import tensorflow as tf
print("Using TensorFlow v", tf.__version__)

images = np.zeros((1, 224, 224, 3), dtype=np.float32)
images = tf.convert_to_tensor(images)
features, endpoints, model = efficientnet_builder.build_model_base(
    images, 'efficientnet-b0', training=True)

print(type(model))
model.summary()
model.save('test_b0.h5')