我训练了以下自动编码器模型:
input_img = Input(shape=(1, 32, 32))
x = Convolution2D(16, 3, 3, activation='relu', border_mode='same')(input_img)
x = MaxPooling2D((2, 2), border_mode='same')(x)
x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(x)
x = MaxPooling2D((2, 2), border_mode='same')(x)
x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(x)
encoded = MaxPooling2D((2, 2), border_mode='same')(x)
x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(encoded)
x = UpSampling2D((2, 2))(x)
x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(x)
x = UpSampling2D((2, 2))(x)
x = Convolution2D(16, 3, 3, activation='relu',border_mode='same')(x)
x = UpSampling2D((2, 2))(x)
decoded = Convolution2D(1, 3, 3, activation='sigmoid', …Run Code Online (Sandbox Code Playgroud) 我想要它的数学证明。有谁知道它的论文吗?或者可以练习数学吗?
machine-learning neural-network pca autoencoder deep-learning
我正在研究一个变分自动编码器 (VAE) 来检测时间序列中的异常。到目前为止,我使用了这个 tut https://blog.keras.io/building-autoencoders-in-keras.html和这个https://wiseodd.github.io/techblog/2016/12/10/variational-autoencoder/ .
不过,我在实施 VAE 时遇到了一些麻烦。我有 77093 个具有 1 维的样本。我使用 timesteps=100 进行预测。所以我重塑我的 x_train 如下:
x_train.shape = (77093, 100, 1)
Run Code Online (Sandbox Code Playgroud)
该模型:
inputs = Input(shape=(timesteps, input_dim))
encoded = LSTM(32)(inputs)
mu = Dense(1, activation='linear')(encoded)
log_sigma = Dense(1, activation='linear')(encoded)
z = Lambda(sample_z)([mu, log_sigma])
decoded = RepeatVector(timesteps)(z)
decoded = LSTM(1, return_sequences=True)(decoded)
decoded = LSTM(1)(decoded)
sequence_autoencoder = Model(inputs, decoded)
Run Code Online (Sandbox Code Playgroud)
我从以下样本中取样:
def sample_z(args):
mu, log_sigma = args
eps = K.random_normal(shape=(50, 1), mean=0., stddev=1.)
return mu + K.exp(log_sigma / 2) * eps
Run Code Online (Sandbox Code Playgroud)
模型编译。但我不知道它是否正确。 …
目前,我尝试为 tensorflow 中的时间序列数据构建一个自动编码器。我有将近 500 天的数据,其中每天有 24 个数据点。因为这是我第一次尝试,所以我的架构非常简单。在我输入 size 之后24,隐藏层的 size:10; 3; 10输出为 again 24。我对数据进行了标准化(数据点在范围内[-0.5; 0.5]),使用 sigmoid 激活函数和 RMSPropOptimizer。
训练后(图中的损失函数)对于我输入网络的每个时间数据,输出都是相同的。有人知道这是什么原因吗?我的数据集是否有可能是问题(下面的代码)?
class TimeDataset:
def __init__(self,data):
self._index_in_epoch = 0
self._epochs_completed = 0
self._data = data
self._num_examples = data.shape[0]
pass
@property
def data(self):
return self._data
def next_batch(self, batch_size, shuffle=True):
start = self._index_in_epoch
# first call
if start == 0 and self._epochs_completed == 0:
idx = np.arange(0, self._num_examples) # get all possible indexes
np.random.shuffle(idx) # shuffle indexe
self._data …Run Code Online (Sandbox Code Playgroud) 我试图在 Keras 中创建一个自定义的 Dense 层来绑定自动编码器中的权重。我已经尝试按照在卷积层中执行此操作的示例here,但似乎某些步骤不适用于 Dense 层(而且,代码来自两年多前)。
通过绑定权重,我希望解码层使用编码层的转置权重矩阵。本文(第 5 页)也采用了这种方法。以下是文章的相关引用:
在这里,我们选择编码和解码激活函数都为 sigmoid 函数,并且只考虑绑定权重的情况,其中 W ?= W T (其中 W T 是W的转置),就像大多数现有的深度学习方法一样。
在上面的引用中,W是编码层中的权重矩阵,W'(等于W的转置)是解码层中的权重矩阵。
我在密集层没有太大变化。我tied_to在构造函数中添加了一个参数,它允许您传递要绑定到的层。唯一的其他更改是对build函数的更改,其代码段如下:
def build(self, input_shape):
assert len(input_shape) >= 2
input_dim = input_shape[-1]
if self.tied_to is not None:
self.kernel = K.transpose(self.tied_to.kernel)
self._non_trainable_weights.append(self.kernel)
else:
self.kernel = self.add_weight(shape=(input_dim, self.units),
initializer=self.kernel_initializer,
name='kernel',
regularizer=self.kernel_regularizer,
constraint=self.kernel_constraint)
if self.use_bias:
self.bias = self.add_weight(shape=(self.units,),
initializer=self.bias_initializer,
name='bias',
regularizer=self.bias_regularizer,
constraint=self.bias_constraint)
else:
self.bias = None …Run Code Online (Sandbox Code Playgroud) 我正在开发一个基于火炬的库,用于使用表格数据集构建自动编码器。
一大特点是学习分类特征的嵌入。
然而,在实践中,同时训练许多嵌入层会造成一些减速。我正在使用 for 循环来执行此操作,并且在每次迭代中运行 for 循环是(我认为)导致速度变慢的原因。
在构建模型时,我将嵌入层与用户数据集中的每个分类特征相关联:
for ft in self.categorical_fts:
feature = self.categorical_fts[ft]
n_cats = len(feature['cats']) + 1
embed_dim = compute_embedding_size(n_cats)
embed_layer = torch.nn.Embedding(n_cats, embed_dim)
feature['embedding'] = embed_layer
Run Code Online (Sandbox Code Playgroud)
然后,调用 .forward():
embeddings = []
for i, ft in enumerate(self.categorical_fts):
feature = self.categorical_fts[ft]
emb = feature['embedding'](codes[i])
embeddings.append(emb)
#num and bin are numeric and binary features
x = torch.cat(num + bin + embeddings, dim=1)
Run Code Online (Sandbox Code Playgroud)
然后x进入密集层。
这完成了工作,但在每次前向传递期间运行此 for 循环确实会减慢训练速度,尤其是当数据集具有数十或数百个分类列时。
有人知道像这样矢量化的方法吗?谢谢!
更新:为了更清晰,我绘制了我如何将分类特征输入网络的草图。您可以看到每个分类列都有自己的嵌入矩阵,而数字特征在传递到前馈网络之前直接连接到它们的输出。
我们可以在不迭代每个嵌入矩阵的情况下做到这一点吗?
我正在训练一个 LSTM 自动编码器,但损失函数随机上升,如下图所示:
我尝试了多种方法来防止这种情况发生,调整批量大小,调整图层中的神经元数量,但似乎没有任何帮助。我检查了我的输入数据以查看它是否包含空值/无穷大值,但它没有,它也被标准化了。这是我的代码供参考:
model = Sequential()
model.add(Masking(mask_value=0, input_shape=(430, 3)))
model.add(LSTM(100, dropout=0.2, recurrent_dropout=0.2, activation='relu'))
model.add(RepeatVector(430))
model.add(LSTM(100, dropout=0.2, recurrent_dropout=0.2, activation='relu', return_sequences=True))
model.add(TimeDistributed(Dense(3)))
model.compile(optimizer='adam', loss='mean_squared_error', metrics=['accuracy'])
context_paths = loadFile()
X_train, X_test = train_test_split(context_paths, test_size=0.20)
history = model.fit(X_train, X_train, epochs=1, batch_size=4, verbose=1, validation_data=(X_test, X_test))
Run Code Online (Sandbox Code Playgroud)
损失函数在随机时间点爆炸,有时早些,有时晚些。我读到这个线程可能出现的问题,但在尝试多次后的事情这一点我不知道怎样做才能防止损失函数从随机暴涨。任何建议表示赞赏。除此之外,我可以看到我的准确度并没有增加多少,所以问题可能是相互关联的。
我正在数据集https://www.kaggle.com/jessicali9530/celeba-dataset上开发自动编码器 。
import tensorflow
tensorflow.__version__
Run Code Online (Sandbox Code Playgroud)
输出:
'2.2.0-rc3'
Run Code Online (Sandbox Code Playgroud)
from tensorflow.keras.preprocessing import image
data_gen = image.ImageDataGenerator(rescale=1.0/255)
batch_size = 20
train_data_gen = data_gen.flow_from_directory(directory=train_dest_path,
target_size=(256, 256),
batch_size=batch_size,
shuffle=True,
class_mode = 'input')
test_data_gen = data_gen.flow_from_directory(directory=test_dest_path,
target_size=(256,256),
batch_size=batch_size,
shuffle=True,
class_mode= 'input')
# autoencoder
from tensorflow.keras.layers import Input, Conv2D, MaxPooling2D, UpSampling2D
from tensorflow.keras import Model
from tensorflow.keras.optimizers import Adam, SGD
#parameters
inchannel = 3
x, y = 256, 256
input_img = Input(shape=(x,y,inchannel))
def autoencoder_model(input_img):
#encoder
conv1 = Conv2D(32, kernel_size=(3,3), activation='relu', padding='same')(input_img)
pool1 = MaxPooling2D(pool_size=(2,2))(conv1)
conv2 …Run Code Online (Sandbox Code Playgroud) 我正在尝试学习图像自动编码,但我无法使用输入和输出图像来训练模型
例如:输入图像文件夹:“.../Pictures/Input”
输出图像文件夹:“.../Pictures/Output”
#get input images from data_dir_input
ds_input = tf.keras.preprocessing.image_dataset_from_directory(
data_dir_input,
seed=123,
image_size=(img_height, img_width),
label_mode=None,
batch_size=batch_size)
#get output images from data_dir_output
ds_output = tf.keras.preprocessing.image_dataset_from_directory(
data_dir_output,
seed=123,
image_size=(img_height, img_width),
label_mode=None,
batch_size=batch_size)
# --------- model init etc --------------
# ...
model.fit(x=ds_input, y=ds_output, batch_size=32, epochs=50)
Run Code Online (Sandbox Code Playgroud)
但是我说这个错误:
`y` argument is not supported when using dataset as input
训练模型时如何使用自己的输入图像和输出图像?
我正在构建一个 UNET 模型。我陷入了一件事,如果我们必须将两个图像作为输入传递给 UNET,我们可以通过连接它们来完成它,就像下面的代码
inputs = []
for _ in range(num_inputs):
inputs.append(Input((self.input_height, self.input_width, self.input_features)))
x = concatenate(inputs)
x = Conv2D(32, (3, 3), activation='relu', padding='same')(x)
Run Code Online (Sandbox Code Playgroud)
但是我们如何才能在一次通过中获得两个图像作为输出?
artificial-intelligence machine-learning autoencoder deep-learning unity3d-unet
autoencoder ×10
keras ×6
python ×6
tensorflow ×3
lstm ×2
embedding ×1
inference ×1
pca ×1
pytorch ×1
torch ×1
unity3d-unet ×1