Skip to content

Commit 485ef9f

Browse files
authored
Get ready for release of 0.1.0 (#145)
* Correct `encode` method for `NamedTuple` * Implement `blocklossfn(block)` fallback method * minor cleanup of plot code * implement `Block` interface for `WrapperBlock` * remove `collectobs` stub * make `ProjectiveTransforms` work with `WrapperBlock`s * fix `wd` option in `fitonecycle!` * remove outdated docstring * update doc serve sript * fix `plotprediction!` for segmentation * amend * add Colab instructions to "Setup" page * Update `fitonecycle` notebook
1 parent 186c3dd commit 485ef9f

File tree

12 files changed

+259
-66
lines changed

12 files changed

+259
-66
lines changed

docs/serve.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import DataAugmentation
77
using FilePathsBase
88
using Colors
99

10-
function serve(lazy=true)
10+
function serve(lazy=true; kwargs...)
1111
refmodules = [FastAI, FluxTraining, DLPipelines, DataAugmentation, DataLoaders, FastAI.Datasets]
12-
project = Pollen.documentationproject(FastAI; refmodules, watchpackage=true)
12+
project = Pollen.documentationproject(FastAI; refmodules, watchpackage=true, kwargs...)
1313
Pollen.serve(project, lazy=lazy)
1414
end
1515
serve()

docs/setup.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Setup
22

3-
FastAI.jl is a **Julia** package. You can download Julia from the [official website](http://localhost:8000/docs/setup.md.html).
4-
5-
**FastAI.jl** is not registered yet, but you can try it out by installing it manually. You should be able to install FastAI.jl using the REPL as follows (The package mode in the REPL can be entered by typing `]`).
3+
FastAI.jl is a **Julia** package. You can download Julia from the [official website](http://localhost:8000/docs/setup.md.html). You can install FastAI.jl like any other Julia package using the REPL as follows (The package mode in the REPL can be entered by typing `]`).
64

75
```julia
86
pkg> add https://github.com/FluxML/FastAI.jl
@@ -14,6 +12,8 @@ pkg> add https://github.com/FluxML/FastAI.jl
1412
pkg> add CairoMakie
1513
```
1614

15+
**Colab** If you don't have access to a GPU or want to try out FastAI.jl without installing Julia, try out [this FastAI.jl Colab notebook](https://colab.research.google.com/gist/lorenzoh/2fdc91f9e42a15e633861c640c68e5e8). We're working on adding a "Launch Colab" button to every documentation page based off a notebook file, but for now you can copy the code over manually.
16+
1717
**Pretrained models** To use pretrained vision models, you currently have to install a WIP branch of Metalhead.jl:
1818

1919
```julia

notebooks/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ FastAI = "5d0beca9-ade8-49ae-ad0b-a3cf890e669f"
88
FilePathsBase = "48062228-2e41-5def-b9a4-89aafe57970f"
99
FluxTraining = "7bf95e4d-ca32-48da-9824-f0dc5310474f"
1010
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
11+
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
1112
Metalhead = "dbeba491-748d-5e0e-a39e-b530a07fa0cc"
1213
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1314
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

notebooks/fitonecycle.ipynb

Lines changed: 224 additions & 28 deletions
Large diffs are not rendered by default.

src/datablock/encoding.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ function encode(encoding::Encoding, context, blocks::Tuple, datas::Tuple)
8181
end
8282

8383
# Named tuples of data are handled like tuples, but the keys are preserved
84-
function encode(encoding::Encoding, context, blocks::Union{Tuple, NamedTuple}, datas::NamedTuple)
84+
function encode(encoding::Encoding, context, blocks::NamedTuple, datas::NamedTuple)
8585
@assert length(blocks) == length(datas)
8686
return NamedTuple(zip(
8787
keys(datas),
88-
encode(encoding, context, blocks, values(datas))
88+
encode(encoding, context, values(blocks), values(datas))
8989
))
9090
end
9191

@@ -114,11 +114,11 @@ function decode(encoding::Encoding, context, blocks::Tuple, datas::Tuple)
114114
end
115115

116116
# Named tuples of data are handled like tuples, but the keys are preserved
117-
function decode(encoding::Encoding, context, blocks::Union{Tuple, NamedTuple}, datas::NamedTuple)
117+
function decode(encoding::Encoding, context, blocks::NamedTuple, datas::NamedTuple)
118118
@assert length(blocks) == length(datas)
119119
return NamedTuple(zip(
120120
keys(datas),
121-
decode(encoding, context, blocks, values(datas))
121+
decode(encoding, context, values(blocks), values(datas))
122122
))
123123
end
124124

src/datablock/loss.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ For example for `block = OneHotTensor{1}(classes)` (i.e. an encoded
1111
function blocklossfn end
1212

1313

14-
blocklossfn(predblock) = blocklossfn(predblock, targetblock)
14+
blocklossfn(predblock) = blocklossfn(predblock, predblock)
1515

1616
function blocklossfn(outblock::OneHotTensor{0}, yblock::OneHotTensor{0})
1717
outblock.classes == yblock.classes || error("Classes of $outblock and $yblock differ!")

src/datablock/plot.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,15 @@ function plotsample!(f, ctxs::Tuple{NDContext{2}, NDOverlayContext{2}}, blocks,
6868
plotblock!(ax, blocks[1], datas[1], alpha = 0.6) # plots an N-D image
6969
end
7070

71-
function plotsample!(f, ctxs::Tuple{NDContext{2}, NDContext{2}}, blocks, datas)
72-
f[1, 1] = ax1 = imageaxis(f)
73-
plotblock!(ax1, blocks[1], datas[1]) # plots an image
74-
f[1, 2] = ax2 = imageaxis(f)
75-
plotblock!(ax, blocks[2], datas[2]) # plots an image
71+
function plotsample!(
72+
f,
73+
ctxs::NTuple{N, NDContext{2}},
74+
blocks::NTuple{N},
75+
datas::NTuple{N}) where N
76+
for i in 1:N
77+
f[1, i] = ax = imageaxis(f)
78+
plotblock!(ax, blocks[i], datas[i]) # plots an image
79+
end
7680
end
7781

7882
function plotsample!(
@@ -102,13 +106,14 @@ function plotprediction!(f, method::BlockMethod, x, ŷ, y)
102106
ŷblock = method.outputblock
103107
blocks = (xblock, ŷblock, yblock)
104108
input, target_pred, target = decode(method.encodings, Validation(), blocks, (x, ŷ, y))
105-
inblocks = decodedblock(method.encodings, blocks)
109+
inblocks = decodedblock(method.encodings, blocks, true)
106110
contexts = plotcontext(inblocks)
107111
plotprediction!(f, contexts, inblocks, (input, target_pred, target))
108112
end
109113

110114
function plotprediction!(
111-
f, ::Tuple{NDContext{2}, TextContext, TextContext},
115+
f,
116+
::Tuple{NDContext{2}, TextContext, TextContext},
112117
blocks,
113118
datas)
114119

src/datablock/wrappers.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
abstract type WrapperBlock <: Block end
22

3+
wrapped(w::WrapperBlock) = w.block
4+
mockblock(w::WrapperBlock) = mockblock(wrapped(w))
5+
checkblock(w::WrapperBlock, data) = checkblock(wrapped(w), data)
36

47
# If not overwritten, encodings are applied to the wrapped block
58
function encode(enc::Encoding, ctx, wrapper::WrapperBlock, data; kwargs...)
@@ -21,17 +24,15 @@ struct Named{Name, B<:Block} <: WrapperBlock
2124
end
2225
Named(name::Symbol, block::B) where {B<:Block} = Named{name, B}(block)
2326

24-
mockblock(named::Named) = mockblock(named.block)
25-
checkblock(named::Named, data) = checkblock(named.block, data)
2627

2728
# the name is preserved through encodings and decodings
2829
function encodedblock(enc::Encoding, named::Named{Name}) where Name
29-
outblock = encodedblock(enc, named.block)
30+
outblock = encodedblock(enc, wrapped(named))
3031
return isnothing(outblock) ? nothing : Named(Name, outblock)
3132
end
3233

3334
function decodedblock(enc::Encoding, named::Named{Name}) where Name
34-
outblock = decodedblock(enc, named.block)
35+
outblock = decodedblock(enc, wrapped(named))
3536
return isnothing(outblock) ? nothing : Named(Name, outblock)
3637
end
3738

src/datasets/transformations.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,3 @@ getobs(jdata, 15) == 15
157157
```
158158
"""
159159
joinobs(datas...) = JoinedData(datas)
160-
161-
162-
function collectobs(data, parallel=false)
163-
collect()
164-
end

src/encodings/projective.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function blockitemtype(block::Mask{N}, n::Int) where N
135135
end
136136
end
137137
blockitemtype(block::Keypoints{N}, n::Int) where N = N == n ? DataAugmentation.Keypoints : nothing
138+
blockitemtype(block::WrapperBlock, n::Int) = blockitemtype(wrapped(block), n)
138139

139140

140141
"""
@@ -152,6 +153,7 @@ end
152153

153154
grabbounds(block::Image{N}, a, n) where N = N == n ? DataAugmentation.Bounds(size(a)) : nothing
154155
grabbounds(block::Mask{N}, a, n) where N = N == n ? DataAugmentation.Bounds(size(a)) : nothing
156+
grabbounds(block::WrapperBlock, a, n) = grabbounds(wrapped(block), a, n)
155157

156158

157159
function getsamplebounds(blocks, datas, N)

0 commit comments

Comments
 (0)