基于tensorflow2 实现的简单GAN 实例

这里直接展示我自己编写的GAN代码

关于GAN的原理介绍这里就不多讲了~~

import os
import warnings
warnings.filterwarnings("ignore")
import tensorflow as tf
import numpy as np
import pandas as pd
import glob
from tensorflow import keras
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline

batch_size = 64
buffer_size = 60000
# 导入图像
(train_image,train_label),(_,_) = tf.keras.datasets.fashion_mnist.load_data()

train_image = train_image.reshape(train_image.shape[0],28,28,1).astype('float32')  # 将二维 图像 转换为 三维 图像

train_image = train_image/255

datasets = tf.data.Dataset.from_tensor_slices(train_image)
datasets = datasets.shuffle(buffer_size).batch(batch_size)
# 生成器构建, 这里主要采用了反卷积的操作
def generator_model():
    model = tf.keras.Sequential()
    model.add( tf.keras.layers.Dense(512*3*3,input_shape =(256 ,),use_bias = False))   # input_shape 是 自由定义的
    model.add( tf.keras.layers.Reshape((3, 3, 512)))
    model.add( tf.keras.layers.LeakyReLU())
    
    model.add( tf.keras.layers.Conv2DTranspose<
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值