【发布时间】:2020-09-27 06:25:24
【问题描述】:
实际上我正在尝试在 keras 上重现 tensorflow 模型,我对这个主题真的很陌生。 我想重现这些行
embedding = tf.layers.conv2d(conv6, 128, (16, 16), padding='VALID', name='embedding')
embedding = tf.reshape(embedding, (-1, 128))
embedding = embedding - tf.reduce_min(embedding, keepdims =True)
z_n = embedding/tf.reduce_max(embedding, keepdims =True)
我的实际代码是:
def conv_conv_pool(n_filters,
name,
pool=True,
activation=tf.nn.relu, padding='same', filters=(3,3)):
"""{Conv -> BN -> RELU}x2 -> {Pool, optional}
Args:
input_ (4-D Tensor): (batch_size, H, W, C)
n_filters (list): number of filters [int, int]
training (1-D Tensor): Boolean Tensor
name (str): name postfix
pool (bool): If True, MaxPool2D
activation: Activaion functions
Returns:
net: output of the Convolution operations
pool (optional): output of the max pooling operations
"""
net = Sequential()
for i, F in enumerate(n_filters):
conv = Conv2D(
filters = F,
kernel_size = (3,3),
padding = 'same',
)
net.add(conv)
batch_norm = BatchNormalization()
net.add(batch_norm)
net.add(Activation('relu'))
if pool is False:
return net
pool = Conv2D(
filters = F,
kernel_size = (3,3),
strides = (2,2),
padding = 'same',
)
net.add(pool)
batch_norm = BatchNormalization()
net.add(batch_norm)
net.add(Activation('relu'))
return net
def model_keras():
model = Sequential()
model.add(conv_conv_pool(n_filters = [8, 8], name="1"))
model.add(conv_conv_pool([32, 32], name="2"))
model.add(conv_conv_pool([32, 32], name="3"))
model.add(conv_conv_pool([64, 64], name="4"))
model.add(conv_conv_pool([64, 64], name="5"))
model.add(conv_conv_pool([128, 128], name="6", pool=False))
return model
标准化应该在第 6 层之后。
我正在考虑使用 lambda 层,这是否正确?是的话应该怎么写?
【问题讨论】:
-
为了更好地解释我的情况。实际上我正在 Keras 上写一个序列(这里是代码)` def model_keras(): model = Sequential() model.add(conv_conv_pool(n_filters = [8, 8], name="1")) model.add( conv_conv_pool([32, 32], name="2")) model.add(conv_conv_pool([32, 32], name="3")) model.add(conv_conv_pool([64, 64], name="4 ")) model.add(conv_conv_pool([64, 64], name="5")) model.add(conv_conv_pool([128, 128], name="6", pool=False)) `我想要在名为“6”的层上进行操作,但我不太清楚该怎么做
-
请在编辑问题上方插入您的代码。如果可能的话,还报告什么是 conv_conv_pool
-
好的,谢谢,现在很清楚了……您引用的规范化接收来自卷积层(4d 形状)的输入,然后尝试返回 2d 形状。这是正确的吗?是你要找的吗?还是在输出中保持 al 4d 更好?
-
@MarcoCerliani 是的,我想通过 4d 到 2d 进行重塑
-
@MarcoCerliani 非常感谢你,我要试试并告诉你
标签: python tensorflow keras normalization