作家
登录

如何使用TensorFlow和自编码器模型生成手写数字

作者: 来源: 2017-11-10 14:41:23 阅读 我要评论

  1. def encoder(X_in, keep_prob): 
  2.     activation = lrelu    with tf.variable_scope("encoder", reuse=None): 
  3.         X = tf.reshape(X_in, shape=[-1, 28, 28, 1]) 
  4.         x = tf.layers.conv2d(X, filters=64, kernel_size=4, strides=2, padding='same', activation=activation) 
  5.         x = tf.nn.dropout(x, keep_prob) 
  6.         x = tf.layers.conv2d(x, filters=64, kernel_size=4, strides=2, padding='same', activation=activation) 
  7.         x = tf.nn.dropout(x, keep_prob) 
  8.         x = tf.layers.conv2d(x, filters=64, kernel_size=4, strides=1, padding='same', activation=activation) 
  9.         x = tf.nn.dropout(x, keep_prob) 
  10.         x = tf.contrib.layers.flatten(x) 
  11.         mn = tf.layers.dense(x, units=n_latent) 
  12.         sd       = 0.5 * tf.layers.dense(x, units=n_latent)             
  13.         epsilon = tf.random_normal(tf.stack([tf.shape(x)[0], n_latent]))  
  14.         z  = mn + tf.multiply(epsilon, tf.exp(sd))         
  15.         return z, mn, sd  

定义解码器

解码器不会关怀输入值是不是大年夜我们定义的某个特定分布中采样获得的。它仅仅会测验测验重建输入图像。最后,我们应用了一系列的转置卷积(transpose convolution)。

  1. def decoder(sampled_z, keep_prob):    with tf.variable_scope("decoder", reuse=None): 
  2.         x = tf.layers.dense(sampled_z, units=inputs_decoder, activation=lrelu) 
  3.         x = tf.layers.dense(x, units=inputs_decoder * 2 + 1, activation=lrelu) 
  4.         x = tf.reshape(x, reshaped_dim) 
  5.         x = tf.layers.conv2d_transpose(x, filters=64, kernel_size=4, strides=2, padding='same', activation=tf.nn.relu) 
  6.         x = tf.nn.dropout(x, keep_prob) 
  7.         x = tf.layers.conv2d_transpose(x, filters=64, kernel_size=4, strides=1, padding='same', activation=tf.nn.relu) 
  8.         x = tf.nn.dropout(x, keep_prob) 
  9.         x = tf.layers.conv2d_transpose(x, filters=64, kernel_size=4, strides=1, padding='same', activation=tf.nn.relu) 
  10.          
  11.         x = tf.contrib.layers.flatten(x) 

      推荐阅读

      优秀程序员眼中的整洁代码

    Tech Neo技巧沙龙 | 11月25号,九州云/ZStack与您一路商量云时代收集界线治理实践 有若干法度榜样员,就有若干定义。所以我只询问了一些异常有名且经验丰富的法度榜样员。 优良法度榜样员>>>详细阅读


    本文标题:如何使用TensorFlow和自编码器模型生成手写数字

    地址:http://www.17bianji.com/lsqh/38737.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)