如何使用 Keras 创建侧输出层?

How to create side output layer with Keras?

我尝试从这个Article

中建立深度学习模型

# My code now
img_rows, img_cols = 3280, 2464
input_shape = (1, img_rows, img_cols)
model = Sequential()
model.add(Conv2D(64, (3, 3), activation='relu', input_shape=input_shape))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(128, (3, 3), activation='relu'))
model.add(Conv2D(128, (3, 3), activation='relu'))
model.add(Conv2D(128, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(256, (3, 3), activation='relu'))
model.add(Conv2D(256, (3, 3), activation='relu'))
model.add(Conv2D(256, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(512, (3, 3), activation='relu'))
model.add(Conv2D(512, (3, 3), activation='relu'))
model.add(Conv2D(512, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(512, (3, 3), activation='relu'))
model.add(Conv2D(512, (3, 3), activation='relu'))
model.add(Conv2D(512, (3, 3), activation='relu'))

从图中可以看出,它有分支层(红色矩形)然后连接起来。

如何在 Keras 中正确执行此操作,或者我需要使用 tensorflow?

不要使用顺序 API 实现网络,使用 keras 的功能 API,这是小菜一碟。

这是一个并行层与 keras API 函数连接的示例。

  branchA = Conv3D(filters=filters, kernel_size=kernel_size, padding='same')(input_layer)

  branchB = Conv3D(filters=filters, kernel_size=kernel_size, padding='same')(input_layer)

  branchC = Conv3D(filters=filters, kernel_size=kernel_size, padding='same')(input_layer)
  branchC = Conv3D(filters=filters, kernel_size=kernel_size, padding='same')(branchC )

  branchD = Conv3D(filters=filters, kernel_size=kernel_size, padding='same')(input_layer)
  branchD = Conv3D(filters=filters, kernel_size=kernel_size, padding='same')(branchD )
  branchD = Conv3D(filters=filters, kernel_size=kernel_size, padding='same')(branchD )

  finconc = concatenate([branchA, branchB, branchC, branchD], axis=-1)

参考这里: https://keras.io/guides/functional_api/