Skip to content

Commit e791b23

Browse files
authored
Docs: how-to for logging (#126)
* Add Metalhead PR setup instructions * Add how-to for TensorBoard logging
1 parent 8a2a1c0 commit e791b23

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

assets/tensorboardscreenshot.png

328 KB
Loading

docs/howto/logtensorboard.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# How to log to TensorBoard
2+
3+
TensorBoard is a format and viewer for logs of model training and can be used to inspect and compare the results of training runs. We can log step and epoch metrics, hyperparameters and even visualizations to TensorBoard using FluxTraining.jl's logging callbacks.
4+
5+
## Generating logs
6+
7+
To use logging callbacks, we need to pass a log backend, here [`TensorBoardBackend`](#). This design allows flexibly supporting other logging backends like Weights and Biases or neptune.ai in the future.
8+
9+
{cell=main}
10+
```julia
11+
using FastAI
12+
13+
dir = mktempdir()
14+
backend = TensorBoardBackend(dir)
15+
```
16+
17+
Then we create callbacks for logging metrics and hyperparameters to that backend:
18+
19+
{cell=main}
20+
```julia
21+
metricscb = LogMetrics(backend)
22+
hparamscb = LogHyperParams(backend)
23+
```
24+
25+
Like any other callbacks, these can then be passed to a `Learner` along with other callbacks and we can start training. By using the [`Metrics`](#) callback we can log metrics other than the loss.
26+
27+
```julia
28+
29+
callbacks = [
30+
metricscb,
31+
hparamscb,
32+
ToGPU(),
33+
Metrics(accuracy)
34+
]
35+
36+
data = Datasets.loadtaskdata(Datasets.datasetpath("imagenette2-160"), ImageClassificationTask)
37+
method = ImageClassification(Datasets.getclassesclassification("imagenette2-160"), (160, 160))
38+
learner = methodlearner(method, data, Models.xresnet18(), callbacks...)
39+
fitonecycle!(learner, 5)
40+
```
41+
42+
## Inspecting logs
43+
44+
To inspect the logs you will have to install the `tensorboard` command-line using `pip` (you can access the command-line in the Julia REPL by pressing `;`).
45+
46+
```
47+
shell> pip install tensorboard
48+
```
49+
50+
After this one-time installation, you can run it by pointing it to the log directory created above:
51+
52+
```
53+
shell> tensorboard --logdir $dir
54+
```
55+
56+
This should give you an URL that you can open in a browser which should look like this:
57+
58+
![](../../assets/tensorboardscreenshot.png)
59+
60+
Note that you can also open TensorBoard and it will update as the training progresses.

docs/setup.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Setup
22

3-
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:
3+
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 `]`).
44

55
```julia
66
pkg> add https://github.com/FluxML/FastAI.jl
@@ -10,4 +10,10 @@ FastAI.jl also defines [Makie.jl](https://github.com/JuliaPlots/Makie.jl) plotti
1010

1111
```julia
1212
pkg> add CairoMakie
13+
```
14+
15+
To use pretrained vision models, you currently have to install a WIP branch of Metalhead.jl:
16+
17+
```julia
18+
pkg> add https://github.com/darsnack/Metalhead.jl#darsnack/vision-refactor
1319
```

toc.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- [Find a good learning rate](docs/notebooks/lrfind.ipynb)
1717
- [Augment vision data](docs/howto/augmentvision.md)
1818
- [Visualize data](docs/notebooks/how_to_visualize.ipynb)
19+
- [Log to TensorBoard](docs/howto/logtensorboard.md)
1920
- Reference
2021
- [Docstrings](REFERENCE)
2122
- [Interfaces](docs/interfaces.md)

0 commit comments

Comments
 (0)