How to share convolution kernels between layers in keras?

前端 未结 2 796
情深已故
情深已故 2021-01-20 00:11

Suppose I want to compare two images with deep convolutional NN. How can I implement two different pathways with the same kernels in keras?

Like this:

2条回答
  •  [愿得一人]
    2021-01-20 00:32

    Indeed using the same (instance of) layer twice ensures that the weights will be shared.

    Just look at the siamese example, I just put here an excerpt from the model to show an example:

    # because we re-use the same instance `base_network`,
    # the weights of the network
    # will be shared across the two branches
    processed_a = base_network(input_a)
    processed_b = base_network(input_b)
    

提交回复
热议问题