小编A. *_*ski的帖子

用于构建自动编码器的 keras.Flatten 的逆

我的目标是构建一个卷积自动编码器,将输入图像编码为大小为 的平面向量(10,1)我按照 keras文档中的示例进行操作,并根据我的目的对其进行了修改。不幸的是,模型是这样的:

input_img = Input(shape=(28, 28, 1))

x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Flatten()(x)

encoded = Dense(units = 10, activation = 'relu')(x)


x = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded)
x = UpSampling2D((2, 2))(x)
x = Conv2D(16, (3, 3), activation='relu')(x)
x = UpSampling2D((2, 2))(x)
decoded = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x)

autoencoder = Model(input_img, decoded)
Run Code Online (Sandbox Code Playgroud)

给我 …

python autoencoder keras

6
推荐指数
1
解决办法
2273
查看次数

如何计算 Keras 模型中模型输入的损失梯度?

我想要实现的是计算交叉熵相对于输入值的梯度x。在 TensorFlow 中我没有遇到任何问题:

ce_grad = tf.gradients(cross_entropy, x)
Run Code Online (Sandbox Code Playgroud)

但随着我的网络变得越来越大,我改用 Keras 来更快地构建它们。但是,现在我真的不知道如何实现上述目标?有没有办法从model存储整个模型的变量中提取交叉熵和输入张量?

为了清楚起见,我的cross_entropy是:

cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels = y_, logits=y_conv))
<tf.Tensor 'Mean:0' shape=() dtype=float32>
Run Code Online (Sandbox Code Playgroud)

x

x = tf.placeholder(tf.float32, shape = [None,784])
<tf.Tensor 'Placeholder:0' shape=(?, 784) dtype=float32>
Run Code Online (Sandbox Code Playgroud)

python machine-learning neural-network keras tensorflow

4
推荐指数
1
解决办法
3874
查看次数