Skip to content

Commit dfc4df7

Browse files
itan1lorenzoh
andauthored
Keypoint regression example (#221)
Updates the keypoint regression notebook with the following fixes: * remove FastAI.DLPipelines import * fix typos/text * replace BlockTask with SupervisedTask * Fix image sizes to (224, 224) * use FastAI.decodeypred() * import Flux for Flux.ADAM() * Add ImageShow import Co-authored-by: lorenzoh <[email protected]>
1 parent 9b9584d commit dfc4df7

File tree

1 file changed

+13
-29
lines changed

1 file changed

+13
-29
lines changed

notebooks/keypointregression.ipynb

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,12 @@
1818
"cell_type": "code",
1919
"execution_count": 1,
2020
"metadata": {},
21-
"outputs": [
22-
{
23-
"name": "stderr",
24-
"output_type": "stream",
25-
"text": [
26-
"┌ Info: Precompiling FastAI [5d0beca9-ade8-49ae-ad0b-a3cf890e669f]\n",
27-
"└ @ Base loading.jl:1342\n",
28-
"WARNING: using Makie.Label in module FastAI conflicts with an existing identifier.\n"
29-
]
30-
}
31-
],
21+
"outputs": [],
3222
"source": [
3323
"import CairoMakie; CairoMakie.activate!(type=\"png\")\n",
3424
"using DelimitedFiles: readdlm\n",
35-
"using FastAI\n",
36-
"using FastAI.FilePathsBase, FastAI.StaticArrays, FastAI.DLPipelines\n",
25+
"using FastAI, ImageShow\n",
26+
"using FastAI.FilePathsBase, FastAI.StaticArrays\n",
3727
"import FastAI.DataAugmentation"
3828
]
3929
},
@@ -198,7 +188,7 @@
198188
{
199189
"data": {
200190
"text/plain": [
201-
"loadannotfile (generic function with 2 tasks)"
191+
"loadannotfile (generic function with 2 methods)"
202192
]
203193
},
204194
"execution_count": 6,
@@ -302,7 +292,7 @@
302292
"cell_type": "markdown",
303293
"metadata": {},
304294
"source": [
305-
"Before we can start using this data container for training, we need to split into a training and validation dataset. Since there are 13 different persons with many images each, randomly splitting the container does not make sense. The validation dataset would then contain many images that are very similar to those seen in training, and would hence say little about the generalization ability of a model. We instead use the first 12 subjects as a training dataset and validate on the last."
295+
"Before we can start using this data container for training, we need to split it into a training and validation dataset. Since there are 13 different persons with many images each, randomly splitting the container does not make sense. The validation dataset would then contain many images that are very similar to those seen in training, and would hence say little about the generalization ability of a model. We instead use the first 12 subjects as a training dataset and validate on the last."
306296
]
307297
},
308298
{
@@ -349,7 +339,7 @@
349339
{
350340
"data": {
351341
"text/plain": [
352-
"BlockTask(Image{2} -> Keypoints{2, 1})"
342+
"SupervisedTask(Image{2} -> Keypoints{2, 1})"
353343
]
354344
},
355345
"execution_count": 10,
@@ -358,8 +348,8 @@
358348
}
359349
],
360350
"source": [
361-
"sz = (128, 128)\n",
362-
"task = BlockTask(\n",
351+
"sz = (224, 224)\n",
352+
"task = SupervisedTask(\n",
363353
" (Image{2}(), Keypoints{2}(1)),\n",
364354
" (\n",
365355
" ProjectiveTransforms(sz, buffered=true, augmentations=augs_projection(max_warp=0)),\n",
@@ -384,7 +374,7 @@
384374
{
385375
"data": {
386376
"text/plain": [
387-
"(\"128×128×3 Array{Float32, 3}\", Float32[0.33977616, 0.19801295])"
377+
"(\"224×224×3 Array{Float32, 3}\", Float32[-0.11184323, 0.52864575])"
388378
]
389379
},
390380
"execution_count": 11,
@@ -414,7 +404,7 @@
414404
"data": {
415405
"text/plain": [
416406
"1-element Vector{SVector{2, Float32}}:\n",
417-
" [85.745674, 76.67283]"
407+
" [99.47356, 171.20831]"
418408
]
419409
},
420410
"execution_count": 12,
@@ -423,14 +413,7 @@
423413
}
424414
],
425415
"source": [
426-
"DLPipelines.decodeŷ(task, Training(), y)"
427-
]
428-
},
429-
{
430-
"cell_type": "markdown",
431-
"metadata": {},
432-
"source": [
433-
"We should also visualize our data to make sure that after all the encoding it still makes sense and the keypoint is properly aligned with the head on the image. The visualizations are derived from the data blocks we used when defining our `BlockTask`."
416+
"FastAI.decodeypred(task, Training(), y)"
434417
]
435418
},
436419
{
@@ -473,7 +456,7 @@
473456
"cell_type": "markdown",
474457
"metadata": {},
475458
"source": [
476-
"We'll use a modified ResNet as a model backbone. and add a couple layers that regress the keypoint. [`taskmodel`](#) knows how to do this by looking at the data blocks used and calling [`blockmodel`](#)`(KepointTensor{2, Float32}((1,)), KeypointTensor{2, Float32}((1,)), backbone)`."
459+
"We'll use a modified ResNet as a model backbone. and add a couple layers that regress the keypoint. [`taskmodel`](#) knows how to do this by looking at the data blocks used and calling [`blockmodel`](#)`(KeypointTensor{2, Float32}((1,)), KeypointTensor{2, Float32}((1,)), backbone)`."
477460
]
478461
},
479462
{
@@ -552,6 +535,7 @@
552535
}
553536
],
554537
"source": [
538+
"import Flux\n",
555539
"learner = Learner(\n",
556540
" model,\n",
557541
" (traindl, validdl),\n",

0 commit comments

Comments
 (0)