【问题标题】:Tensorflow CNN: Accessing the data from the Convolution layer to be used in the Lambda layerTensorflow CNN:从卷积层访问数据以在 Lambda 层中使用
【发布时间】:2020-09-12 23:09:44
【问题描述】:

我正在使用 Tensorflow 2.x 在卷积层之后创建一个 Lambda 层。 我有一个名为“custom_layer”的函数,它接收前一个卷积层的张量输出。 我需要从这个张量中提取卷积层的每个特征图并执行数学运算。 最后,必须将输出组合成一个张量并返回以用于下一层。

#Lamba layer
def custom_layer(tensor):
    # perform operation on individual feature maps


    # return the combined tensor output
    return tensor
model = tf.keras.models.Sequential([
    tf.keras.layers.Conv2D(filters= 64, kernel_size= (3,3), input_shape = (28,28,1), activation = 'relu', name = 'conv2D_1'),

    tf.keras.layers.Lambda(custom_layer, name="lambda_layer"),

    tf.keras.layers.Conv2D(filters= 64, kernel_size= (3,3), activation = 'relu', name = 'conv2D_2'),
    tf.keras.layers.MaxPooling2D(pool_size = (2,2), name = 'MaxPool2D_1'),      
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dense(10, activation= 'softmax')])

使用tf.print(tensor) 我能够查看张量输出(特征图)。但我无法找到访问这些单独特征图的方法。

【问题讨论】:

  • 比如,哪种操作?

标签: tensorflow keras deep-learning conv-neural-network tensorflow2.0


【解决方案1】:

问题解决了。我在 custom_layer(tensor) 函数中使用了 tf.py_function()。

【讨论】:

  • 尊敬的先生,请您分享您对这个问题的回答。我是 tensorflow 和 keras 的新手,几个月前我一直在寻找这个问题的解决方案。请你救我的命。你是唯一的希望..
猜你喜欢
  • 1970-01-01
  • 2018-06-21
  • 1970-01-01
  • 2018-02-11
  • 1970-01-01
  • 2017-10-21
  • 2019-07-10
  • 2015-07-23
  • 1970-01-01
相关资源
最近更新 更多