예제 #1
0
def test_vgg_classify():
    vgg16 = Vgg(True, vgg=Vgg.VGG16)
    vgg19 = Vgg(True, vgg=Vgg.VGG19)
    x = np.expand_dims(image_boy, 0)
    y1 = vgg16(x)
    y2 = vgg19(x)
    with tf.Session() as sess:
        y1, y2 = sess.run([y1, y2])
        assert y2[0].tolist().index(y2.max()) == y1[0].tolist().index(y1.max())
예제 #2
0
def test_multiple_call():
    vgg1 = Vgg(False, vgg=Vgg.VGG16)
    vgg2 = Vgg(False, vgg=Vgg.VGG16)
    x = np.expand_dims(image_boy, 0)
    y1 = vgg1(x)
    y2 = vgg2(x)
    y3 = vgg2(x.copy())
    with tf.Session() as sess:
        sess.run([y1, y2, y3])
예제 #3
0
def test_vgg19():
    vgg = Vgg(False, vgg=Vgg.VGG19)
    x = np.random.normal(size=[16, 128, 128, 3])
    y = vgg(x, 'block2_conv2')
    assert y.shape == (16, 64, 64, 128)
    with tf.Session() as sess:
        sess.run(y)
예제 #4
0
def test_vgg16():
    vgg = Vgg(False, vgg=Vgg.VGG16)
    x = np.random.normal(size=[16, 128, 128, 3])
    y = vgg(x)
    assert y.shape == (16, )
    with tf.Session() as sess:
        sess.run(y)
예제 #5
0
 def __init__(self,
              glayers=16,
              dlayers=4,
              vgg_layer='block5_conv4',
              init_epoch=100,
              gan_weight=1e-3,
              vgg_weight=0.1569,
              name='srfeat',
              **kwargs):
     super(SRFEAT, self).__init__(**kwargs)
     self.name = name
     self.g_layers = glayers
     self.init_epoch = init_epoch
     self.gan_weight = gan_weight
     self.vgg_weight = vgg_weight
     self.vgg_layer = vgg_layer
     self.vgg = Vgg(False, Vgg.VGG19)
     self.F = 64
     self.D = Discriminator.dcgan_d(self, [None, None, self.channel],
                                    64,
                                    times_stride=dlayers,
                                    norm='bn',
                                    name_or_scope='Critic')
     self.DF = Discriminator.dcgan_d(self, [None, None, self.channel],
                                     64,
                                     times_stride=dlayers,
                                     norm='bn',
                                     name_or_scope='DF')
예제 #6
0
 def __init__(self,
              glayers=16,
              dlayers=4,
              vgg_layer='block2_conv2',
              init_epoch=100,
              mse_weight=1,
              gan_weight=1e-3,
              use_vgg=False,
              vgg_weight=2e-6,
              name='srgan',
              **kwargs):
     super(SRGAN, self).__init__(**kwargs)
     self.name = name
     self.g_layers = glayers
     self.init_epoch = init_epoch
     self.mse_weight = mse_weight
     self.gan_weight = gan_weight
     self.vgg_weight = vgg_weight
     self.vgg_layer = vgg_layer
     self.use_vgg = use_vgg
     self.vgg = None
     if self.use_vgg:
         self.vgg = Vgg(False, 'vgg19')
     self.D = Discriminator.dcgan_d(self, [None, None, self.channel],
                                    64,
                                    times_stride=dlayers,
                                    norm='bn',
                                    name_or_scope='Critic')
예제 #7
0
import tensorflow as tf
import numpy as np

try:
    DATASETS = load_datasets('./Data/datasets.json')
except FileNotFoundError:
    DATASETS = load_datasets('../Data/datasets.json')
data = DATASETS['91-IMAGE']
loader = BatchLoader(1,
                     data,
                     'test',
                     convert_to_gray=True,
                     crop=False,
                     scale=1)

m = Vgg(input_shape=[None, None, 3], type='vgg19')
with tf.Session() as sess:
    # m = Vgg(input_shape=[None, None, 3], type='vgg19')
    for hr, lr in loader:
        y = m(hr, [2, 3], [2, 3])
        break

tf.reset_default_graph()
m = Vgg(input_shape=[None, None, 3], type='vgg19')
with tf.Session() as sess:
    # m = Vgg(input_shape=[None, None, 3], type='vgg19')
    for hr, lr in loader:
        y = m(hr, [2, 3], [2, 3])
        break

# Error for not reusing VGG variables