> For the complete documentation index, see [llms.txt](https://gut-analysis-toolbox.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gut-analysis-toolbox.gitbook.io/docs/benchmarks/ganglia-models.md).

# Ganglia Models

Ganglia model benchmark v3 vs v2

### Ganglia Model v3

We recently updated our enteric ganglia model to v3. This model architecture is more powerful than v2 and we have added more training data, specifically from [Hamnett et al. (2022)](https://doi.org/10.1016/j.cub.2022.08.030).

The median IoU for v3 (0.83 ± 0.08 ) is higher than v2 (0.79 ± 0.09 ) when evaluating on the test dataset (mean  ± std, 20 images).&#x20;

<figure><img src="https://460806082-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUMXPxIZOpwi2uL22W18F%2Fuploads%2FhZDmI9xWfk2piZjMLhzk%2Fimage.png?alt=media&amp;token=126c5829-8cca-4695-ad80-c9f7eca880d6" alt=""><figcaption><p>Ganglia model v2 vs v3</p></figcaption></figure>

Although this may not appear to be much, in v3 we replaced the original UNet (v2) with a Feature Pyramid Network (FPN) and a ResNet101 backbone. Also, the median IoU is higher. This architecture offers several improvements:

* **Stronger feature extraction**: ResNet101 captures complex patterns better, meaning it may work well for challenging datasets -> high noise or uneven illumination.
* **Multi-scale fusion**: FPN integrates features at multiple resolutions, improving segmentation of enteric ganglia of different sizes.
* **Improved generalization**: The model should perform better than v2 across varying imaging conditions and datasets.&#x20;

***

### Testing different architectures

We have used PyTorch instead of Tensorflow and adapted code from this [repository ](https://github.com/mukund-ks/DeepLabV3Plus-PyTorch)for training our new ganglia model. We wanted to have the flexibility of testing multiple architectures, so [segmentation-models-pytorch](https://segmentation-modelspytorch.readthedocs.io/en/latest/) library was incorporated into the code. The two architectures that worked well were:

* DeepLabv3Plus
* Feature Pyramid Network

Using a combined loss of Dice and BCE Loss seemed to work the best. This is possibly because BCE will help with pixelwise classification and Dice will aid in overall segmentation quality. However, we had to test different combinations of weights.

The graphs below show shows the IoU and Dice scores for each network and weight combination. The syntax for x axis is: `NETWORK`\_`dice_weight`\_`BCE_weight` . So, FPN\_0.1\_0.9 means FPN network with 0.1 weighting for Dice and 0.9 weighting for BCE.

<figure><img src="https://460806082-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUMXPxIZOpwi2uL22W18F%2Fuploads%2F0aQK5PwDHUYifZYbG3Ft%2Fimage.png?alt=media&amp;token=eb4f9007-3951-453c-b354-e253e47704f5" alt=""><figcaption><p>IoU for each network and weight combination</p></figcaption></figure>

<figure><img src="https://460806082-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUMXPxIZOpwi2uL22W18F%2Fuploads%2F7XBwIcFfx8Kr9zteaHLN%2Fimage.png?alt=media&amp;token=b100fd29-aefe-4297-9854-c29abb3c8b8d" alt=""><figcaption><p>Dice score for each network and weight combination</p></figcaption></figure>

We chose FPN\_0.6\_0.4 even though others had a higher score as it did a better job with  separating ganglia on some challenging images. They all perform fairly well, so this will be re-evaluated with new data at a future stage.&#x20;

Example segmentation, showing how FPN\_0.6\_0.4 separates ganglia accurately (yellow arrow). But, both of them separate areas which was joined in ground truth data (light green).&#x20;

<figure><img src="https://460806082-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUMXPxIZOpwi2uL22W18F%2Fuploads%2FtpC0zBb2gaqfl0wYCwhY%2Fimage.png?alt=media&amp;token=b01bd161-016c-4b52-8d40-70f5a12fa2e7" alt=""><figcaption><p>Comparing ganglia segmentation</p></figcaption></figure>

However, there is a lot of subjectivity with defining ganglia and it can get very tricky, especially in the proximal colon. It is recommended to combine no. of cells/ganglia with spatial analysis in GAT.
