autoencoder

TensorFlow tfrecords: tostring() changes dimension of image

女生的网名这么多〃 提交于 2019-12-06 15:33:55
问题 I have built a model to train a convolutional autoencoder in TensorFlow. I followed the instructions on Reading Data from the TF documentation to read in my own images of size 233 x 233 x 3. Here is my convert_to() function adapted from those instructions: def convert_to(images, name): """Converts a dataset to tfrecords.""" num_examples = images.shape[0] rows = images.shape[1] cols = images.shape[2] depth = images.shape[3] filename = os.path.join(FLAGS.tmp_dir, name + '.tfrecords') print(

Keras fit_generator producing exception: output of generator should be a tuple(x, y, sample_weight) or (x, y). Found: [[[[ 0.86666673

╄→гoц情女王★ 提交于 2019-12-06 08:48:55
I am trying to build an autoencoder for non MNIST, non Imagenet data. Using https://blog.keras.io/building-autoencoders-in-keras.html as my base. However, am getting the following error. **Exception: output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: [[[[ 0.86666673 0.86666673 0.86666673 ..., 0.62352943 0.627451 0.63137257] [ 0.86666673 0.86666673 0.86666673 ..., 0.63137257 0.627451 0.627451 ] [ 0.86666673 0.86666673 0.86666673 ..., 0.63137257 0.627451 0.62352943] ...,** Since this is an autoencoder, in my datagenerator, used class mode=None. My code is as follows.

Pytorch中的自编码(autoencoder)

為{幸葍}努か 提交于 2019-12-06 02:27:16
Pytorch中的自编码(autoencoder) 本文资料来源: https://www.bilibili.com/video/av15997678/?p=25 什么是自编码 先压缩原数据、提取出最有代表性的信息。然后处理后再进行解压。减少处理压力 通过对比白色X和黑色X的区别(cost函数),从而不断提升自编码模型的能力(也就是还原的准确度) 由于这里只是使用了数据本身,没有使用label,所以可以说autoencoder是一种无监督学习模型。 实际在使用中,我们先训练好一个autoencoder模型,然后只取用其前一半,来获取到压缩了的特征进行其他的训练,以达到压缩特征的目的。 自编码可以达到类似于PCA的效果 自编码in Pytorch encoder decoder 连接成网络 设置优化器和损失函数 autoencoder=AutoEncoder() optimizer=torch.optim.Adam(autoencoder.parameters(),lr=LR) loss_func=mm.MSELoss() 搭建网络,传入数据 这里的y是压缩之前的数据,用来在loss function中和decoded对比的 设置输出 来源: https://www.cnblogs.com/jiading/p/11956955.html

How do I split an convolutional autoencoder?

白昼怎懂夜的黑 提交于 2019-12-05 18:10:24
I have compiled an autoencoder (full code is below), and after training it I would like to split it into two separate models: encoder (layers e1...encoded) and decoder (all other layers) in which to feed manually modified images that had been encoded by the decoder. I have succeeded in creating an encoder as a separate model with: encoder = Model(input_img, autoencoder.layers[6].output) But the same approach fails when I try to make a decoder: encoded_input = Input(shape=(4,4,8)) decoder = Model(input_img, decoded) This is my full code: from keras.layers import Input, Dense, Conv2D,

How to inject values into the middle of TensorFlow graph?

扶醉桌前 提交于 2019-12-05 10:43:47
Consider the following code: x = tf.placeholder(tf.float32, (), name='x') z = x + tf.constant(5.0) y = tf.mul(z, tf.constant(0.5)) with tf.Session() as sess: print(sess.run(y, feed_dict={x: 30})) The resulting graph is x -> z -> y. Sometimes I'm interested in computing y all the way from from x but sometimes I have z to start and would like inject this value into the graph. So the z needs to behave like a partial placeholder. How can I do that? (For anyone interested why I need this. I am working with an autoencoder network which observes an image x, generates an intermediate compressed

How to use masking layer to mask input/output in LSTM autoencoders?

冷暖自知 提交于 2019-12-05 05:50:14
问题 I am trying to use LSTM autoencoder to do sequence-to-sequence learning with variable lengths of sequences as inputs, using following code: inputs = Input(shape=(None, input_dim)) masked_input = Masking(mask_value=0.0, input_shape=(None,input_dim))(inputs) encoded = LSTM(latent_dim)(masked_input) decoded = RepeatVector(timesteps)(encoded) decoded = LSTM(input_dim, return_sequences=True)(decoded) sequence_autoencoder = Model(inputs, decoded) encoder = Model(inputs, encoded) where inputs are

TensorFlow tfrecords: tostring() changes dimension of image

廉价感情. 提交于 2019-12-04 21:25:37
I have built a model to train a convolutional autoencoder in TensorFlow. I followed the instructions on Reading Data from the TF documentation to read in my own images of size 233 x 233 x 3. Here is my convert_to() function adapted from those instructions: def convert_to(images, name): """Converts a dataset to tfrecords.""" num_examples = images.shape[0] rows = images.shape[1] cols = images.shape[2] depth = images.shape[3] filename = os.path.join(FLAGS.tmp_dir, name + '.tfrecords') print('Writing', filename) writer = tf.python_io.TFRecordWriter(filename) for index in range(num_examples): print

How do I correctly implement a custom activity regularizer in Keras?

一世执手 提交于 2019-12-04 20:08:02
问题 I am trying to implement sparse autoencoders according to Andrew Ng's lecture notes as shown here. It requires that a sparsity constraint be applied on an autoencoder layer by introducing a penalty term (K-L divergence). I tried to implement this using the direction provided here, after some minor changes. Here is the K-L divergence and the sparsity penalty term implemented by the SparseActivityRegularizer class as shown below. def kl_divergence(p, p_hat): return (p * K.log(p / p_hat)) + ((1

TensorFlow自编码器(AutoEncoder)之MNIST实践

自闭症网瘾萝莉.ら 提交于 2019-12-04 18:23:57
自编码器可以用于降维,添加噪音学习也可以获得去噪的效果。 以下使用单隐层训练mnist数据集,并且共享了对称的权重参数。 模型本身不难,调试的过程中有几个需要注意的地方: 模型对权重参数初始值敏感,所以这里对权重参数w做了一些限制 需要对数据标准化 学习率设置合理(Adam,0.001) 1,建立模型 import numpy as np import tensorflow as tf class AutoEncoder(object): ''' 使用对称结构,解码器重用编码器的权重参数 ''' def __init__(self, input_shape, h1_size, lr): tf.reset_default_graph()# 重置默认计算图,有时出错后内存还一团糟 with tf.variable_scope('auto_encoder', reuse=tf.AUTO_REUSE): self.W1 = self.weights(shape=(input_shape, h1_size), name='h1') self.b1 = self.bias(h1_size) self.W2 = tf.transpose(tf.get_variable('h1')) # 共享参数,使用其转置 self.b2 = self.bias(input_shape) self.lr =

Tying Autoencoder Weights in a Dense Keras Layer

徘徊边缘 提交于 2019-12-04 18:09:34
I am attempting to create a custom, Dense layer in Keras to tie weights in an Autoencoder. I have tried following an example for doing this in convolutional layers here , but it seemed like some of the steps did not apply for the Dense layer (also, the code is from over two years ago). By tying weights, I want the decode layer to use the transposed weight matrix of the encode layer. This approach is also taken in this article (page 5). Below is the relevant quote from the article: Here, we choose both the encoding and decoding activation function to be sigmoid function and only consider the