text
stringlengths
0
4.99k
_________________________________________________________________
inv_1 (Involution) ((None, 32, 32, 3), (None 26
_________________________________________________________________
re_lu_3 (ReLU) (None, 32, 32, 3) 0
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 16, 16, 3) 0
_________________________________________________________________
inv_2 (Involution) ((None, 16, 16, 3), (None 26
_________________________________________________________________
re_lu_4 (ReLU) (None, 16, 16, 3) 0
_________________________________________________________________
max_pooling2d_3 (MaxPooling2 (None, 8, 8, 3) 0
_________________________________________________________________
inv_3 (Involution) ((None, 8, 8, 3), (None, 26
_________________________________________________________________
re_lu_5 (ReLU) (None, 8, 8, 3) 0
_________________________________________________________________
flatten_1 (Flatten) (None, 192) 0
_________________________________________________________________
dense_2 (Dense) (None, 64) 12352
_________________________________________________________________
dense_3 (Dense) (None, 10) 650
=================================================================
Total params: 13,080
Trainable params: 13,074
Non-trainable params: 6
_________________________________________________________________
Loss and Accuracy Plots
Here, the loss and the accuracy plots demonstrate that INNs are slow learners (with lower parameters).
plt.figure(figsize=(20, 5))
plt.subplot(1, 2, 1)
plt.title(\"Convolution Loss\")
plt.plot(conv_hist.history[\"loss\"], label=\"loss\")
plt.plot(conv_hist.history[\"val_loss\"], label=\"val_loss\")
plt.legend()
plt.subplot(1, 2, 2)
plt.title(\"Involution Loss\")
plt.plot(inv_hist.history[\"loss\"], label=\"loss\")
plt.plot(inv_hist.history[\"val_loss\"], label=\"val_loss\")
plt.legend()
plt.show()
plt.figure(figsize=(20, 5))
plt.subplot(1, 2, 1)
plt.title(\"Convolution Accuracy\")
plt.plot(conv_hist.history[\"accuracy\"], label=\"accuracy\")
plt.plot(conv_hist.history[\"val_accuracy\"], label=\"val_accuracy\")
plt.legend()
plt.subplot(1, 2, 2)
plt.title(\"Involution Accuracy\")
plt.plot(inv_hist.history[\"accuracy\"], label=\"accuracy\")
plt.plot(inv_hist.history[\"val_accuracy\"], label=\"val_accuracy\")
plt.legend()
plt.show()
png
png
Visualizing Involution Kernels
To visualize the kernels, we take the sum of K×K values from each involution kernel. All the representatives at different spatial locations frame the corresponding heat map.
The authors mention:
\"Our proposed involution is reminiscent of self-attention and essentially could become a generalized version of it.\"
With the visualization of the kernel we can indeed obtain an attention map of the image. The learned involution kernels provides attention to individual spatial positions of the input tensor. The location-specific property makes involution a generic space of models in which self-attention belongs.
layer_names = [\"inv_1\", \"inv_2\", \"inv_3\"]
outputs = [inv_model.get_layer(name).output for name in layer_names]
vis_model = keras.Model(inv_model.input, outputs)
fig, axes = plt.subplots(nrows=10, ncols=4, figsize=(10, 30))
for ax, test_image in zip(axes, test_images[:10]):
(inv1_out, inv2_out, inv3_out) = vis_model.predict(test_image[None, ...])
_, inv1_kernel = inv1_out
_, inv2_kernel = inv2_out
_, inv3_kernel = inv3_out
inv1_kernel = tf.reduce_sum(inv1_kernel, axis=[-1, -2, -3])
inv2_kernel = tf.reduce_sum(inv2_kernel, axis=[-1, -2, -3])
inv3_kernel = tf.reduce_sum(inv3_kernel, axis=[-1, -2, -3])
ax[0].imshow(keras.preprocessing.image.array_to_img(test_image))
ax[0].set_title(\"Input Image\")
ax[1].imshow(keras.preprocessing.image.array_to_img(inv1_kernel[0, ..., None]))
ax[1].set_title(\"Involution Kernel 1\")
ax[2].imshow(keras.preprocessing.image.array_to_img(inv2_kernel[0, ..., None]))
ax[2].set_title(\"Involution Kernel 2\")