2
votes

When using CNN with tensorflow, what the convulsion matrix looks like (what are the kernel values) ?

Look on this basic example of CNN:

    model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)))
    model.add(layers.MaxPooling2D((2, 2)))
    model.add(layers.Conv2D(64, (3, 3), activation='relu'))
    model.add(layers.MaxPooling2D((2, 2)))
    model.add(layers.Conv2D(64, (3, 3), activation='relu'))
  1. what the convolution matrix looks like ? what are the values of the 3x3 matrix ?

  2. In the example above, we use 3 Conv2D layers (each layer use 3x3 convultion matrix). Does those 3 matrixes are the same ? or they will have different values ?

1

1 Answers

1
votes
  1. Each convolution layer will have a weight and bias which can be inspected using
# For 1 layer <conv> (weight)
model.layers[0].get_weights()[0]

# For 1 layer <conv> (bias)
model.layers[0].get_weights()[1]

# For 2 layer <pool> (no weight and bias term) <so empty list is returned>
model.layers[1].get_weights()

#and so on....

conv matrix is a 4D tensor (in_channel × filter_size × filter_size × out_channel) and for your case: (3, 3, 3, 32).

  1. Each filter will have different value. Nothing is common.