Example #1
0
    def buildModel(self):
        print("Building EDSR...")
        self.norm_input = utils.normalize_color_tf(self.input)
        self.norm_target = utils.normalize_color_tf(self.target)

        #input layer
        x = tl.InputLayer(self.norm_input, name='inputlayer')

        # One convolution before res blocks and to convert to required feature depth
        #第一层的剪枝将会作用在这里,filter数量减少
        #x = tl.Conv2d(x, self.feature_size-self.prunedlist[0], [3, 3], name='c')
        x = tl.Conv2d(x, self.feature_size, [3, 3], name='c')

        # Store the output of the first convolution to add later
        conv_1 = x

        scaling_factor = 0.1
        # Add the residual blocks to the model
        for i in range(self.num_layers):
            x = self.__resBlock(x, self.feature_size, scale=scaling_factor,layer=i)
        # One more convolution, and then we add the output of our first conv layer
        x = tl.Conv2d(x, self.feature_size, [3, 3], act = None, name = 'm1')
        x = tl.ElementwiseLayer([conv_1,x],tf.add, name='res_add')

        x = TransposedConv2dLayer(x, self.feature_size, [5,5], [2,2], name='deconv_1')
        x = tl.Conv2d(x, self.feature_size, [3, 3], act=tf.nn.relu, name='deconv_conv_1')
        x = TransposedConv2dLayer(x, self.feature_size, [5, 5], [2, 2], name='deconv_2')
        if self.scale==8:
            x = tl.Conv2d(x, self.feature_size, [3, 3], act=tf.nn.relu, name='deconv_conv_2')
            x = TransposedConv2dLayer(x, self.feature_size, [5, 5], [2, 2], name='deconv_3')

        # One final convolution on the upsampling output
        output = tl.Conv2d(x,self.output_channels,[1,1],act=tf.nn.relu, name='lastLayer')
        # output = tl.Conv2d(x, self.output_channels, [1, 1], act=None, name='lastLayer')
        self.output = output.outputs
        self.output = tf.clip_by_value(output.outputs, 0.0, 1.0)

        self.cacuLoss()

        # Tensorflow graph setup... session, saver, etc.
        session_conf = tf.ConfigProto(allow_soft_placement=True,log_device_placement=False)
        session_conf.gpu_options.allocator_type = 'BFC'
        self.sess = tf.Session(config=session_conf)
        self.saver = tf.train.Saver(var_list = tf.trainable_variables(), max_to_keep=100)
        print("Done building!")
Example #2
0
def deconv_upsample(x, n_features, kernel=(5, 5), scale=4):
    x = TransposedConv2dLayer(x, n_features, kernel, (2, 2), name='deconv_1')
    if scale == 4:
        x = tl.Conv2d(x,
                      n_features, (3, 3),
                      act=tf.nn.relu,
                      name='deconv_conv_1')
        x = TransposedConv2dLayer(x,
                                  n_features,
                                  kernel, (2, 2),
                                  name='deconv_2')
    if scale == 8:
        x = tl.Conv2d(x,
                      n_features, (3, 3),
                      act=tf.nn.relu,
                      name='deconv_conv_2')
        x = TransposedConv2dLayer(x,
                                  n_features,
                                  kernel, (2, 2),
                                  name='deconv_3')
    return x