Add documentation for YOLO train phase

This commit is contained in:
Tobias Eidelpes 2023-03-09 10:38:18 +01:00
parent d7dd335971
commit 671bb8dd43

View File

@ -1,5 +1,26 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "d32cb908",
"metadata": {},
"source": [
"# Table of contents\n",
"1. [Introduction](#introduction)\n",
"2. [Load train metrics](#loadmetrics)\n",
"3. [Plot metrics](#plotmetrics)"
]
},
{
"cell_type": "markdown",
"id": "0249e74b",
"metadata": {},
"source": [
"## Introduction <a name=\"introduction\"></a>\n",
"\n",
"In this notebook we load the training metrics which have been saved during training on the cluster and generate nice plots for visualization."
]
},
{
"cell_type": "code",
"execution_count": 1,
@ -14,6 +35,16 @@
"from helpers import set_size"
]
},
{
"cell_type": "markdown",
"id": "9afb12e4",
"metadata": {},
"source": [
"## Load train metrics <a name=\"loadmetrics\"></a>\n",
"\n",
"The metrics have been saved to YOLO's `runs` directory in a file called `results.txt`. The file does not contain headers, unfortunately, so we have to set them manually here."
]
},
{
"cell_type": "code",
"execution_count": 2,
@ -344,6 +375,14 @@
"df"
]
},
{
"cell_type": "markdown",
"id": "78ad0ffe",
"metadata": {},
"source": [
"To be able to plot multiple lines in one plot, seaborn expects a _merged_ dataframe."
]
},
{
"cell_type": "code",
"execution_count": 12,
@ -478,6 +517,16 @@
"df_aranged"
]
},
{
"cell_type": "markdown",
"id": "b4626b54",
"metadata": {},
"source": [
"## Plot metrics <a name=\"plotmetrics\"></a>\n",
"\n",
"First, set the style of the plots to match with all other plots."
]
},
{
"cell_type": "code",
"execution_count": 5,
@ -492,6 +541,14 @@
" 'xtick.labelsize': 8, 'ytick.labelsize': 8})"
]
},
{
"cell_type": "markdown",
"id": "85f2437a",
"metadata": {},
"source": [
"Second, specify the save directory for the plots."
]
},
{
"cell_type": "code",
"execution_count": 6,
@ -502,6 +559,14 @@
"fig_save_dir = '../../thesis/graphics/'"
]
},
{
"cell_type": "markdown",
"id": "53b6e6c2",
"metadata": {},
"source": [
"Third, point seaborn to the dataframe and specify how to discriminate the two metrics (precision and recall). In this case, the different metrics are stored under the dataframe column `metrics` and thus we specify it for `style`."
]
},
{
"cell_type": "code",
"execution_count": 7,
@ -533,6 +598,14 @@
"fig.savefig(fig_save_dir + 'precision_recall.pdf', format='pdf', bbox_inches='tight')"
]
},
{
"cell_type": "markdown",
"id": "cea90e65",
"metadata": {},
"source": [
"Plot the box and object loss during training. YOLO usually reports a third loss (`cls_loss`) which is in this case always zero because we only have one class (_Plant_)."
]
},
{
"cell_type": "code",
"execution_count": 8,
@ -570,6 +643,14 @@
"fig.savefig(fig_save_dir + 'val_box_obj_loss.pdf', format='pdf', bbox_inches='tight')"
]
},
{
"cell_type": "markdown",
"id": "ccfd9180",
"metadata": {},
"source": [
"Plot the fitness of the model per epoch. The best weights are selected based on fitness, which is why the vertical gray line marks the best fitness at epoch 133. Fitness is calculated as the weighted average of `mAP@0.5` and `mAP@0.5:0.95` with the weighting 0.1 and 0.9, respectively."
]
},
{
"cell_type": "code",
"execution_count": 9,