Hannes Kuchelmeister commited on
Commit
ef10223
1 Parent(s): 447c563

add better contour plot using argmin and abs

Browse files
.gitattributes CHANGED
@@ -28,3 +28,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
28
  *.ckpt filter=lfs diff=lfs merge=lfs -text
29
  data/**/*.json filter=lfs diff=lfs merge=lfs -text
30
  data/**/*.csv filter=lfs diff=lfs merge=lfs -text
 
 
28
  *.ckpt filter=lfs diff=lfs merge=lfs -text
29
  data/**/*.json filter=lfs diff=lfs merge=lfs -text
30
  data/**/*.csv filter=lfs diff=lfs merge=lfs -text
31
+ *.ipynb filter=lfs diff=lfs merge=lfs -text
notebooks/1.0-hfk-datamodules-exploration.ipynb CHANGED
@@ -1,204 +1,3 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "metadata": {},
6
- "source": [
7
- "## Exploring Code for Data"
8
- ]
9
- },
10
- {
11
- "cell_type": "code",
12
- "execution_count": null,
13
- "metadata": {},
14
- "outputs": [],
15
- "source": [
16
- "import pandas as pd"
17
- ]
18
- },
19
- {
20
- "cell_type": "code",
21
- "execution_count": null,
22
- "metadata": {},
23
- "outputs": [],
24
- "source": [
25
- "metadata = pd.read_csv(\"../data/focus/metadata.csv\")"
26
- ]
27
- },
28
- {
29
- "cell_type": "code",
30
- "execution_count": null,
31
- "metadata": {},
32
- "outputs": [],
33
- "source": [
34
- "metadata"
35
- ]
36
- },
37
- {
38
- "cell_type": "code",
39
- "execution_count": null,
40
- "metadata": {},
41
- "outputs": [],
42
- "source": [
43
- "idx = 0\n",
44
- "# File Path\n",
45
- "metadata.iloc[idx, 1]"
46
- ]
47
- },
48
- {
49
- "cell_type": "code",
50
- "execution_count": null,
51
- "metadata": {},
52
- "outputs": [],
53
- "source": [
54
- "# Focus Value\n",
55
- "metadata.iloc[idx, 5]"
56
- ]
57
- },
58
- {
59
- "cell_type": "markdown",
60
- "metadata": {},
61
- "source": [
62
- "## Testing FocusDataSet"
63
- ]
64
- },
65
- {
66
- "cell_type": "code",
67
- "execution_count": null,
68
- "metadata": {},
69
- "outputs": [],
70
- "source": [
71
- "from importlib.machinery import SourceFileLoader\n",
72
- "\n",
73
- "focus_datamodule = SourceFileLoader(\"focus_datamodule\", \"../src/datamodules/focus_datamodule.py\").load_module()\n",
74
- "from focus_datamodule import FocusDataSet\n",
75
- "\n",
76
- "ds = FocusDataSet(\"../data/focus/metadata.csv\", \"../data/focus/\")\n",
77
- "\n",
78
- "for d in ds:\n",
79
- " break\n",
80
- "\n",
81
- "d"
82
- ]
83
- },
84
- {
85
- "cell_type": "code",
86
- "execution_count": null,
87
- "metadata": {},
88
- "outputs": [],
89
- "source": [
90
- "from focus_datamodule import FocusDataModule\n",
91
- "\n",
92
- "datamodule = FocusDataModule(data_dir=\"../data/focus\", csv_file=\"../data/focus/metadata.csv\")\n",
93
- "datamodule.setup()"
94
- ]
95
- },
96
- {
97
- "cell_type": "code",
98
- "execution_count": null,
99
- "metadata": {},
100
- "outputs": [],
101
- "source": [
102
- "for data in datamodule.test_dataloader():\n",
103
- " break\n",
104
- "\n",
105
- "len(data[\"focus_value\"])"
106
- ]
107
- },
108
- {
109
- "cell_type": "code",
110
- "execution_count": null,
111
- "metadata": {},
112
- "outputs": [],
113
- "source": [
114
- "import types\n",
115
- "import importlib.machinery\n",
116
- "focus_module = SourceFileLoader('focus_module', '../src/models/focus_module.py').load_module()\n",
117
- "from focus_module import FocusLitModule\n",
118
- "\n",
119
- "model = FocusLitModule()\n",
120
- "\n",
121
- "model.step(data)"
122
- ]
123
- },
124
- {
125
- "cell_type": "markdown",
126
- "metadata": {},
127
- "source": [
128
- "## Benchmark in-memory and from disk"
129
- ]
130
- },
131
- {
132
- "cell_type": "code",
133
- "execution_count": null,
134
- "metadata": {},
135
- "outputs": [],
136
- "source": [
137
- "import time\n",
138
- "\n",
139
- "iterations = 10"
140
- ]
141
- },
142
- {
143
- "cell_type": "code",
144
- "execution_count": null,
145
- "metadata": {},
146
- "outputs": [],
147
- "source": [
148
- "datamodule = FocusDataModule(data_dir=\"../data/focus150\", csv_file=\"../data/focus150/metadata.csv\")\n",
149
- "datamodule.setup()\n",
150
- "\n",
151
- "\n",
152
- "start = time.perf_counter()\n",
153
- "counter = 0\n",
154
- "for i in range(iterations):\n",
155
- " for data in datamodule.train_dataloader():\n",
156
- " counter += 1\n",
157
- "\n",
158
- "print(time.perf_counter() - start)"
159
- ]
160
- },
161
- {
162
- "cell_type": "code",
163
- "execution_count": null,
164
- "metadata": {},
165
- "outputs": [],
166
- "source": [
167
- "datamodule = FocusDataModule(data_dir=\"../data/focus150\", csv_file=\"../data/focus150/metadata.csv\", in_memory=False)\n",
168
- "datamodule.setup()\n",
169
- "\n",
170
- "start = time.perf_counter()\n",
171
- "counter = 0\n",
172
- "for i in range(iterations):\n",
173
- " for data in datamodule.train_dataloader():\n",
174
- " counter += 1\n",
175
- "print(time.perf_counter() - start)"
176
- ]
177
- }
178
- ],
179
- "metadata": {
180
- "interpreter": {
181
- "hash": "f9f85f796d01129d0dd105a088854619f454435301f6ffec2fea96ecbd9be4ac"
182
- },
183
- "kernelspec": {
184
- "display_name": "Python 3.9.7 64-bit",
185
- "language": "python",
186
- "name": "python3"
187
- },
188
- "language_info": {
189
- "codemirror_mode": {
190
- "name": "ipython",
191
- "version": 3
192
- },
193
- "file_extension": ".py",
194
- "mimetype": "text/x-python",
195
- "name": "python",
196
- "nbconvert_exporter": "python",
197
- "pygments_lexer": "ipython3",
198
- "version": "3.8.10"
199
- },
200
- "orig_nbformat": 4
201
- },
202
- "nbformat": 4,
203
- "nbformat_minor": 2
204
- }
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cb54303b39da6232abd0c39c72d4133d38f26cf103c39ec5a2fc4f100e475c9a
3
+ size 4381
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
notebooks/2.0-hfk-convolutional_testing.ipynb CHANGED
@@ -1,203 +1,3 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "metadata": {},
6
- "source": [
7
- "## Testing FocusDataSet"
8
- ]
9
- },
10
- {
11
- "cell_type": "code",
12
- "execution_count": 1,
13
- "metadata": {},
14
- "outputs": [
15
- {
16
- "name": "stdout",
17
- "output_type": "stream",
18
- "text": [
19
- "2450\n"
20
- ]
21
- },
22
- {
23
- "data": {
24
- "text/plain": [
25
- "{'image': array([[[211, 185, 62],\n",
26
- " [216, 192, 68],\n",
27
- " [223, 198, 79],\n",
28
- " ...,\n",
29
- " [214, 190, 64],\n",
30
- " [222, 199, 71],\n",
31
- " [224, 201, 73]],\n",
32
- " \n",
33
- " [[218, 192, 69],\n",
34
- " [223, 197, 74],\n",
35
- " [229, 205, 83],\n",
36
- " ...,\n",
37
- " [216, 193, 65],\n",
38
- " [225, 202, 74],\n",
39
- " [226, 203, 75]],\n",
40
- " \n",
41
- " [[223, 198, 72],\n",
42
- " [228, 202, 79],\n",
43
- " [234, 210, 88],\n",
44
- " ...,\n",
45
- " [220, 197, 69],\n",
46
- " [228, 205, 77],\n",
47
- " [226, 203, 73]],\n",
48
- " \n",
49
- " ...,\n",
50
- " \n",
51
- " [[157, 138, 17],\n",
52
- " [163, 145, 21],\n",
53
- " [178, 157, 32],\n",
54
- " ...,\n",
55
- " [166, 169, 40],\n",
56
- " [170, 173, 42],\n",
57
- " [176, 179, 46]],\n",
58
- " \n",
59
- " [[145, 126, 5],\n",
60
- " [155, 137, 13],\n",
61
- " [177, 156, 31],\n",
62
- " ...,\n",
63
- " [156, 158, 31],\n",
64
- " [166, 169, 40],\n",
65
- " [175, 178, 47]],\n",
66
- " \n",
67
- " [[147, 128, 7],\n",
68
- " [159, 141, 17],\n",
69
- " [181, 160, 35],\n",
70
- " ...,\n",
71
- " [149, 151, 24],\n",
72
- " [162, 164, 37],\n",
73
- " [172, 175, 46]]], dtype=uint8),\n",
74
- " 'focus_value': tensor(0.5450)}"
75
- ]
76
- },
77
- "execution_count": 1,
78
- "metadata": {},
79
- "output_type": "execute_result"
80
- }
81
- ],
82
- "source": [
83
- "from importlib.machinery import SourceFileLoader\n",
84
- "\n",
85
- "focus_datamodule = SourceFileLoader(\"focus_datamodule\", \"../src/datamodules/focus_datamodule.py\").load_module()\n",
86
- "from focus_datamodule import FocusDataSet\n",
87
- "\n",
88
- "ds = FocusDataSet(\"../data/focus150/metadata.csv\", \"../data/focus150/\")\n",
89
- "\n",
90
- "counter = 0\n",
91
- "for d in ds:\n",
92
- " counter += 1\n",
93
- "\n",
94
- "print(counter)\n",
95
- "\n",
96
- "d"
97
- ]
98
- },
99
- {
100
- "cell_type": "code",
101
- "execution_count": 81,
102
- "metadata": {},
103
- "outputs": [
104
- {
105
- "name": "stdout",
106
- "output_type": "stream",
107
- "text": [
108
- "14\n"
109
- ]
110
- },
111
- {
112
- "data": {
113
- "text/plain": [
114
- "torch.Size([64, 1])"
115
- ]
116
- },
117
- "execution_count": 81,
118
- "metadata": {},
119
- "output_type": "execute_result"
120
- }
121
- ],
122
- "source": [
123
- "from focus_datamodule import FocusDataModule\n",
124
- "\n",
125
- "datamodule = FocusDataModule(data_dir=\"../data/focus150\", csv_file=\"../data/focus150/metadata.csv\")\n",
126
- "datamodule.setup()\n",
127
- "\n",
128
- "for data in datamodule.test_dataloader():\n",
129
- " break\n",
130
- "\n",
131
- "len(data[\"focus_value\"])\n",
132
- "\n",
133
- "# https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html\n",
134
- "import torch\n",
135
- "import torch.nn as nn\n",
136
- "import torch.nn.functional as F\n",
137
- "\n",
138
- "class Net(nn.Module):\n",
139
- " def __init__(self):\n",
140
- " super().__init__()\n",
141
- " pool_size = 3\n",
142
- " \n",
143
- " conv1_size = 5\n",
144
- " conv1_out = 6\n",
145
- " conv2_size = 5\n",
146
- " conv2_out = 16\n",
147
- " size_img = 150\n",
148
- "\n",
149
- " size_img -= conv1_size - 1\n",
150
- " size_img = int( (size_img) / pool_size)\n",
151
- " size_img -= conv2_size - 1\n",
152
- " size_img = int(size_img / pool_size)\n",
153
- "\n",
154
- " print(size_img)\n",
155
- "\n",
156
- " self.model = nn.Sequential(\n",
157
- " nn.Conv2d(3, conv1_out, conv1_size),\n",
158
- " nn.MaxPool2d(pool_size, pool_size),\n",
159
- " nn.Conv2d(conv1_out, conv2_out, conv2_size),\n",
160
- " nn.MaxPool2d(pool_size, pool_size),\n",
161
- " nn.Flatten(),\n",
162
- " nn.Linear(conv2_out * size_img * size_img, 120), # 16 * 34 * 34 or [64, 16, 15, 15]\n",
163
- " nn.Linear(120, 84),\n",
164
- " nn.Linear(84, 1)\n",
165
- " )\n",
166
- "\n",
167
- " def forward(self, x):\n",
168
- " x = self.model(x)\n",
169
- " return x\n",
170
- "\n",
171
- "\n",
172
- "net = Net()\n",
173
- "\n",
174
- "net(data[\"image\"]).shape"
175
- ]
176
- }
177
- ],
178
- "metadata": {
179
- "interpreter": {
180
- "hash": "f9f85f796d01129d0dd105a088854619f454435301f6ffec2fea96ecbd9be4ac"
181
- },
182
- "kernelspec": {
183
- "display_name": "Python 3.9.7 64-bit",
184
- "language": "python",
185
- "name": "python3"
186
- },
187
- "language_info": {
188
- "codemirror_mode": {
189
- "name": "ipython",
190
- "version": 3
191
- },
192
- "file_extension": ".py",
193
- "mimetype": "text/x-python",
194
- "name": "python",
195
- "nbconvert_exporter": "python",
196
- "pygments_lexer": "ipython3",
197
- "version": "3.8.10"
198
- },
199
- "orig_nbformat": 4
200
- },
201
- "nbformat": 4,
202
- "nbformat_minor": 2
203
- }
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f546606a42c83af81a425f6d05cb0fafa0522a373be7c6b9a85d166387dc49b4
3
+ size 5434
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
notebooks/3.0-hfk-model-performance-visualisation.ipynb CHANGED
The diff for this file is too large to render. See raw diff