标签: autoencoder

二进制交叉熵损失在自动编码器上如何工作?

我只使用Dense图层编写了香草自动编码器。下面是我的代码:

iLayer = Input ((784,))
layer1 = Dense(128, activation='relu' ) (iLayer)
layer2 = Dense(64, activation='relu') (layer1)
layer3 = Dense(28, activation ='relu') (layer2)
layer4 = Dense(64, activation='relu') (layer3)
layer5 = Dense(128, activation='relu' ) (layer4)
layer6 = Dense(784, activation='softmax' ) (layer5)
model = Model (iLayer, layer6)
model.compile(loss='binary_crossentropy', optimizer='adam')

(trainX, trainY), (testX, testY) =  mnist.load_data()
print ("shape of the trainX", trainX.shape)
trainX = trainX.reshape(trainX.shape[0], trainX.shape[1]* trainX.shape[2])
print ("shape of the trainX", trainX.shape)
model.fit (trainX, trainX, epochs=5, batch_size=100)
Run Code Online (Sandbox Code Playgroud)

问题:

1)softmax提供概率分布。明白了 …

machine-learning neural-network autoencoder keras cross-entropy

10
推荐指数
1
解决办法
5469
查看次数

Python/Keras/Theano错误的自动编码器维度

我正在尝试遵循Deep Autoencoder Keras 示例.我得到了一个维度不匹配异常,但对于我的生活,我无法弄清楚为什么.当我只使用一个编码维度时它可以工作,但是当我堆叠它们时却不行.

例外:输入0与图层dense_18不兼容:
expected shape =(None,128),found shape =(None,32)*

错误就行了 decoder = Model(input=encoded_input, output=decoder_layer(encoded_input))

from keras.layers import Dense,Input
from keras.models import Model

import numpy as np

# this is the size of the encoded representations
encoding_dim = 32

#NPUT LAYER
input_img = Input(shape=(784,))

#ENCODE LAYER
# "encoded" is the encoded representation of the input
encoded = Dense(encoding_dim*4, activation='relu')(input_img)
encoded = Dense(encoding_dim*2, activation='relu')(encoded)
encoded = Dense(encoding_dim, activation='relu')(encoded)

#DECODED LAYER
# "decoded" is the lossy reconstruction of the input
decoded …
Run Code Online (Sandbox Code Playgroud)

machine-learning neural-network theano autoencoder keras

9
推荐指数
1
解决办法
1658
查看次数

Do Keras dropout和GaussianNoise图层在每个批次中应用不同的噪声实例吗?

我正在Keras建立一个去噪自动编码器.我正在使用的模型是

input_img = Input(shape=(10,))
encoded = GaussianNoise(0.01)(input_img)
encoded = Dropout(0.1)(encoded)
encoded = Dense(20,activation='relu')(encoded)
decoded = Dense(10, activation='sigmoid')(encoded)
ae = Model(input=input_img, output=decoded)
Run Code Online (Sandbox Code Playgroud)

如果我随后打电话

ae.fit(x_train, x_train,
                     nb_epoch=3,
                     batch_size=5,
                     shuffle=True,
                     validation_data=(x_test, x_test))
Run Code Online (Sandbox Code Playgroud)

是否有为每批产生的噪音的新实例?换句话说,对于上面的每个时期,每个批次都有不同的噪声实例?或者噪声实例是否针对所有批次固定为相同的事物,并且仅在时期变化时才更改?或者更糟糕的是,整个事物只选择了一个噪声实例?

noise autoencoder keras

9
推荐指数
1
解决办法
2662
查看次数

来自密集的Tensorflow的稀疏矩阵

我正在创建一个卷积稀疏自动编码器,我需要将一个充满值(其形状[samples, N, N, D])的4D矩阵转换为稀疏矩阵.

对于每个样本,我有D NxN特征映射.我想将每个NxN特征映射转换为稀疏矩阵,最大值映射为1,其他所有映射为0.

我不想在运行时这样做但在Graph声明期间(因为我需要使用生成的稀疏矩阵作为其他图形操作的输入),但我不明白如何获得索引来构建稀疏矩阵.

python graph sparse-matrix autoencoder tensorflow

9
推荐指数
1
解决办法
4459
查看次数

