基于tensorflow2实现的变分自编码器(VAE)

这里简单记录一下、
我学习VAE原理之后,对VAE进行一个简单的实现。

VAE主要包括三部分:
1.编码器 ----> 均值,方差(图像特征)
2.均值,方差(图像特征)—> 新的特征向量(符合一定分布)
3.新的特征向量 —> 解码器 —> 新的图像

这里直接贴上我关于VAE实现的代码:

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
import time
%matplotlib inline

batch_size = 64
buffer_size = 60000
test_size = 10000

(train_image,_),(test_image,_) = tf.keras.datasets.mnist.load_data()

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

test_image = test_image.reshape(test_image.shape[0], 28, 28, 1).astype('float32')


train_image = train_image/255
test_image = test_image/255

train_datasets = tf.data.Dataset.from_tensor_slices(train_image).shuffle(buffer_size).batch(batch_size)
test_datasets = tf.data.Dataset.from_tensor_slices(test_image).shuffle(test_size).batch(batch_size)

epochs = 10
latent_dim = 64
num = 16
seed = tf.random.normal([num,latent_dim])  # 随机生成 16 个编码向量

def Encoder():
    model = tf.keras.Sequential()
    
    model
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值