"tinyCub = torchvision.datasets.ImageFolder(root=\"./data/test_tiny\", transform=transform)# The model was trained on normalized images to improve its performance. Therefore, normalization must also be applied on test images.\n",
"# The model was trained on normalized images to improve its performance. Therefore, normalization must also be applied on test images.\n",
"Finally, we will compute the average precision on the dataset. We should have an accuracy of about 61%."
"Finally, we will compute the average precision on the dataset. We should have an accuracy of about 69%."
]
]
},
},
{
{
...
@@ -244,7 +241,7 @@
...
@@ -244,7 +241,7 @@
"id": "bc186f4e-7725-4b98-abfa-cee5eed947f9",
"id": "bc186f4e-7725-4b98-abfa-cee5eed947f9",
"metadata": {},
"metadata": {},
"source": [
"source": [
"We see that the gradients focus a lot on the neck and the tail, but also on the top corners of the image. Altough it may describe how the neural network take its decision, it may not match the human decision process to classify a duck."
"We see that the gradients focus a lot on the head, wings and tail; but also on the top corners of the image. Altough it may describe how the neural network take its decision, it may not match the human decision process to classify an albatross."
]
]
},
},
{
{
...
@@ -274,7 +271,7 @@
...
@@ -274,7 +271,7 @@
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"n_samples = 50\n",
"n_samples = 10 # Number of perturbed samples per step\n",
"sigma = 0.1"
"sigma = 0.1"
]
]
},
},
...
@@ -299,7 +296,7 @@
...
@@ -299,7 +296,7 @@
"id": "f504bb5e-6a3a-4a64-aec8-fe62b38e16aa",
"id": "f504bb5e-6a3a-4a64-aec8-fe62b38e16aa",
"metadata": {},
"metadata": {},
"source": [
"source": [
"With averaged gradients, the interpretation seems much less noisy. With a sufficiently high number of samples and a low standard deviation, the gradient seems to vary a lot around the neck to the tail, with some specks on the corner of the image and the beak."
"With averaged gradients, the interpretation seems much less noisy. With a sufficiently high number of samples and a low standard deviation, the gradient seems to vary a lot around the head."
]
]
},
},
{
{
...
@@ -319,6 +316,18 @@
...
@@ -319,6 +316,18 @@
"$$"
"$$"
]
]
},
},
{
"cell_type": "code",
"execution_count": null,
"id": "e2b779ba-05e4-4cfe-925c-4668644441d2",
"metadata": {},
"outputs": [],
"source": [
"n_steps = 20 # Number of Integrated Gradients steps\n",
"The Integrated Gradients display how much variations (in term of gradient) exist between a white image and the actual image.\n",
"The Integrated Gradients display how much variations (in term of gradient) exist between a white image and the actual image. Note that the heatmaps are now located on the wings.\n",
"We will now combine Integrated Gradients with SmoothGrads."
"We will now combine Integrated Gradients with SmoothGrads."
]
]
},
},
{
"cell_type": "code",
"execution_count": null,
"id": "3011d1d3-8fbd-4a22-b6df-4fafdbc9f563",
"metadata": {},
"outputs": [],
"source": [
"n_steps = 20 # Number of Integrated gradients steps\n",
"n_samples = 10 # Number of perturbed samples per step\n",
"sigma = 0.1"
]
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": null,
...
@@ -374,10 +370,19 @@
...
@@ -374,10 +370,19 @@
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"id": "a01eae6b-e595-4d4d-bb2c-10c861f8a6fe",
"id": "113772f6-dae3-4622-9019-0cc96ea8556c",
"metadata": {},
"metadata": {},
"source": [
"source": [
"We note that integrated gradients with smoothgrads provide much more focused variations.\n",
"We note that integrated gradients with smoothgrads provide much more focused variations."
]
},
{
"cell_type": "markdown",
"id": "1e606715-69ee-490d-a3ff-61f3890a42b9",
"metadata": {},
"source": [
"You can change the image and rerun the experiments to see how those two approaches vary.\n",
"\n",
"\n",
"\n",
"Overall, we note that with these three approaches we obtain seemingly similar results. But the following questions remain:\n",
"Overall, we note that with these three approaches we obtain seemingly similar results. But the following questions remain:\n",