python实现自编码器autoencode
来源:互联网 发布:昆山宏观数据库 编辑:程序博客网 时间:2024/06/05 22:35
# -*- coding: utf-8 -*-"""Created on Sun Sep 3 13:48:19 2017@author: piaodexin"""
from __future__ import division, print_function, absolute_importimport tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_dataimport matplotlib.pyplot as pltimport numpy as npmnist=input_data.read_data_sets('E:\\mnist',one_hot=True)'''定义输入层 (28,28) =784第一层隐含层500个第二层100个第三层500输出层784 这是因为自编码就是希望神经网络自己学习图片特征,然后再用学习到的特征去组成原始图片,所以最后输出层是(28,28)=784'''input_n=784hidden1_n=500hidden2_n=100hidden3_n=500output_n=784learn_rate=0.01batch_size=100train_epoch=30000x=tf.placeholder(tf.float32,[None,input_n])y=tf.placeholder(tf.float32,[None,input_n])weights1=tf.Variable(tf.truncated_normal([input_n,hidden1_n],stddev=0.1))bias1=tf.Variable(tf.constant(0.1,shape=[hidden1_n]))weights2=tf.Variable(tf.truncated_normal([hidden1_n,hidden2_n],stddev=0.1))bias2=tf.Variable(tf.constant(0.1,shape=[hidden2_n]))weights3=tf.Variable(tf.truncated_normal([hidden2_n,hidden3_n],stddev=0.1))bias3=tf.Variable(tf.constant(0.1,shape=[hidden3_n]))weights4=tf.Variable(tf.truncated_normal([hidden3_n,output_n],stddev=0.1))bias4=tf.Variable(tf.constant(0.1,shape=[output_n]))def get_result(x,weights1,bias1,weights2,bias2,weights3,bias3,weights4,bias4): a1=tf.nn.sigmoid(tf.matmul(x,weights1)+bias1) a2=tf.nn.sigmoid(tf.matmul(a1,weights2)+bias2) a3=tf.nn.sigmoid(tf.matmul(a2,weights3)+bias3) y_=tf.nn.sigmoid(tf.matmul(a3,weights4)+bias4) return y_'''当我一步一步求y_的时候,却出现错误,只能用函数,不知道为什么'''y_=get_result(x,weights1,bias1,weights2,bias2,weights3,bias3,weights4,bias4)loss=tf.reduce_mean(tf.pow(y_-y,2))train_op=tf.train.RMSPropOptimizer(learn_rate).minimize(loss)with tf.Session() as sess: tf.global_variables_initializer().run() for i in range(train_epoch): xs,ys=mnist.train.next_batch(batch_size) if i%1000 == 0: print('epoch:',i) print('loss:',sess.run(loss,feed_dict={x:xs,y:xs})) sess.run(train_op,feed_dict={x:xs,y:xs}) xt=mnist.test.images[:5] yt=xt encode_decode=sess.run(y_,feed_dict={x:xt,y:yt}) f,a =plt.subplots(2,5,figsize=(10,2)) for i in range(5): a[0][i].imshow(np.reshape(mnist.test.images[i],(28,28))) a[1][i].imshow(np.reshape(encode_decode[i],(28,28))) f.show() plt.draw()
#结果展示:上面是原图片,下面是自编码学习到的
阅读全文
1 0
- python实现自编码器autoencode
- 深度自编码器python实现
- tensorflow实现自编码器
- Tensorflow实现自编码器
- tensorflow实现自编码器
- TensorFlow实现自编码器
- TensorFlow实现自编码器
- Tensorflow实现自编码器
- autoencode
- autoencode
- Keras实现各类自编码器
- 用TensorFlow实现自编码器
- Tensorflow实现AGN自编码器
- TensorFlow实现自编码器AutoEncoer
- 自编码器及其tensorflow实现
- 自编码器原理及实现
- 递归神经网络(recursive NN)结合自编码(Autoencode)实现句子建模
- 1TensorFlow实现自编码器-1.1自动编码器基本原理
- [js高手之路] 我的开源javascript框架gdom
- 简单介绍Java ClassLoader
- tensorflow官网无法访问
- 高二&高一模拟赛12 总结
- 《嵌入式开发探秘》之第二章 开发环境搭建(1)
- python实现自编码器autoencode
- C#中的Builder模式
- 老毛桃啊老毛桃
- Android开发 之 OpenGL ES系列(2--基本概念)
- Qt模型/视图
- 牛顿迭代法 && 高斯牛顿法
- [编程题] 买苹果
- TCP的三次握手和四次挥手,以及两次握手为什么不行?
- bzoj 5018: [Snoi2017]英雄联盟