\n",
@@ -550,7 +550,7 @@
},
{
"cell_type": "markdown",
- "id": "849fa319",
+ "id": "b08a5590",
"metadata": {},
"source": [
"
Checkpoint 2
\n",
@@ -570,7 +570,7 @@
},
{
"cell_type": "markdown",
- "id": "876bdd3b",
+ "id": "13b502ee",
"metadata": {
"lines_to_next_cell": 0
},
@@ -598,7 +598,7 @@
},
{
"cell_type": "markdown",
- "id": "5a1c2a34",
+ "id": "a39a4234",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -621,7 +621,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "85aa4a15",
+ "id": "ccbd9243",
"metadata": {},
"outputs": [],
"source": [
@@ -653,7 +653,7 @@
},
{
"cell_type": "markdown",
- "id": "2b95f3e8",
+ "id": "3d75236e",
"metadata": {
"lines_to_next_cell": 0
},
@@ -668,7 +668,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "ac1205e5",
+ "id": "edd299c4",
"metadata": {
"lines_to_next_cell": 0,
"tags": [
@@ -689,7 +689,7 @@
},
{
"cell_type": "markdown",
- "id": "9c976d43",
+ "id": "8cc42dea",
"metadata": {
"tags": []
},
@@ -704,7 +704,7 @@
},
{
"cell_type": "markdown",
- "id": "881575de",
+ "id": "afa65120",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -721,7 +721,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "e43f27f1",
+ "id": "4088b0ab",
"metadata": {
"lines_to_next_cell": 0,
"tags": [
@@ -735,7 +735,7 @@
},
{
"cell_type": "markdown",
- "id": "d29d8d58",
+ "id": "5b47154f",
"metadata": {
"lines_to_next_cell": 0
},
@@ -746,7 +746,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "f51b15fc",
+ "id": "fb6eecc1",
"metadata": {},
"outputs": [],
"source": [
@@ -756,7 +756,7 @@
},
{
"cell_type": "markdown",
- "id": "73814dae",
+ "id": "c79251f6",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -774,7 +774,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "5fc36682",
+ "id": "810cae99",
"metadata": {
"lines_to_next_cell": 0
},
@@ -786,7 +786,7 @@
},
{
"cell_type": "markdown",
- "id": "e07edb85",
+ "id": "19e0a570",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -805,7 +805,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "5082b8ab",
+ "id": "8eb2fe39",
"metadata": {},
"outputs": [],
"source": [
@@ -814,7 +814,7 @@
},
{
"cell_type": "markdown",
- "id": "43ef8a2d",
+ "id": "7ffb373b",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -830,7 +830,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "468fe88f",
+ "id": "1a5c8832",
"metadata": {},
"outputs": [],
"source": [
@@ -839,7 +839,7 @@
},
{
"cell_type": "markdown",
- "id": "6dd0f856",
+ "id": "2b585f2b",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -851,7 +851,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "89da32d6",
+ "id": "e957ad43",
"metadata": {},
"outputs": [],
"source": [
@@ -864,7 +864,7 @@
},
{
"cell_type": "markdown",
- "id": "2b894eac",
+ "id": "204a9236",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -878,7 +878,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "b25e284e",
+ "id": "b87e8d1e",
"metadata": {},
"outputs": [],
"source": [
@@ -890,7 +890,7 @@
},
{
"cell_type": "markdown",
- "id": "72125f93",
+ "id": "618bebe4",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -910,7 +910,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "41cf9baf",
+ "id": "258d6086",
"metadata": {},
"outputs": [],
"source": [
@@ -934,7 +934,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "a5b1fb2e",
+ "id": "724e40db",
"metadata": {
"lines_to_next_cell": 2
},
@@ -946,7 +946,7 @@
},
{
"cell_type": "markdown",
- "id": "421a4724",
+ "id": "4ad4b22d",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -968,7 +968,7 @@
},
{
"cell_type": "markdown",
- "id": "d375c071",
+ "id": "271bc482",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -980,7 +980,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "f782b7f0",
+ "id": "8f5fb50f",
"metadata": {
"lines_to_next_cell": 0,
"tags": [
@@ -1091,7 +1091,7 @@
},
{
"cell_type": "markdown",
- "id": "bf2700e1",
+ "id": "e323e6f7",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -1103,7 +1103,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "93af3047",
+ "id": "fd20bc6e",
"metadata": {},
"outputs": [],
"source": [
@@ -1119,7 +1119,7 @@
},
{
"cell_type": "markdown",
- "id": "65452041",
+ "id": "240c3164",
"metadata": {
"tags": []
},
@@ -1134,7 +1134,7 @@
},
{
"cell_type": "markdown",
- "id": "db668256",
+ "id": "deb3d3a0",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -1146,7 +1146,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "f76c5e65",
+ "id": "d3f7104a",
"metadata": {},
"outputs": [],
"source": [
@@ -1168,7 +1168,7 @@
},
{
"cell_type": "markdown",
- "id": "573bb9d9",
+ "id": "6c7e4472",
"metadata": {
"tags": []
},
@@ -1184,7 +1184,7 @@
},
{
"cell_type": "markdown",
- "id": "26dfd88b",
+ "id": "b3c5bbd0",
"metadata": {
"tags": []
},
@@ -1194,7 +1194,7 @@
},
{
"cell_type": "markdown",
- "id": "f48126ab",
+ "id": "7c8c76fe",
"metadata": {
"tags": []
},
@@ -1211,7 +1211,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "4305090b",
+ "id": "3d4f212c",
"metadata": {
"title": "Loading the test dataset"
},
@@ -1231,7 +1231,7 @@
},
{
"cell_type": "markdown",
- "id": "154db796",
+ "id": "0394fb82",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -1243,7 +1243,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "ebbcd12d",
+ "id": "f7e02a34",
"metadata": {},
"outputs": [],
"source": [
@@ -1256,7 +1256,7 @@
},
{
"cell_type": "markdown",
- "id": "61d5d4bc",
+ "id": "bc9acb76",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1266,7 +1266,7 @@
},
{
"cell_type": "markdown",
- "id": "7ae07350",
+ "id": "54fb79ed",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1284,7 +1284,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "bca04b2a",
+ "id": "068cff35",
"metadata": {
"lines_to_next_cell": 0,
"tags": [
@@ -1320,7 +1320,7 @@
},
{
"cell_type": "markdown",
- "id": "bebb99c9",
+ "id": "255934ec",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -1332,7 +1332,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "c87df0c0",
+ "id": "6daca8ca",
"metadata": {},
"outputs": [],
"source": [
@@ -1345,7 +1345,7 @@
},
{
"cell_type": "markdown",
- "id": "2fbc38e9",
+ "id": "18186b93",
"metadata": {
"tags": []
},
@@ -1360,7 +1360,7 @@
},
{
"cell_type": "markdown",
- "id": "baf8c83a",
+ "id": "29b63b00",
"metadata": {
"tags": []
},
@@ -1371,7 +1371,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "2465c04b",
+ "id": "411b8730",
"metadata": {},
"outputs": [],
"source": [
@@ -1385,7 +1385,7 @@
},
{
"cell_type": "markdown",
- "id": "35613805",
+ "id": "dcce6a0c",
"metadata": {
"tags": []
},
@@ -1400,7 +1400,7 @@
},
{
"cell_type": "markdown",
- "id": "321fcad6",
+ "id": "106316e5",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1415,7 +1415,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "1c45c814",
+ "id": "152bed37",
"metadata": {},
"outputs": [],
"source": [
@@ -1436,7 +1436,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "584f13f4",
+ "id": "3d722e25",
"metadata": {
"title": "Another visualization function"
},
@@ -1465,7 +1465,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "df33dd4a",
+ "id": "04eabebc",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1473,7 +1473,7 @@
"source": [
"for idx in range(batch_size):\n",
" print(\"Source class:\", y[idx].item())\n",
- " print(\"Target class:\", 0)\n",
+ " print(\"Target class:\", target_class)\n",
" visualize_color_attribution_and_counterfactual(\n",
" attributions[idx].cpu().numpy(), x[idx].cpu().numpy(), x_fake[idx].cpu().numpy()\n",
" )"
@@ -1481,7 +1481,7 @@
},
{
"cell_type": "markdown",
- "id": "f2bdfa5d",
+ "id": "46e50c88",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1497,11 +1497,21 @@
},
{
"cell_type": "markdown",
- "id": "da87745e",
+ "id": "a9b101b6",
"metadata": {
"lines_to_next_cell": 0
},
"source": [
+ "By now you will have hopefully noticed that it isn't the exact color of the image that determines its class, but that two images with a very similar color can be of different classes!\n",
+ "\n",
+ "Here are two examples of image-counterfactual-attribution triplets.\n",
+ "You'll notice that they are *very* similar in every way! But one set is different classes, and one set is the same class!\n",
+ "\n",
+ "![same_class](assets/same_class.png)\n",
+ "![diff_class](assets/diff_class.png)\n",
+ "\n",
+ "We are missing a crucial step of the explanation pipeline: a quantification of how the class changes over the interpolation. \n",
+ "\n",
"In the lecture, we used the attribution to act as a mask, to gradually go from the original image to the counterfactual image.\n",
"This allowed us to classify all of the intermediate images, and learn how the class changed over the interpolation.\n",
"Here we have a much simpler task so we have some advantages:\n",
@@ -1512,7 +1522,7 @@
},
{
"cell_type": "markdown",
- "id": "88f10203",
+ "id": "246fda63",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1526,7 +1536,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "2e79affe",
+ "id": "2e9602ae",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1546,7 +1556,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "70f9846e",
+ "id": "a6039426",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1582,7 +1592,7 @@
},
{
"cell_type": "markdown",
- "id": "386a9f4c",
+ "id": "62c10f55",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1596,7 +1606,7 @@
},
{
"cell_type": "markdown",
- "id": "ae25a656",
+ "id": "f35c78d1",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1612,46 +1622,37 @@
},
{
"cell_type": "markdown",
- "id": "53c7b041",
+ "id": "ce0defa7",
"metadata": {
"lines_to_next_cell": 0
},
"source": [
"
Checkpoint 4
\n",
"At this point you have:\n",
- "- Created a StarGAN that can change the class of an image\n",
- "- Evaluated the StarGAN on unseen data\n",
- "- Used the StarGAN to create counterfactual images\n",
- "- Used the counterfactual images to highlight the differences between classes\n",
- "- Interpolated between the images to see how the classifier behaves\n"
+ "
\n",
+ "- Created a StarGAN that can change the class of an image
\n",
+ "- Evaluated the StarGAN on unseen data
\n",
+ "- Used the StarGAN to create counterfactual images
\n",
+ "- Used the counterfactual images to highlight the differences between classes
\n",
+ "- Interpolated between the images to see how the classifier behaves
\n",
+ "
"
]
},
{
"cell_type": "markdown",
- "id": "c75ed748",
+ "id": "bbd7820d",
"metadata": {
"lines_to_next_cell": 0
},
"source": [
"# Part 5: Exploring the Style Space, finding the answer\n",
- "By now you will have hopefully noticed that it isn't the exact color of the image that determines its class, but that two images with a very similar color can be of different classes!\n",
- "\n",
- "Here is an example of two images that are very similar in color, but are of different classes.\n",
- "![same_color_diff_class](assets/same_color_diff_class.png)\n",
- "While both of the images are yellow, the attribution tells us (if you squint!) that one of the yellows has slightly more blue in it!\n",
- "\n",
- "Conversely, here is an example of two images with very different colors, but that are of the same class:\n",
- "![same_class_diff_color](assets/same_class_diff_color.png)\n",
- "Here the attribution is empty! Using the discriminative attribution we can see that the significant color change doesn't matter at all!\n",
- "\n",
- "\n",
"So color is important... but not always? What's going on!?\n",
"There is a final piece of information that we can use to solve the puzzle: the style space."
]
},
{
"cell_type": "markdown",
- "id": "45dcb17b",
+ "id": "141b4181",
"metadata": {},
"source": [
"
Task 5.1: Explore the style space
\n",
@@ -1663,7 +1664,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "11309f0a",
+ "id": "b6e9c103",
"metadata": {},
"outputs": [],
"source": [
@@ -1698,7 +1699,7 @@
},
{
"cell_type": "markdown",
- "id": "e7e0f8d4",
+ "id": "c01c00f7",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1714,7 +1715,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "cc183548",
+ "id": "11b7d4c9",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1741,7 +1742,7 @@
},
{
"cell_type": "markdown",
- "id": "9f34f021",
+ "id": "2c53c235",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1755,7 +1756,7 @@
},
{
"cell_type": "markdown",
- "id": "5d29071b",
+ "id": "9d81df42",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1772,7 +1773,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "366dd45c",
+ "id": "081a67e4",
"metadata": {},
"outputs": [],
"source": [
@@ -1794,7 +1795,7 @@
},
{
"cell_type": "markdown",
- "id": "b657a0f5",
+ "id": "1d74498c",
"metadata": {},
"source": [
"
Questions
\n",
@@ -1806,17 +1807,19 @@
},
{
"cell_type": "markdown",
- "id": "35b0a886",
+ "id": "1efd608c",
"metadata": {},
"source": [
"
Checkpoint 5
\n",
"Congratulations! You have made it to the end of the exercise!\n",
"You have:\n",
- "- Created a StarGAN that can change the class of an image\n",
- "- Evaluated the StarGAN on unseen data\n",
- "- Used the StarGAN to create counterfactual images\n",
- "- Used the counterfactual images to highlight the differences between classes\n",
- "- Used the style space to understand the differences between classes\n",
+ "
\n",
+ "- Created a StarGAN that can change the class of an image
\n",
+ "- Evaluated the StarGAN on unseen data
\n",
+ "- Used the StarGAN to create counterfactual images
\n",
+ "- Used the counterfactual images to highlight the differences between classes
\n",
+ "- Used the style space to understand the differences between classes
\n",
+ "
\n",
"\n",
"If you have any questions, feel free to ask them in the chat!\n",
"And check the Solutions exercise for a definite answer to how these classes are defined!"
@@ -1824,7 +1827,7 @@
},
{
"cell_type": "markdown",
- "id": "c7f12c18",
+ "id": "4f71144a",
"metadata": {},
"source": [
"# Bonus!\n",
diff --git a/solution.ipynb b/solution.ipynb
index b8d9964..b2359d5 100644
--- a/solution.ipynb
+++ b/solution.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
- "id": "2cec6e2e",
+ "id": "508f55c4",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -29,7 +29,7 @@
},
{
"cell_type": "markdown",
- "id": "c9faff54",
+ "id": "88480b87",
"metadata": {
"lines_to_next_cell": 0
},
@@ -41,7 +41,7 @@
},
{
"cell_type": "markdown",
- "id": "8b2714f2",
+ "id": "62e6288c",
"metadata": {},
"source": [
"\n",
@@ -54,7 +54,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "196887ff",
+ "id": "524e722d",
"metadata": {
"lines_to_next_cell": 0
},
@@ -68,7 +68,7 @@
},
{
"cell_type": "markdown",
- "id": "dc029ece",
+ "id": "c9c22ad8",
"metadata": {
"lines_to_next_cell": 0
},
@@ -84,7 +84,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "3f76a8a6",
+ "id": "25fb11b9",
"metadata": {},
"outputs": [],
"source": [
@@ -102,7 +102,7 @@
},
{
"cell_type": "markdown",
- "id": "9ec21db3",
+ "id": "cc3c08e3",
"metadata": {
"lines_to_next_cell": 0
},
@@ -113,7 +113,7 @@
},
{
"cell_type": "markdown",
- "id": "06793f28",
+ "id": "254aef78",
"metadata": {
"lines_to_next_cell": 0
},
@@ -130,7 +130,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "becee066",
+ "id": "469219c6",
"metadata": {
"tags": [
"solution"
@@ -154,7 +154,7 @@
},
{
"cell_type": "markdown",
- "id": "e0d3e182",
+ "id": "61dbe630",
"metadata": {
"lines_to_next_cell": 0
},
@@ -165,7 +165,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "0bd2cb1e",
+ "id": "4ffba779",
"metadata": {
"lines_to_next_cell": 0
},
@@ -194,7 +194,7 @@
},
{
"cell_type": "markdown",
- "id": "88a42af2",
+ "id": "7be4250a",
"metadata": {
"lines_to_next_cell": 0
},
@@ -211,7 +211,7 @@
},
{
"cell_type": "markdown",
- "id": "72fbabcd",
+ "id": "5f8c898d",
"metadata": {},
"source": [
"# Part 2: Using Integrated Gradients to find what the classifier knows\n",
@@ -221,7 +221,7 @@
},
{
"cell_type": "markdown",
- "id": "5a41df80",
+ "id": "a284d49b",
"metadata": {},
"source": [
"## Attributions through integrated gradients\n",
@@ -234,7 +234,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "c7615db3",
+ "id": "925ce3e7",
"metadata": {
"tags": []
},
@@ -252,7 +252,7 @@
},
{
"cell_type": "markdown",
- "id": "f8bc4307",
+ "id": "b72a7b5a",
"metadata": {
"tags": []
},
@@ -268,7 +268,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "300ad40e",
+ "id": "9a722cf0",
"metadata": {
"tags": [
"solution"
@@ -292,7 +292,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "8ebbe326",
+ "id": "3a0c2413",
"metadata": {
"tags": []
},
@@ -305,7 +305,7 @@
},
{
"cell_type": "markdown",
- "id": "2de7d44e",
+ "id": "1941efec",
"metadata": {
"lines_to_next_cell": 2,
"tags": []
@@ -317,7 +317,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "c484acb2",
+ "id": "3c89c686",
"metadata": {
"tags": []
},
@@ -345,7 +345,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "898595ea",
+ "id": "e10dc24d",
"metadata": {
"tags": []
},
@@ -358,7 +358,7 @@
},
{
"cell_type": "markdown",
- "id": "5b66372f",
+ "id": "91f7fb24",
"metadata": {
"lines_to_next_cell": 2
},
@@ -372,7 +372,7 @@
},
{
"cell_type": "markdown",
- "id": "f26f6f42",
+ "id": "5e1f90c7",
"metadata": {
"lines_to_next_cell": 0
},
@@ -385,7 +385,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "69cf5669",
+ "id": "598a1f0a",
"metadata": {},
"outputs": [],
"source": [
@@ -410,7 +410,7 @@
},
{
"cell_type": "markdown",
- "id": "9642568b",
+ "id": "d873aa39",
"metadata": {
"lines_to_next_cell": 0
},
@@ -424,7 +424,7 @@
},
{
"cell_type": "markdown",
- "id": "2891c43d",
+ "id": "05d0cef7",
"metadata": {},
"source": [
"\n",
@@ -450,7 +450,7 @@
},
{
"cell_type": "markdown",
- "id": "357966b5",
+ "id": "43b62c80",
"metadata": {},
"source": [
"
Task 2.3: Use random noise as a baseline
\n",
@@ -462,7 +462,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "99c5b515",
+ "id": "1988179e",
"metadata": {
"tags": [
"solution"
@@ -488,7 +488,7 @@
},
{
"cell_type": "markdown",
- "id": "f9b5fba2",
+ "id": "f3c3e97c",
"metadata": {
"tags": []
},
@@ -502,7 +502,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "2ba867e8",
+ "id": "5370fe7e",
"metadata": {
"tags": [
"solution"
@@ -532,7 +532,7 @@
},
{
"cell_type": "markdown",
- "id": "ccedb79c",
+ "id": "7abf9f27",
"metadata": {
"tags": []
},
@@ -548,7 +548,7 @@
},
{
"cell_type": "markdown",
- "id": "68893afb",
+ "id": "c37b4cc9",
"metadata": {},
"source": [
"
BONUS Task: Using different attributions.
\n",
@@ -562,7 +562,7 @@
},
{
"cell_type": "markdown",
- "id": "849fa319",
+ "id": "b08a5590",
"metadata": {},
"source": [
"
Checkpoint 2
\n",
@@ -582,7 +582,7 @@
},
{
"cell_type": "markdown",
- "id": "876bdd3b",
+ "id": "13b502ee",
"metadata": {
"lines_to_next_cell": 0
},
@@ -610,7 +610,7 @@
},
{
"cell_type": "markdown",
- "id": "5a1c2a34",
+ "id": "a39a4234",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -633,7 +633,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "85aa4a15",
+ "id": "ccbd9243",
"metadata": {},
"outputs": [],
"source": [
@@ -665,7 +665,7 @@
},
{
"cell_type": "markdown",
- "id": "2b95f3e8",
+ "id": "3d75236e",
"metadata": {
"lines_to_next_cell": 0
},
@@ -680,7 +680,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "ff8cbb81",
+ "id": "f0b9e1fa",
"metadata": {
"tags": [
"solution"
@@ -697,7 +697,7 @@
},
{
"cell_type": "markdown",
- "id": "9c976d43",
+ "id": "8cc42dea",
"metadata": {
"tags": []
},
@@ -712,7 +712,7 @@
},
{
"cell_type": "markdown",
- "id": "881575de",
+ "id": "afa65120",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -729,7 +729,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "de64cf3c",
+ "id": "00157769",
"metadata": {
"lines_to_next_cell": 0,
"tags": [
@@ -743,7 +743,7 @@
},
{
"cell_type": "markdown",
- "id": "d29d8d58",
+ "id": "5b47154f",
"metadata": {
"lines_to_next_cell": 0
},
@@ -754,7 +754,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "f51b15fc",
+ "id": "fb6eecc1",
"metadata": {},
"outputs": [],
"source": [
@@ -764,7 +764,7 @@
},
{
"cell_type": "markdown",
- "id": "73814dae",
+ "id": "c79251f6",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -782,7 +782,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "5fc36682",
+ "id": "810cae99",
"metadata": {
"lines_to_next_cell": 0
},
@@ -794,7 +794,7 @@
},
{
"cell_type": "markdown",
- "id": "e07edb85",
+ "id": "19e0a570",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -813,7 +813,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "5082b8ab",
+ "id": "8eb2fe39",
"metadata": {},
"outputs": [],
"source": [
@@ -822,7 +822,7 @@
},
{
"cell_type": "markdown",
- "id": "43ef8a2d",
+ "id": "7ffb373b",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -838,7 +838,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "468fe88f",
+ "id": "1a5c8832",
"metadata": {},
"outputs": [],
"source": [
@@ -847,7 +847,7 @@
},
{
"cell_type": "markdown",
- "id": "6dd0f856",
+ "id": "2b585f2b",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -859,7 +859,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "89da32d6",
+ "id": "e957ad43",
"metadata": {},
"outputs": [],
"source": [
@@ -872,7 +872,7 @@
},
{
"cell_type": "markdown",
- "id": "2b894eac",
+ "id": "204a9236",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -886,7 +886,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "b25e284e",
+ "id": "b87e8d1e",
"metadata": {},
"outputs": [],
"source": [
@@ -898,7 +898,7 @@
},
{
"cell_type": "markdown",
- "id": "72125f93",
+ "id": "618bebe4",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -918,7 +918,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "41cf9baf",
+ "id": "258d6086",
"metadata": {},
"outputs": [],
"source": [
@@ -942,7 +942,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "a5b1fb2e",
+ "id": "724e40db",
"metadata": {
"lines_to_next_cell": 2
},
@@ -954,7 +954,7 @@
},
{
"cell_type": "markdown",
- "id": "421a4724",
+ "id": "4ad4b22d",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -976,7 +976,7 @@
},
{
"cell_type": "markdown",
- "id": "d375c071",
+ "id": "271bc482",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -988,7 +988,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "c79ac460",
+ "id": "18724935",
"metadata": {
"lines_to_next_cell": 2,
"tags": [
@@ -1058,7 +1058,7 @@
},
{
"cell_type": "markdown",
- "id": "bf2700e1",
+ "id": "e323e6f7",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -1070,7 +1070,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "93af3047",
+ "id": "fd20bc6e",
"metadata": {},
"outputs": [],
"source": [
@@ -1086,7 +1086,7 @@
},
{
"cell_type": "markdown",
- "id": "65452041",
+ "id": "240c3164",
"metadata": {
"tags": []
},
@@ -1101,7 +1101,7 @@
},
{
"cell_type": "markdown",
- "id": "db668256",
+ "id": "deb3d3a0",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -1113,7 +1113,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "f76c5e65",
+ "id": "d3f7104a",
"metadata": {},
"outputs": [],
"source": [
@@ -1135,7 +1135,7 @@
},
{
"cell_type": "markdown",
- "id": "573bb9d9",
+ "id": "6c7e4472",
"metadata": {
"tags": []
},
@@ -1151,7 +1151,7 @@
},
{
"cell_type": "markdown",
- "id": "26dfd88b",
+ "id": "b3c5bbd0",
"metadata": {
"tags": []
},
@@ -1161,7 +1161,7 @@
},
{
"cell_type": "markdown",
- "id": "f48126ab",
+ "id": "7c8c76fe",
"metadata": {
"tags": []
},
@@ -1178,7 +1178,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "4305090b",
+ "id": "3d4f212c",
"metadata": {
"title": "Loading the test dataset"
},
@@ -1198,7 +1198,7 @@
},
{
"cell_type": "markdown",
- "id": "154db796",
+ "id": "0394fb82",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -1210,7 +1210,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "ebbcd12d",
+ "id": "f7e02a34",
"metadata": {},
"outputs": [],
"source": [
@@ -1223,7 +1223,7 @@
},
{
"cell_type": "markdown",
- "id": "61d5d4bc",
+ "id": "bc9acb76",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1233,7 +1233,7 @@
},
{
"cell_type": "markdown",
- "id": "7ae07350",
+ "id": "54fb79ed",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1251,7 +1251,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "ede3165e",
+ "id": "25cc00c8",
"metadata": {
"tags": [
"solution"
@@ -1288,7 +1288,7 @@
},
{
"cell_type": "markdown",
- "id": "bebb99c9",
+ "id": "255934ec",
"metadata": {
"lines_to_next_cell": 0,
"tags": []
@@ -1300,7 +1300,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "c87df0c0",
+ "id": "6daca8ca",
"metadata": {},
"outputs": [],
"source": [
@@ -1313,7 +1313,7 @@
},
{
"cell_type": "markdown",
- "id": "2fbc38e9",
+ "id": "18186b93",
"metadata": {
"tags": []
},
@@ -1328,7 +1328,7 @@
},
{
"cell_type": "markdown",
- "id": "baf8c83a",
+ "id": "29b63b00",
"metadata": {
"tags": []
},
@@ -1339,7 +1339,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "2465c04b",
+ "id": "411b8730",
"metadata": {},
"outputs": [],
"source": [
@@ -1353,7 +1353,7 @@
},
{
"cell_type": "markdown",
- "id": "35613805",
+ "id": "dcce6a0c",
"metadata": {
"tags": []
},
@@ -1368,7 +1368,7 @@
},
{
"cell_type": "markdown",
- "id": "321fcad6",
+ "id": "106316e5",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1383,7 +1383,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "1c45c814",
+ "id": "152bed37",
"metadata": {},
"outputs": [],
"source": [
@@ -1404,7 +1404,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "584f13f4",
+ "id": "3d722e25",
"metadata": {
"title": "Another visualization function"
},
@@ -1433,7 +1433,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "df33dd4a",
+ "id": "04eabebc",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1441,7 +1441,7 @@
"source": [
"for idx in range(batch_size):\n",
" print(\"Source class:\", y[idx].item())\n",
- " print(\"Target class:\", 0)\n",
+ " print(\"Target class:\", target_class)\n",
" visualize_color_attribution_and_counterfactual(\n",
" attributions[idx].cpu().numpy(), x[idx].cpu().numpy(), x_fake[idx].cpu().numpy()\n",
" )"
@@ -1449,7 +1449,7 @@
},
{
"cell_type": "markdown",
- "id": "f2bdfa5d",
+ "id": "46e50c88",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1465,11 +1465,21 @@
},
{
"cell_type": "markdown",
- "id": "da87745e",
+ "id": "a9b101b6",
"metadata": {
"lines_to_next_cell": 0
},
"source": [
+ "By now you will have hopefully noticed that it isn't the exact color of the image that determines its class, but that two images with a very similar color can be of different classes!\n",
+ "\n",
+ "Here are two examples of image-counterfactual-attribution triplets.\n",
+ "You'll notice that they are *very* similar in every way! But one set is different classes, and one set is the same class!\n",
+ "\n",
+ "![same_class](assets/same_class.png)\n",
+ "![diff_class](assets/diff_class.png)\n",
+ "\n",
+ "We are missing a crucial step of the explanation pipeline: a quantification of how the class changes over the interpolation. \n",
+ "\n",
"In the lecture, we used the attribution to act as a mask, to gradually go from the original image to the counterfactual image.\n",
"This allowed us to classify all of the intermediate images, and learn how the class changed over the interpolation.\n",
"Here we have a much simpler task so we have some advantages:\n",
@@ -1480,7 +1490,7 @@
},
{
"cell_type": "markdown",
- "id": "88f10203",
+ "id": "246fda63",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1494,7 +1504,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "2e79affe",
+ "id": "2e9602ae",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1514,7 +1524,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "70f9846e",
+ "id": "a6039426",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1550,7 +1560,7 @@
},
{
"cell_type": "markdown",
- "id": "386a9f4c",
+ "id": "62c10f55",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1564,7 +1574,7 @@
},
{
"cell_type": "markdown",
- "id": "ae25a656",
+ "id": "f35c78d1",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1580,46 +1590,37 @@
},
{
"cell_type": "markdown",
- "id": "53c7b041",
+ "id": "ce0defa7",
"metadata": {
"lines_to_next_cell": 0
},
"source": [
"
Checkpoint 4
\n",
"At this point you have:\n",
- "- Created a StarGAN that can change the class of an image\n",
- "- Evaluated the StarGAN on unseen data\n",
- "- Used the StarGAN to create counterfactual images\n",
- "- Used the counterfactual images to highlight the differences between classes\n",
- "- Interpolated between the images to see how the classifier behaves\n"
+ "
\n",
+ "- Created a StarGAN that can change the class of an image
\n",
+ "- Evaluated the StarGAN on unseen data
\n",
+ "- Used the StarGAN to create counterfactual images
\n",
+ "- Used the counterfactual images to highlight the differences between classes
\n",
+ "- Interpolated between the images to see how the classifier behaves
\n",
+ "
"
]
},
{
"cell_type": "markdown",
- "id": "c75ed748",
+ "id": "bbd7820d",
"metadata": {
"lines_to_next_cell": 0
},
"source": [
"# Part 5: Exploring the Style Space, finding the answer\n",
- "By now you will have hopefully noticed that it isn't the exact color of the image that determines its class, but that two images with a very similar color can be of different classes!\n",
- "\n",
- "Here is an example of two images that are very similar in color, but are of different classes.\n",
- "![same_color_diff_class](assets/same_color_diff_class.png)\n",
- "While both of the images are yellow, the attribution tells us (if you squint!) that one of the yellows has slightly more blue in it!\n",
- "\n",
- "Conversely, here is an example of two images with very different colors, but that are of the same class:\n",
- "![same_class_diff_color](assets/same_class_diff_color.png)\n",
- "Here the attribution is empty! Using the discriminative attribution we can see that the significant color change doesn't matter at all!\n",
- "\n",
- "\n",
"So color is important... but not always? What's going on!?\n",
"There is a final piece of information that we can use to solve the puzzle: the style space."
]
},
{
"cell_type": "markdown",
- "id": "45dcb17b",
+ "id": "141b4181",
"metadata": {},
"source": [
"
Task 5.1: Explore the style space
\n",
@@ -1631,7 +1632,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "11309f0a",
+ "id": "b6e9c103",
"metadata": {},
"outputs": [],
"source": [
@@ -1666,7 +1667,7 @@
},
{
"cell_type": "markdown",
- "id": "e7e0f8d4",
+ "id": "c01c00f7",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1682,7 +1683,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "cc183548",
+ "id": "11b7d4c9",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1709,7 +1710,7 @@
},
{
"cell_type": "markdown",
- "id": "9f34f021",
+ "id": "2c53c235",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1723,7 +1724,7 @@
},
{
"cell_type": "markdown",
- "id": "5d29071b",
+ "id": "9d81df42",
"metadata": {
"lines_to_next_cell": 0
},
@@ -1740,7 +1741,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "366dd45c",
+ "id": "081a67e4",
"metadata": {},
"outputs": [],
"source": [
@@ -1762,7 +1763,7 @@
},
{
"cell_type": "markdown",
- "id": "b657a0f5",
+ "id": "1d74498c",
"metadata": {},
"source": [
"
Questions
\n",
@@ -1774,17 +1775,19 @@
},
{
"cell_type": "markdown",
- "id": "35b0a886",
+ "id": "1efd608c",
"metadata": {},
"source": [
"
Checkpoint 5
\n",
"Congratulations! You have made it to the end of the exercise!\n",
"You have:\n",
- "- Created a StarGAN that can change the class of an image\n",
- "- Evaluated the StarGAN on unseen data\n",
- "- Used the StarGAN to create counterfactual images\n",
- "- Used the counterfactual images to highlight the differences between classes\n",
- "- Used the style space to understand the differences between classes\n",
+ "
\n",
+ "- Created a StarGAN that can change the class of an image
\n",
+ "- Evaluated the StarGAN on unseen data
\n",
+ "- Used the StarGAN to create counterfactual images
\n",
+ "- Used the counterfactual images to highlight the differences between classes
\n",
+ "- Used the style space to understand the differences between classes
\n",
+ "
\n",
"\n",
"If you have any questions, feel free to ask them in the chat!\n",
"And check the Solutions exercise for a definite answer to how these classes are defined!"
@@ -1792,7 +1795,7 @@
},
{
"cell_type": "markdown",
- "id": "c7f12c18",
+ "id": "4f71144a",
"metadata": {},
"source": [
"# Bonus!\n",
@@ -1807,7 +1810,7 @@
},
{
"cell_type": "markdown",
- "id": "93aa15d5",
+ "id": "9a7ef223",
"metadata": {
"tags": [
"solution"
@@ -1821,7 +1824,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "ac995812",
+ "id": "ce759160",
"metadata": {
"tags": [
"solution"
diff --git a/solution.py b/solution.py
index c70861b..1111482 100644
--- a/solution.py
+++ b/solution.py
@@ -967,7 +967,7 @@ def visualize_color_attribution_and_counterfactual(
# %%
for idx in range(batch_size):
print("Source class:", y[idx].item())
- print("Target class:", 0)
+ print("Target class:", target_class)
visualize_color_attribution_and_counterfactual(
attributions[idx].cpu().numpy(), x[idx].cpu().numpy(), x_fake[idx].cpu().numpy()
)
@@ -980,6 +980,16 @@ def visualize_color_attribution_and_counterfactual(
#
#
# %% [markdown]
+# By now you will have hopefully noticed that it isn't the exact color of the image that determines its class, but that two images with a very similar color can be of different classes!
+#
+# Here are two examples of image-counterfactual-attribution triplets.
+# You'll notice that they are *very* similar in every way! But one set is different classes, and one set is the same class!
+#
+# ![same_class](assets/same_class.png)
+# ![diff_class](assets/diff_class.png)
+#
+# We are missing a crucial step of the explanation pipeline: a quantification of how the class changes over the interpolation.
+#
# In the lecture, we used the attribution to act as a mask, to gradually go from the original image to the counterfactual image.
# This allowed us to classify all of the intermediate images, and learn how the class changed over the interpolation.
# Here we have a much simpler task so we have some advantages:
@@ -1045,25 +1055,15 @@ def visualize_color_attribution_and_counterfactual(
# %% [markdown]
#
Checkpoint 4
# At this point you have:
-# - Created a StarGAN that can change the class of an image
-# - Evaluated the StarGAN on unseen data
-# - Used the StarGAN to create counterfactual images
-# - Used the counterfactual images to highlight the differences between classes
-# - Interpolated between the images to see how the classifier behaves
-#
+#
+# - Created a StarGAN that can change the class of an image
+# - Evaluated the StarGAN on unseen data
+# - Used the StarGAN to create counterfactual images
+# - Used the counterfactual images to highlight the differences between classes
+# - Interpolated between the images to see how the classifier behaves
+#
# %% [markdown]
# # Part 5: Exploring the Style Space, finding the answer
-# By now you will have hopefully noticed that it isn't the exact color of the image that determines its class, but that two images with a very similar color can be of different classes!
-#
-# Here is an example of two images that are very similar in color, but are of different classes.
-# ![same_color_diff_class](assets/same_color_diff_class.png)
-# While both of the images are yellow, the attribution tells us (if you squint!) that one of the yellows has slightly more blue in it!
-#
-# Conversely, here is an example of two images with very different colors, but that are of the same class:
-# ![same_class_diff_color](assets/same_class_diff_color.png)
-# Here the attribution is empty! Using the discriminative attribution we can see that the significant color change doesn't matter at all!
-#
-#
# So color is important... but not always? What's going on!?
# There is a final piece of information that we can use to solve the puzzle: the style space.
# %% [markdown]
@@ -1167,11 +1167,13 @@ def visualize_color_attribution_and_counterfactual(
#
Checkpoint 5
# Congratulations! You have made it to the end of the exercise!
# You have:
-# - Created a StarGAN that can change the class of an image
-# - Evaluated the StarGAN on unseen data
-# - Used the StarGAN to create counterfactual images
-# - Used the counterfactual images to highlight the differences between classes
-# - Used the style space to understand the differences between classes
+#
+# - Created a StarGAN that can change the class of an image
+# - Evaluated the StarGAN on unseen data
+# - Used the StarGAN to create counterfactual images
+# - Used the counterfactual images to highlight the differences between classes
+# - Used the style space to understand the differences between classes
+#
#
# If you have any questions, feel free to ask them in the chat!
# And check the Solutions exercise for a definite answer to how these classes are defined!