Я хочу визуализировать 1D-фильтры моего 1D-CNN, используя метод градиентного всплытия (https://blog.keras.io/how-convolutional-neural-networks-see-the-world.html).. Ниже приводится сводная информация о моей модели и код, который я пробовал.
Model.summary() #after removing the fully connected layers.
Layer (type) Output Shape Param #
=================================================================
conv1d_5_input (InputLayer) (None, 289, 2493) 0
_________________________________________________________________
conv1d_5 (Conv1D) (None, 131, 22) 1535710
_________________________________________________________________
batch_normalization_12 (Batc (None, 131, 22) 88
_________________________________________________________________
activation_12 (Activation) (None, 131, 22) 0
_________________________________________________________________
max_pooling1d_5 (MaxPooling1 (None, 65, 22) 0
_________________________________________________________________
dropout_14 (Dropout) (None, 65, 22) 0
_________________________________________________________________
conv1d_6 (Conv1D) (None, 30, 30) 23790
_________________________________________________________________
batch_normalization_13 (Batc (None, 30, 30) 120
_________________________________________________________________
activation_13 (Activation) (None, 30, 30) 0
_________________________________________________________________
max_pooling1d_6 (MaxPooling1 (None, 15, 30) 0
=================================================================
Total params: 1,559,708
Trainable params: 1,559,604
Non-trainable params: 104
layer_dict = dict([(layer.name, layer) for layer in model2.layers])
input_img = model2.input
layer_name = 'conv1d_5'
filter_index = 18
layer_output = layer_dict[layer_name].output
loss_fxn = K.mean(layer_output[ :, :, filter_index])
# Find gradient of loss_fxn w.r.t. the input_img
gradient = K.gradients(loss_fxn, input_img)[0]
# Normalize the gradient
gradient = gradient / (K.sqrt(K.mean(K.square(gradient))) + 1e-05)
iterate = K.function([input_img], [loss_fxn, gradient])
w = 256
h = 256
input_img_data = np.random.random((1, w, h, 3))*20 + 128 ##NOISY IMAGE
step_size = 1
steps = 100
for i in range(steps):
loss, grads = iterate([input_img_data])
input_img_data = input_img_data + grads*step_size
print("Step: {}/{}, Loss: {}".format(i+1, steps, loss))
Это ошибка, которую я получаю:
InvalidArgumentError: transpose ожидает вектор размера 5. Но input (1) - это вектор размера 4 [[{{node conv1d_5_1 / convolution / Conv2D-0-TransposeNHWCToNCHW-LayoutOptimizer}}]] [[{{node Mean_10}}]] *
Как визуализировать мои 1D-фильтры?