GAN的训练入门- from Deep-Learning-with-TensorFlow-book-master

GAN的初级代码,分别描述了Generator及Discriminator的基础功能。

import  tensorflow as tf
from    tensorflow import keras
from    tensorflow.keras import layers


class Generator(keras.Model):
    # 生成器网络
    def __init__(self):
        super(Generator, self).__init__()
        filter = 64
        # 转置卷积层1,输出channel为filter*8,核大小4,步长1,不使用padding,不使用偏置
        self.conv1 = layers.Conv2DTranspose(filter*8, 4,1, 'valid', use_bias=False)
        self.bn1 = layers.BatchNormalization()
        # 转置卷积层2
        self.conv2 = layers.Conv2DTranspose(filter*4, 4,2, 'same', use_bias=False)
        self.bn2 = layers.BatchNormalization()
        # 转置卷积层3
        self.conv3 = layers.Conv2DTranspose(filter*2, 4,2, 'same', use_bias=False)
        self.bn3 = layers.BatchNormalization()
        # 转置卷积层4
        self.conv4 = layers.Conv2DTranspose(filter*1, 4,2, 'same', use_bias=False)
        self.bn4 = layers.BatchNormalization()
        # 转置卷积层5
        self.conv5 = layers.Conv2DTranspose(3, 4,2, 'same', use_bias=False)

    def call(self, inputs, training=None):
        x = inputs # [z, 100]
        # Reshape乘4D张量,方便后续转置卷积运算:(b, 1, 1, 100)
        x = tf.reshape(x, (x.shape[0], 1, 1, x.shape[1]))
        x = tf.nn.relu(x) # 激活函数
        # 转置卷积-BN-激活函数:(b, 4, 4, 512)
        x = tf.nn.relu(self.bn1(self.conv1(x), training=training))
        # 转置卷积-BN-激活函数:(b, 8, 8, 256)
        x = tf.nn.relu(self.bn2(self.conv2(x), training=training))
        # 转置卷积-BN-激活函数:(b, 16, 16, 128)
        x = tf.nn.relu(self.bn3(self.conv3(x), training=training))
        # 转置卷积-BN-激活函数:(b, 32, 32, 64)
        x = tf.nn.relu(self.bn4(self.conv4(x), training=training))
        # 转置卷积-激活函数:(b, 64, 64, 3)
        x = self.conv5(x)
        x = tf.tanh(x) # 输出x范围-1~1,与预处理一致

        return x


class Discriminator(keras.Model):
    # 判别器
    def __init__(self):
        super(Discriminator, self)._
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Key Features Learn advanced techniques in deep learning with this example-rich guide on Google's brainchildExplore various neural networks with the help of this comprehensive guideAdvanced guide on machine learning techniques, in particular TensorFlow for deep learning. Book Description Deep learning is the next step after machine learning. It is machine learning but with a more advanced implementation. As machine learning is no longer an academic topic, but a mainstream practice, deep learning has taken a front seat. With deep learning being used by many data scientists, deeper neural networks are evaluated for accurate results. Data scientists want to explore data abstraction layers and this book will be their guide on this journey. This book evaluates common, and not so common, deep neural networks and shows how these can be exploited in the real world with complex raw data using TensorFlow. The book will take you through an understanding of the current machine learning landscape then delve into TensorFlow and how to use it by considering various data sets and use cases. Throughout the chapters, you'll learn how to implement various deep learning algorithms for your machine learning systems and integrate them into your product offerings such as search, image recognition, and language processing. Additionally, we'll examine its performance by optimizing it with respect to its various parameters, comparing it against benchmarks along with teaching machines to learn from the information and determine the ideal behavior within a specific context, in order to maximize its performance. After finishing the book, you will be familiar with machine learning techniques, in particular TensorFlow for deep learning, and will be ready to apply some of your knowledge in a real project either in a research or commercial setting. What you will learn Provide an overview of the machine learning landscapeLook at the historical development and progress of deep learningDescribe TensorFlow and become very familiar with it both in theory and in practiceAccess public datasets and use TF to load, process, clean, and transform dataUse TensorFlow on real-world data sets including images and textGet familiar with TensorFlow by applying it in various hands on exercises using the command lineEvaluate the performance of your deep learning modelsQuickly teach machines to learn from data by exploring reinforcement learning techniques.Understand how this technology is being used in the real world by exploring active areas of deep learning research and application.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值