Skip to content

🧠 Training Your Own Networks

The DL_Track_US package GUI includes the possibility to train your own neural networks.


Why train your own model?

  • To create models tailored to your own dataset.
  • To improve segmentation if the example models don't generalize well enough.
  • To learn more about deep learning for muscle ultrasound.

🚨 It’s highly recommended to have a working GPU setup; otherwise training can take much longer.
Check out our GitHub repository for setup instructions.

If you're new to neural networks, we recommend this introduction course.

πŸ“ Note:
DL_Track_US UI allows training but not modifying network architectures!


The paired images and labeled masks needed for training are located in:
πŸ“ DL_Track_US_example/model_training

Download DL_Track_US Examples & Models if you haven’t already.

In this tutorial, we will train a model for aponeurosis segmentation.
Training a fascicle segmentation model is identical β€” only the images and masks would differ.


1. Data Preparation and Image Labeling

Inside the DL_Track_US_example/model_training folder:

  • πŸ“ apo_img_example β†’ Original images
  • πŸ“ apo_mask_example β†’ Corresponding labeled masks

model training folder

⚑ IMPORTANT:
Image names and mask names must match exactly!

Example:

image mask


2. Specifying Relevant Directories

  • Open the UI.
  • Click the Advanced Methods button.
  • In the dropdown, select Train Model.

advanced methods select method train_model

Now specify the directories:

Select Image Directory

  • Click Images.
  • Select DL_Track_US_example/model_training/apo_img_example.

images_button


Select Mask Directory

  • Click Masks.
  • Select DL_Track_US_example/model_training/apo_mask_example.

masks_button


Select Output Directory

  • Click Output.
  • Choose a folder to save the trained model, loss plots, and CSV results.

output_button


Image augmentation artificially increases your dataset size by applying random transformations.

🚨 Especially recommended if you have fewer than 1500 images.

  • Click Augment Images.

augment_button

A messagebox will notify you once augmentation is complete.


4. Specifying Training Parameters

  • Keep the default settings for this tutorial.
  • NEVER use just 3 epochs for real training.
    (3 epochs are okay only for testing.)

hyperparameters

Now click:

  • Start Training

training_button

Three messageboxes will guide you during the training process.

Once training is finished, you’ll find:

  • Trained model (Test_Apo.h5)
  • Training loss plot (Training_Results.tif)
  • Loss values per epoch (Test_apo.csv)

5. Using Your Own Networks

You can use your trained models like this:

  • Click Apo Model or Fasc Model in the GUI to load your trained model.

apo model fasc model

⚑ IMPORTANT:
Never use the same images for training and inference.
Always validate on unseen data to check your model's performance.

If unsure, feel free to ask in our DL_Track_US Discussion Forum!


6. Error Handling

Errors during training trigger a messagebox:

error handling

Follow the instructions shown.
Uncaught errors should be reported in the
DL_Track_US Discussion Forum.

See here for guidance on how to best report errors.


7. Labeling Your Own Images

To train your networks, you must label images correctly.

πŸ›  We provide a semi-automated script!

You need:

  • πŸ“ Original images folder
  • πŸ“ output_images folder
  • πŸ“ fascicle_masks folder
  • πŸ“ aponeurosis_masks folder

You’ll use ImageJ/Fiji and our script:
πŸ—‚ DL_Track_US/DL_Track_US/gui_helpers/gui_files/Image_Labeling_DL_Track_US.ijm

Drag the .ijm file into a running Fiji/ImageJ window to start.

fiji labelling


Labeling Steps

  1. Set Directories:
    a. Input images
    b. Aponeurosis masks
    c. Fascicle masks
    d. Output images

  2. Label Aponeuroses:
    Use polygon tool to select superficial and then deep aponeurosis.

    upper_apo lower_apo

  3. Label Fascicles:
    Use segmented line tool for clearly visible fascicle parts only.

    fascicles

  4. Save and Move to Next Image.


βœ… You are now ready to create your own high-quality training datasets!