Skip to content

Commit

Permalink
training_guideline: Reordered cells, clarified doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jcohenadad committed Nov 11, 2018
1 parent 9f18edd commit 7f06523
Showing 1 changed file with 23 additions and 37 deletions.
60 changes: 23 additions & 37 deletions notebooks/training_guideline.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -96,33 +96,7 @@
"metadata": {},
"source": [
"### 1. Train a new model\n",
"#### 1.1. Create subfolder to save new model and its parameters.\n",
"\n",
"For simplicity, the new model will be created under the `models/` folder in the AxonDeepSeg repository. The name of the model folder will be generated automatically using the date and time (to avoid multiple instances)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Define path to where the trained model will be saved\n",
"dir_name = time.strftime(\"%Y-%m-%d\") + '_' + time.strftime(\"%H-%M-%S\")\n",
"path_model = os.path.join('../models/', dir_name)\n",
"\n",
"# Create directory\n",
"if not os.path.exists(path_model):\n",
" os.makedirs(path_model)\n",
"\n",
"file_config = 'config_network.json' # file name of network configuration"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 1.2. Define the name and path of the training set\n",
"#### 1.1. Define the name and path of the training set\n",
"\n",
"Here we assume that the training data folder has already been created by following the guidelines detailed in [guide_dataset_building.ipynb](https://github.com/neuropoly/axondeepseg/blob/master/notebooks/guide_dataset_building.ipynb).\n",
"\n",
Expand All @@ -147,19 +121,18 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"trainingset_name = 'TEM_3c_512'\n",
"path_training = './TEM_striatum/data' # folder containing training data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 1.3. Define the configuration parameters of the training\n",
"#### 1.2. Define the U-Net architecture and hyper-parameters\n",
"\n",
"Here we defined the network and training parameters (i.e. hyperparameters). We use a lighter network than the ones used in the original [AxonDeepSeg article](https://www.nature.com/articles/s41598-018-22181-4), because they require large GPU memory (>12GB). The network below runs on an NVIDIA TitanX in ~30min. Note that the architecture below might not produce satisfactory results on your data so you likely need to play around with the architecture and hyperparameters.\n",
"\n",
Expand All @@ -179,7 +152,7 @@
" \"n_classes\": 3, # Number of classes. For this application, the number of classes should be set to **3** (i.e. axon pixel, myelin pixel, or background pixel).\n",
" \"thresholds\": [0, 0.2, 0.8], # Thresholds for the 3-class classification problem. Do not modify. \n",
" \"trainingset_patchsize\": 512, # Patch size of the training set in pixels (note that the patches have the same size in both dimensions). \n",
" \"trainingset\": trainingset_name, # Name of the training set.\n",
" \"trainingset\": \"TEM_3c_512\", # Name of the training set.\n",
" \"batch_size\": 8, # Batch size, i.e. the number of training patches used in one iteration of the training. Note that a larger batch size will take more memory.\n",
"\n",
"# Network architecture parameters: \n",
Expand Down Expand Up @@ -237,9 +210,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 1.4. Save configuration parameters of the network as configuration file (.json)\n",
"#### 1.3. Define training path and save configuration parameters\n",
"\n",
"After the config. parameters of the network to be trained are defined, they are saved into a .json file in the model folder. This .json file keeps tract of the network and model parameters in a structured way."
"Here we define the path where the new model will be saved. It is useful to add date+time in path definition in case multiple training are launched (to avoid conflicts).\n",
"\n",
"The network configuration parameters defined at 1.2. are saved into a .json file in the model folder. This .json file keeps tract of the network and model parameters in a structured way."
]
},
{
Expand All @@ -248,7 +223,18 @@
"metadata": {},
"outputs": [],
"source": [
"# Load config file\n",
"# Define path to where the trained model will be saved\n",
"dir_name = time.strftime(\"%Y-%m-%d\") + '_' + time.strftime(\"%H-%M-%S\")\n",
"path_model = os.path.join('../models/', dir_name)\n",
"\n",
"# Create directory\n",
"if not os.path.exists(path_model):\n",
" os.makedirs(path_model)\n",
"\n",
"# Define file name of network configuration\n",
"file_config = 'config_network.json'\n",
"\n",
"# Load/Write config file (depending if it already exists or not)\n",
"fname_config = os.path.join(path_model+file_config)\n",
"if os.path.exists(fname_config):\n",
" with open(fname_config, 'r') as fd:\n",
Expand All @@ -264,7 +250,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 1.5. Launch the training procedure\n",
"#### 1.4. Launch the training procedure\n",
"\n",
"The training can be launched by calling the *'train_model'* function. After each epoch, the function will display the loss and accuracy of the model. The model is automatically saved at every 5 epochs."
]
Expand All @@ -285,9 +271,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 1.6. Monitor the training with Tensorboard\n",
"#### 1.5. Monitor the training with Tensorboard\n",
"\n",
"TensorBoard can be used to monitor the training procedure (loss and accuracy graphs, gradients, activations, identify bugs, etc.). To run TensorBoard, activate ADS virtual environment and run:\n",
"[TensorBoard](https://www.tensorflow.org/guide/summaries_and_tensorboard) can be used to monitor the training procedure (loss and accuracy graphs, gradients, activations, identify bugs, etc.). To run TensorBoard, activate ADS virtual environment and run:\n",
"```\n",
"tensorboard --logdir PATH_MODEL --port 6006\n",
"```\n",
Expand Down

0 comments on commit 7f06523

Please sign in to comment.