-
大小: 10KB文件类型: .py金币: 1下载: 0 次发布日期: 2021-05-20
- 语言: Python
- 标签: vae autoencoder python 实现
资源简介
AutoEncoder是深度学习的另外一个重要内容,并且非常有意思,神经网络通过大量数据集,进行end-to-end的训练,不断提高其准确率,而AutoEncoder通过设计encode和decode过程使输入和输出越来越接近,是一种无监督学习过程。
代码片段和文件信息
import itertools
import matplotlib as mpl
import numpy as np
import os
import tensorflow as tf
import tensorflow.contrib.slim as slim
import time
import seaborn as sns
from matplotlib import pyplot as plt
from scipy.misc import imsave
from tensorflow.contrib.learn.python.learn.datasets.mnist import read_data_sets
sns.set_style(‘whitegrid‘)
distributions = tf.distributions
flags = tf.app.flags
flags.DEFINE_string(‘data_dir‘ ‘/tmp/dat/‘ ‘Directory for data‘)
flags.DEFINE_string(‘logdir‘ ‘/tmp/log/‘ ‘Directory for logs‘)
# For making plots:
# flags.DEFINE_integer(‘latent_dim‘ 2 ‘Latent dimensionality of model‘)
# flags.DEFINE_integer(‘batch_size‘ 64 ‘Minibatch size‘)
# flags.DEFINE_integer(‘n_samples‘ 10 ‘Number of samples to save‘)
# flags.DEFINE_integer(‘print_every‘ 10 ‘Print every n iterations‘)
# flags.DEFINE_integer(‘hidden_size‘ 200 ‘Hidden size for neural networks‘)
# flags.DEFINE_integer(‘n_iterations‘ 1000 ‘number of iterations‘)
# For bigger model:
flags.DEFINE_integer(‘latent_dim‘ 100 ‘Latent dimensionality of model‘)
flags.DEFINE_integer(‘batch_size‘ 64 ‘Minibatch size‘)
flags.DEFINE_integer(‘n_samples‘ 1 ‘Number of samples to save‘)
flags.DEFINE_integer(‘print_every‘ 1000 ‘Print every n iterations‘)
flags.DEFINE_integer(‘hidden_size‘ 200 ‘Hidden size for neural networks‘)
flags.DEFINE_integer(‘n_iterations‘ 100000 ‘number of iterations‘)
FLAGS = flags.FLAGS
def inference_network(x latent_dim hidden_size):
“““Construct an inference network parametrizing a Gaussian.
Args:
x: A batch of MNIST digits.
latent_dim: The latent dimensionality.
hidden_size: The size of the neural net hidden layers.
Returns:
mu: Mean parameters for the variational family Normal
sigma: Standard deviation parameters for the variational family Normal
“““
with slim.arg_scope([slim.fully_connected] activation_fn=tf.nn.relu):
net = slim.flatten(x)
net = slim.fully_connected(net hidden_size)
net = slim.fully_connected(net hidden_size)
gaussian_params = slim.fully_connected(
net latent_dim * 2 activation_fn=None)
# The mean parameter is unconstrained
mu = gaussian_params[: :latent_dim]
# The standard deviation must be positive. Parametrize with a softplus
sigma = tf.nn.softplus(gaussian_params[: latent_dim:])
return mu sigma
def generative_network(z hidden_size):
“““Build a generative network parametrizing the likelihood of the data
Args:
z: Samples of latent variables
hidden_size: Size of the hidden state of the neural net
Returns:
bernoulli_logits: logits for the Bernoulli likelihood of the data
“““
with slim.arg_scope([slim.fully_connected] activation_fn=tf.nn.relu):
net = slim.fully_connected(z hidden_size)
net = slim.fully_connected(net hidden_size)
bernoulli_logits = slim.fully_connected(net 784 activation_fn=None)
bernoulli_logits = tf.reshape(bernoulli_logits [-1 28 28 1])
return bernoulli_logits
- 上一篇:SRNN python代码实现
- 下一篇:DEM数据三维可视化--python实现
相关资源
- DEM数据三维可视化--python实现
- SRNN python代码实现
- ArcGIS Python常用脚本.docx
- Python找不到cl.exe等
- 自动扫雷系统+Python
- 基于标签的用户协同算法python
- 12306抢票Python代码,内含视频教程
- 个人博客网站源码python3.6+django2.0+my
- python网盘.txt
- Python Flask开发自己敲的试验楼小Demo
- python内置K-means聚类算法对鸢尾花数据
- KCFpython算法
- 指定步数节点内容的PROCAST仿真结果导
- python自然语言处理中文停用词
- 最好中国大学近几年排名及python爬虫
- Tensorflow-BiLSTM分类
- 感知机算法Python实现
- python 实现将TXT文件内容逐行存到EXC
- python 打开并计算两幅dicom图像感兴趣
- python 决策树代码
- 银行ATM系统(Python实现)
- pygame实现的贪吃蛇游戏RetroSnaker.py
- Python文件
- QT文件转换成Python的自动化工具*.ui转
- fcntl模块 win
- python爬虫爬取企业详细信息
- Kruskal算法python实现
- 蚁群算法的python代码
- 最小二乘法python代码,不用库函数
- sm3 python encode
评论
共有 条评论