Hannes Kuchelmeister commited on
Commit
9d1e8db
1 Parent(s): 8d4f085

add example images to notebook

Browse files
notebooks/3.0-hfk-model-performance-visualisation.ipynb CHANGED
@@ -807,14 +807,11 @@
807
  "metadata": {},
808
  "outputs": [
809
  {
810
- "data": {
811
- "text/plain": [
812
- "0.022158753"
813
- ]
814
- },
815
- "execution_count": 5,
816
- "metadata": {},
817
- "output_type": "execute_result"
818
  },
819
  {
820
  "data": {
@@ -832,11 +829,16 @@
832
  "source": [
833
  "import numpy as np\n",
834
  "import matplotlib.pyplot as plt\n",
 
835
  "\n",
836
  "plt.scatter(ys, preds, s=1)\n",
837
  "plt.plot([-0.03, 0.03],[-0.03,0.03])\n",
838
  "\n",
839
- "np.mean(np.abs(np.array(ys) - np.array(preds)))"
 
 
 
 
840
  ]
841
  },
842
  {
@@ -887,7 +889,7 @@
887
  "output_type": "stream",
888
  "text": [
889
  "Type: trichuris\n",
890
- "MAE: 0.020948385819792747\n"
891
  ]
892
  },
893
  {
@@ -919,7 +921,7 @@
919
  "output_type": "stream",
920
  "text": [
921
  "Type: ascaris\n",
922
- "MAE: 0.022454742342233658\n"
923
  ]
924
  },
925
  {
@@ -951,7 +953,7 @@
951
  "output_type": "stream",
952
  "text": [
953
  "Type: schistosoma\n",
954
- "MAE: 0.02243957854807377\n"
955
  ]
956
  },
957
  {
@@ -983,7 +985,7 @@
983
  "output_type": "stream",
984
  "text": [
985
  "Type: hookworm\n",
986
- "MAE: 0.02211937867105007\n"
987
  ]
988
  },
989
  {
@@ -1027,7 +1029,12 @@
1027
  " ys.append(y.numpy())\n",
1028
  " \n",
1029
  " print(f\"Type: {type}\")\n",
1030
- " print(f\"MAE: {np.mean(np.abs(np.array(ys) - np.array(preds)))}\")\n",
 
 
 
 
 
1031
  " plt.scatter(ys, preds, s=1)\n",
1032
  " plt.plot([-0.03, 0.03],[-0.03,0.03])\n",
1033
  "\n",
@@ -1054,19 +1061,21 @@
1054
  },
1055
  {
1056
  "cell_type": "code",
1057
- "execution_count": 8,
1058
  "metadata": {},
1059
  "outputs": [
1060
  {
1061
- "ename": "FileNotFoundError",
1062
- "evalue": "[Errno 2] No such file or directory: 'img/0.0000_I03528_X007_Y019_Z5498.jpg'",
1063
- "output_type": "error",
1064
- "traceback": [
1065
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
1066
- "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
1067
- "\u001b[1;32m/home/hku/master_thesis_models/notebooks/3.0-hfk-model-performance-visualisation.ipynb Cell 10'\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell://ssh-remote%2B192.168.240.119/home/hku/master_thesis_models/notebooks/3.0-hfk-model-performance-visualisation.ipynb#ch0000009vscode-remote?line=4'>5</a>\u001b[0m tile_size \u001b[39m=\u001b[39m \u001b[39m150\u001b[39m\n\u001b[1;32m <a href='vscode-notebook-cell://ssh-remote%2B192.168.240.119/home/hku/master_thesis_models/notebooks/3.0-hfk-model-performance-visualisation.ipynb#ch0000009vscode-remote?line=6'>7</a>\u001b[0m \u001b[39m#img = Image.open(\"img/0.0137_I03524_X007_Y019_Z5634.jpg\") \u001b[39;00m\n\u001b[0;32m----> <a href='vscode-notebook-cell://ssh-remote%2B192.168.240.119/home/hku/master_thesis_models/notebooks/3.0-hfk-model-performance-visualisation.ipynb#ch0000009vscode-remote?line=7'>8</a>\u001b[0m img \u001b[39m=\u001b[39m Image\u001b[39m.\u001b[39;49mopen(\u001b[39m\"\u001b[39;49m\u001b[39mimg/0.0000_I03528_X007_Y019_Z5498.jpg\u001b[39;49m\u001b[39m\"\u001b[39;49m) \n\u001b[1;32m <a href='vscode-notebook-cell://ssh-remote%2B192.168.240.119/home/hku/master_thesis_models/notebooks/3.0-hfk-model-performance-visualisation.ipynb#ch0000009vscode-remote?line=8'>9</a>\u001b[0m img_grey \u001b[39m=\u001b[39m ImageOps\u001b[39m.\u001b[39mgrayscale(img)\n\u001b[1;32m <a href='vscode-notebook-cell://ssh-remote%2B192.168.240.119/home/hku/master_thesis_models/notebooks/3.0-hfk-model-performance-visualisation.ipynb#ch0000009vscode-remote?line=10'>11</a>\u001b[0m img_crop \u001b[39m=\u001b[39m img\u001b[39m.\u001b[39mcrop([\u001b[39m0\u001b[39m, \u001b[39m0\u001b[39m, tile_size\u001b[39m*\u001b[39m\u001b[39mint\u001b[39m(img\u001b[39m.\u001b[39mwidth\u001b[39m/\u001b[39mtile_size), tile_size\u001b[39m*\u001b[39m\u001b[39mint\u001b[39m(img\u001b[39m.\u001b[39mheight\u001b[39m/\u001b[39mtile_size)])\n",
1068
- "File \u001b[0;32m~/.local/lib/python3.8/site-packages/PIL/Image.py:2953\u001b[0m, in \u001b[0;36mopen\u001b[0;34m(fp, mode, formats)\u001b[0m\n\u001b[1;32m <a href='file:///home/hku/.local/lib/python3.8/site-packages/PIL/Image.py?line=2949'>2950</a>\u001b[0m filename \u001b[39m=\u001b[39m fp\n\u001b[1;32m <a href='file:///home/hku/.local/lib/python3.8/site-packages/PIL/Image.py?line=2951'>2952</a>\u001b[0m \u001b[39mif\u001b[39;00m filename:\n\u001b[0;32m-> <a href='file:///home/hku/.local/lib/python3.8/site-packages/PIL/Image.py?line=2952'>2953</a>\u001b[0m fp \u001b[39m=\u001b[39m builtins\u001b[39m.\u001b[39;49mopen(filename, \u001b[39m\"\u001b[39;49m\u001b[39mrb\u001b[39;49m\u001b[39m\"\u001b[39;49m)\n\u001b[1;32m <a href='file:///home/hku/.local/lib/python3.8/site-packages/PIL/Image.py?line=2953'>2954</a>\u001b[0m exclusive_fp \u001b[39m=\u001b[39m \u001b[39mTrue\u001b[39;00m\n\u001b[1;32m <a href='file:///home/hku/.local/lib/python3.8/site-packages/PIL/Image.py?line=2955'>2956</a>\u001b[0m \u001b[39mtry\u001b[39;00m:\n",
1069
- "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'img/0.0000_I03528_X007_Y019_Z5498.jpg'"
 
 
1070
  ]
1071
  }
1072
  ],
@@ -1077,8 +1086,22 @@
1077
  "\n",
1078
  "tile_size = 150\n",
1079
  "\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1080
  "#img = Image.open(\"img/0.0137_I03524_X007_Y019_Z5634.jpg\") \n",
1081
- "img = Image.open(\"img/0.0000_I03528_X007_Y019_Z5498.jpg\") \n",
1082
  "img_grey = ImageOps.grayscale(img)\n",
1083
  "\n",
1084
  "img_crop = img.crop([0, 0, tile_size*int(img.width/tile_size), tile_size*int(img.height/tile_size)])\n",
 
807
  "metadata": {},
808
  "outputs": [
809
  {
810
+ "name": "stdout",
811
+ "output_type": "stream",
812
+ "text": [
813
+ "MAE: 0.0060480572283267975\n"
814
+ ]
 
 
 
815
  },
816
  {
817
  "data": {
 
829
  "source": [
830
  "import numpy as np\n",
831
  "import matplotlib.pyplot as plt\n",
832
+ "from torchmetrics import MeanAbsoluteError\n",
833
  "\n",
834
  "plt.scatter(ys, preds, s=1)\n",
835
  "plt.plot([-0.03, 0.03],[-0.03,0.03])\n",
836
  "\n",
837
+ "ys_arr = torch.tensor(np.array(ys).flatten())\n",
838
+ "preds_arr = torch.tensor(np.array(preds).flatten())\n",
839
+ "\n",
840
+ "mean_absolute_error = MeanAbsoluteError()\n",
841
+ "print(f\"MAE: {mean_absolute_error(preds_arr, ys_arr)}\")\n"
842
  ]
843
  },
844
  {
 
889
  "output_type": "stream",
890
  "text": [
891
  "Type: trichuris\n",
892
+ "MAE: 0.006043851841241121\n"
893
  ]
894
  },
895
  {
 
921
  "output_type": "stream",
922
  "text": [
923
  "Type: ascaris\n",
924
+ "MAE: 0.006212816573679447\n"
925
  ]
926
  },
927
  {
 
953
  "output_type": "stream",
954
  "text": [
955
  "Type: schistosoma\n",
956
+ "MAE: 0.006195892579853535\n"
957
  ]
958
  },
959
  {
 
985
  "output_type": "stream",
986
  "text": [
987
  "Type: hookworm\n",
988
+ "MAE: 0.005734680686146021\n"
989
  ]
990
  },
991
  {
 
1029
  " ys.append(y.numpy())\n",
1030
  " \n",
1031
  " print(f\"Type: {type}\")\n",
1032
+ "\n",
1033
+ " ys_arr = torch.tensor(np.array(ys).flatten())\n",
1034
+ " preds_arr = torch.tensor(np.array(preds).flatten())\n",
1035
+ "\n",
1036
+ " mean_absolute_error = MeanAbsoluteError()\n",
1037
+ " print(f\"MAE: {mean_absolute_error(preds_arr, ys_arr)}\")\n",
1038
  " plt.scatter(ys, preds, s=1)\n",
1039
  " plt.plot([-0.03, 0.03],[-0.03,0.03])\n",
1040
  "\n",
 
1061
  },
1062
  {
1063
  "cell_type": "code",
1064
+ "execution_count": 9,
1065
  "metadata": {},
1066
  "outputs": [
1067
  {
1068
+ "name": "stderr",
1069
+ "output_type": "stream",
1070
+ "text": [
1071
+ "Error: no \"view\" mailcap rules found for type \"image/png\"\n",
1072
+ "Error: no \"view\" mailcap rules found for type \"image/png\"\n",
1073
+ "Error when invoking the open external command: Error in response: Unable to parse response as JSON: \n",
1074
+ "Error when invoking the open external command: Error in response: Unable to parse response as JSON: \n",
1075
+ "Error: no \"view\" mailcap rules found for type \"image/png\"\n",
1076
+ "Error when invoking the open external command: Error in response: Unable to parse response as JSON: \n",
1077
+ "Error: no \"view\" mailcap rules found for type \"image/png\"\n",
1078
+ "Error when invoking the open external command: Error in response: Unable to parse response as JSON: \n"
1079
  ]
1080
  }
1081
  ],
 
1086
  "\n",
1087
  "tile_size = 150\n",
1088
  "\n",
1089
+ "root_file_folder = \"img/\"\n",
1090
+ "files = [\n",
1091
+ " \"-0.021_I04131_X020_Y022_Z5078.jpg\",\n",
1092
+ " \"-0.014_I04133_X020_Y022_Z5146.jpg\",\n",
1093
+ " \"-0.006_I04135_X020_Y022_Z5214.jpg\",\n",
1094
+ " \"+0.000_I04136_X020_Y022_Z5283.jpg\",\n",
1095
+ " \"+0.007_I04138_X020_Y022_Z5351.jpg\",\n",
1096
+ " \"+0.014_I04139_X020_Y022_Z5419.jpg\",\n",
1097
+ " \"+0.021_I04140_X020_Y022_Z5488.jpg\",\n",
1098
+ " \"+0.027_I04137_X020_Y022_Z5556.jpg\",\n",
1099
+ " \"+0.034_I04134_X020_Y022_Z5625.jpg\",\n",
1100
+ " \"+0.041_I04132_X020_Y022_Z5693.jpg\",\n",
1101
+ "]\n",
1102
+ "\n",
1103
  "#img = Image.open(\"img/0.0137_I03524_X007_Y019_Z5634.jpg\") \n",
1104
+ "img = Image.open(os.path.join(root_file_folder, files[0])) \n",
1105
  "img_grey = ImageOps.grayscale(img)\n",
1106
  "\n",
1107
  "img_crop = img.crop([0, 0, tile_size*int(img.width/tile_size), tile_size*int(img.height/tile_size)])\n",
notebooks/img/+0.000_I04136_X020_Y022_Z5283.jpg ADDED
notebooks/img/+0.007_I04138_X020_Y022_Z5351.jpg ADDED
notebooks/img/+0.014_I04139_X020_Y022_Z5419.jpg ADDED
notebooks/img/+0.021_I04140_X020_Y022_Z5488.jpg ADDED
notebooks/img/+0.027_I04137_X020_Y022_Z5556.jpg ADDED
notebooks/img/+0.034_I04134_X020_Y022_Z5625.jpg ADDED
notebooks/img/+0.041_I04132_X020_Y022_Z5693.jpg ADDED
notebooks/img/-0.006_I04135_X020_Y022_Z5214.jpg ADDED
notebooks/img/-0.014_I04133_X020_Y022_Z5146.jpg ADDED
notebooks/img/-0.021_I04131_X020_Y022_Z5078.jpg ADDED