大数据开发之keras代码框架应用

Posted 圆柱模板

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了大数据开发之keras代码框架应用相关的知识,希望对你有一定的参考价值。

     总体来讲keras这个深度学习框架真的很“简易”,它体现在可参考的文档写的比较详细,不像caffe,装完以后都得靠技术博客,keras有它自己的官方文档(不过是英文的),这给初学者提供了很大的学习空间。

    在此做下代码框架应用笔记

     

class VGGNetwork:
    def append_vgg_network(self, x_in, true_X_input):
        return x #x is output of VGG
    def load_vgg_weight(self, model):
        return model
class DiscriminatorNetwork:
    def append_gan_network(self, true_X_input):
        return x
class GenerativeNetwork:
    def create_sr_model(self, ip):
        return x
    def get_generator_output(self, input_img, srgan_model):
        return self.output_func([input_img])
class SRGANNetwork:
    def build_srgan_pretrain_model(self):
        return self.srgan_model_
    def build_discriminator_pretrain_model(self):
        return self.discriminative_model_
    def build_srgan_model(self):
        return self.srgan_model_
    def pre_train_srgan(self, image_dir, nb_images=50000, nb_epochs=1, use_small_srgan=False):
        for i in range(nb_epochs):
            for x in datagen.flow_from_directory
                if iteration % 50 == 0 and iteration != 0
                    validation//print psnr
                Train only generator + vgg network
                if iteration % 1000 == 0 and iteration != 0
                    Saving model weights
    def pre_train_discriminator(self, image_dir, nb_images=50000, nb_epochs=1, batch_size=128): 
        for i in range(nb_epochs):
             for x in datagen.flow_from_directory
                 Train only discriminator
                 if iteration % 1000 == 0 and iteration != 0
                    Saving model weights
    def train_full_model(self, image_dir, nb_images=50000, nb_epochs=10):   
        for i in range(nb_epochs):
            for x in datagen.flow_from_directory
                if iteration % 50 == 0 and iteration != 0
                    validation//print psnr
                if iteration % 1000 == 0 and iteration != 0
                    Saving model weights
                Train only discriminator, disable training of srgan
                Train only generator, disable training of discriminator
if __name__ == "__main__":
    from keras.utils.visualize_util import plot

    # Path to MS COCO dataset
    coco_path = r"D:\Yue\Documents\Dataset\coco2014\train2014"

    ‘‘‘
    Base Network manager for the SRGAN model

    Width / Height = 32 to reduce the memory requirement for the discriminator.

    Batch size = 1 is slower, but uses the least amount of gpu memory, and also acts as
    Instance Normalization (batch norm with 1 input image) which speeds up training slightly.
    ‘‘‘

    srgan_network = SRGANNetwork(img_width=32, img_height=32, batch_size=1)
    srgan_network.build_srgan_model()
    #plot(srgan_network.srgan_model_, ‘SRGAN.png‘, show_shapes=True)

    # Pretrain the SRGAN network
    #srgan_network.pre_train_srgan(coco_path, nb_images=80000, nb_epochs=1)

    # Pretrain the discriminator network
    #srgan_network.pre_train_discriminator(coco_path, nb_images=40000, nb_epochs=1, batch_size=16)

    # Fully train the SRGAN with VGG loss and Discriminator loss
    srgan_network.train_full_model(coco_path, nb_images=80000, nb_epochs=5)

  

以上是关于大数据开发之keras代码框架应用的主要内容,如果未能解决你的问题,请参考以下文章

大数据技术之Hadoop(MapReduce)

框架《Keras深度学习实战》中英文PDF+源代码分析

大数据Hadoop之MapReduce

技术观点简易的深度学习框架Keras代码解析与应用

简易的深度学习框架Keras代码解析与应用

大数据基础之调度框架