解码器在Keras中具有绑定权重的自动编码器的权重

我在Keras实施了一个捆绑权重自动编码器,并成功训练了它.

我的目标是仅使用自动编码器的解码器部分作为另一个网络的最后一层,以微调网络和解码器.

正如你在摘要中看到的那样,解码器没有带有我的绑定权重实现的参数,所以没有什么可以微调的.(decoder.get_weights()退货[])

我的问题是:我是否应该更改绑定权重的实现,以便绑定层仍然可以保持权重,即编码器的转置权重?如果有,怎么样?

还是我离开了?

下面是autoencoder模型的摘要以及绑定的Dense层的类(稍微修改自https://github.com/nanopony/keras-convautoencoder/blob/master/autoencoder_layers.py.)


Layer (type)                     Output Shape          Param #     Connected to                     
====================================================================================================
encoded (Dense)                  (None, Enc_dim)          33000       dense_input_1[0][0]              
____________________________________________________________________________________________________
tieddense_1 (TiedtDense)          (None, Out_Dim)            0           encoded[0][0]                    
====================================================================================================
Total params: 33,000
Trainable params: 33,000
Non-trainable params: 0
________________________________________________________________________


class TiedtDense(Dense):
def __init__(self, output_dim, master_layer, init='glorot_uniform', activation='linear', weights=None,
             W_regularizer=None, b_regularizer=None, activity_regularizer=None,
             W_constraint=None, b_constraint=None, input_dim=None, **kwargs):
    self.master_layer = master_layer
    super(TiedtDense, self).__init__(output_dim, **kwargs)

def build(self, input_shape):
    assert len(input_shape) >= 2
    input_dim = input_shape[-1]
    self.input_dim = input_dim …
Run Code Online (Sandbox Code Playgroud)

python machine-learning neural-network autoencoder keras

9
推荐指数
1
解决办法
1993
查看次数

自动编码器的正规化太强(Keras自动编码器教程代码)

我正在使用本教程关于autoencoders:https://blog.keras.io/building-autoencoders-in-keras.html

所有代码都正常工作,但是当我为正则化参数设置10e-5时性能非常糟糕(结果很模糊),这是教程代码中定义的参数.实际上,我需要将正则化减少到10e-8以获得正确的输出.

我的问题如下:为什么结果与教程有如此不同?数据是相同的,参数是相同的,我没想到会有很大的差异.

我怀疑从2016年5月14日起Keras功能的默认行为已经改变(在所有情况下都执行自动批量标准化?).

输出:

使用10e-5正则化链接到模糊图像输出

用10e-5正则化(模糊); 50个时期后val_loss为0.2967,100个时期后为0.2774

使用10e-8正则化:50个历元后的val_loss为0.1080,100个历元后为0.1009.

没有正则化:50个时期后val_loss为0.1018,100个时期后为0.0944.

完整代码(供参考):

# Source: https://blog.keras.io/building-autoencoders-in-keras.html
import numpy as np
np.random.seed(2713)

from keras.layers import Input, Dense
from keras.models import Model
from keras import regularizers

encoding_dim = 32

input_img = Input(shape=(784,))
# add a Dense layer with a L1 activity regularizer
encoded = Dense(encoding_dim, activation='relu',
                activity_regularizer=regularizers.l1(10e-5))(input_img)
decoded = Dense(784, activation='sigmoid')(encoded)

autoencoder = Model(input_img, decoded)

# this model maps an input to its encoded representation
encoder = Model(input_img, encoded)

# create …
Run Code Online (Sandbox Code Playgroud)

python regularized autoencoder keras

9
推荐指数
1
解决办法
968
查看次数

Pytorch - 如何使用BCE损失

我想在pytorch中编写一个简单的autoencoder并使用BCELoss,但是我得到了NaN,因为它期望目标在0和1之间.有人可以发布一个简单的BCELoss用例吗?

loss autoencoder torch pytorch

9
推荐指数
2
解决办法
2万
查看次数

当脚本在较大的数据集上运行时,LSTM Autoencoder没有进展

的形状p_input此LSTM自动编码"test.py"是(128,8,1); 意思是128组8位数.我试图使用4组25,000个时间步长(基本上0秒到25,000秒)使这个模型适应基于时间序列的数据.我尝试将此数据集输入到p_input形状(4,25000,1)中,并且没有发生错误.但是当我运行脚本时,而不是让iter 1: 0.01727, iter 2: 0.00983, ...我没有得到脚本的任何打印反馈,所以我假设有一些东西正在举行脚本.我还尝试将未更改batch_num为4和step_num25,000直接更改为未编辑的"test.py"文件,并且没有发生打印反馈的相同结果.

我的想法是,在"test.py"中,p_inputs计算tf.splittf.squeeze操作的时间太长.另一个想法是我可能需要增加隐藏的LSTM单元hidden_num的数量和/或增加epochs(iteration)的数量.此外,它可能batch_num必须大于step_num.我试图与"test.py"同step_num = 4batch_num = 25000和脚本印反馈正常运行.

让我知道你对阻止脚本运行的问题的看法.

python python-3.x autoencoder lstm tensorflow

9
推荐指数
1
解决办法
253
查看次数

中间层使tensorflow优化器停止工作

该图训练了一个简单的信号身份编码器,实际上表明权重由优化器进化:

import tensorflow as tf
import numpy as np
initia = tf.random_normal_initializer(0, 1e-3)

DEPTH_1 = 16
OUT_DEPTH = 1
I = tf.placeholder(tf.float32, shape=[None,1], name='I') # input
W = tf.get_variable('W', shape=[1,DEPTH_1], initializer=initia, dtype=tf.float32, trainable=True) # weights
b = tf.get_variable('b', shape=[DEPTH_1], initializer=initia, dtype=tf.float32, trainable=True) # biases
O = tf.nn.relu(tf.matmul(I, W) + b, name='O') # activation / output

#W1 = tf.get_variable('W1', shape=[DEPTH_1,DEPTH_1], initializer=initia, dtype=tf.float32) # weights
#b1 = tf.get_variable('b1', shape=[DEPTH_1], initializer=initia, dtype=tf.float32) # biases
#O1 = tf.nn.relu(tf.matmul(O, W1) + b1, name='O1')

W2 = …
Run Code Online (Sandbox Code Playgroud)

python machine-learning autoencoder deep-learning tensorflow

9
推荐指数
1
解决办法
1927
查看次数

如何在Keras,RepeatVector或return_sequence = True中连接LSTM层?

我正在尝试在keras中为时间序列开发一个编码器模型.数据的形状是(5039,28,1),这意味着我的seq_len是28,我有一个功能.对于编码器的第一层,我使用112个hunits,第二层将有56个并且能够返回到解码器的输入形状,我不得不添加第二层28个hunits(这个自动编码器应该重建它的输入).但我不知道将LSTM层连接在一起的正确方法是什么.AFAIK,我可以添加RepeatVectorreturn_seq=True.您可以在以下代码中查看我的两个模型.我想知道会有什么不同,哪种方法是正确的?

第一个模型使用return_sequence=True:

inputEncoder = Input(shape=(28, 1))
firstEncLayer = LSTM(112, return_sequences=True)(inputEncoder)
snd = LSTM(56, return_sequences=True)(firstEncLayer)
outEncoder = LSTM(28)(snd)

context = RepeatVector(1)(outEncoder)
context_reshaped = Reshape((28,1))(context)

encoder_model = Model(inputEncoder, outEncoder)
firstDecoder = LSTM(112, return_sequences=True)(context_reshaped)
outDecoder = LSTM(1, return_sequences=True)(firstDecoder)

autoencoder = Model(inputEncoder, outDecoder)
Run Code Online (Sandbox Code Playgroud)

第二个模型RepeatVector:

inputEncoder = Input(shape=(28, 1))
firstEncLayer = LSTM(112)(inputEncoder)
firstEncLayer = RepeatVector(1)(firstEncLayer)
snd = LSTM(56)(firstEncLayer)
snd = RepeatVector(1)(snd)
outEncoder = LSTM(28)(snd)
encoder_model = Model(inputEncoder, outEncoder)

context = RepeatVector(1)(outEncoder)
context_reshaped = Reshape((28, 1))(context)

firstDecoder = …
Run Code Online (Sandbox Code Playgroud)

autoencoder deep-learning lstm keras tensorflow

8
推荐指数
1
解决办法
5033
查看次数