Skip to content

Commit

Permalink
fix retro-compatibility issue of tensorflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico-Curti committed Apr 30, 2024
1 parent 430b466 commit 77f27a9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

## Wound analysis using smartphone images

Official implementation of the deepskin algorithm published on [International Journal of Molecular Science](https://www.mdpi.com/1422-0067/24/1/706) by Curti et al. [![International Journal of Molecular Science](https://img.shields.io/badge/IJMS-1422_0067/24/1/706-g.svg)](https://www.mdpi.com/1422-0067/24/1/706)
Official implementation of the deepskin algorithm published on [International Journal of Molecular Science](https://www.mdpi.com/1422-0067/24/1/706) by Curti et al. [![International Journal of Molecular Science](https://img.shields.io/badge/IJMS-1422_0067/24/1/706-g.svg)](https://www.mdpi.com/1422-0067/24/1/706) and used in [![Journal of Medical Systems](https://img.shields.io/badge/JMS-10.1007/s10916/023/02029/9-g.svg)](https://link.springer.com/article/10.1007/s10916-023-02029-9)

* [Overview](#overview)
* [Prerequisites](#prerequisites)
Expand Down Expand Up @@ -191,6 +191,34 @@ See [here](https://github.com/Nico-Curti/Deepskin/blob/main/.github/CONTRIBUTING

## FAQ

* <details>
<summary>
<b>
I'm working with tensorflow `v2.16.1` (or later) and the model produces incorrect segmentations
</b>
</summary>
<p>

If you are working with `tensorflow` versions higher than `2.16.1`, the default Keras version used by the model is `Keras 3`, as indicated in the release documentation (ref. [here](https://blog.tensorflow.org/2024/03/whats-new-in-tensorflow-216.html)).
The original deepskin model was trained with lower versions of `tensorflow` (and, therefore, with lower version of `Keras`).
Therefore, there could be problems related to backward compatibility of packages which can lead to very strange segmentation results: an example is reported and discussed in the [issue](https://github.com/Nico-Curti/Deepskin/issues/2) which reported this error.
A possible solution to solve this issue is to force the use of the legacy version of Keras, adding an extra line at the **beginning** of your scripts:

```python
import os
os.environ['TF_USE_LEGACY_KERAS'] = '1'
from deepskin import wound_segmentation
```

This way, before importing tensorflow package via the deepskin module, the environment variable sets the version of Keras to be used by the model.

**NOTE:** Newer versions of tensorflow are optimized to use the latest versions of Keras, so there may be a loss of efficiency during the prediction!

**NOTE 2:** Incorrect segmentation could be obtained even with images very far from the data used during the model training, so the Keras version couldn't be the answer to all your problems...

</p>
</details>

:construction: **WORK IN PROGRESS** :construction:

## Authors
Expand Down Expand Up @@ -230,6 +258,26 @@ If you have found `deepskin` helpful in your research, please consider citing th
}
```

or the related work about automated PWAT estimation

```BibTex
@article{Curti2024,
author = {Curti, Nico and Merli, Yuri and Zengarini, Corrado and Starace, Michela and Rapparini, Luca and Marcelli, Emanuela and Carlini, Gianluca and Buschi, Daniele and Castellani, Gastone C. and Piraccini, Bianca Maria and Bianchi, Tommaso and Giampieri, Enrico},
title = {Automated Prediction of Photographic Wound Assessment Tool in Chronic Wound Images},
journal = {Journal of Medical Systems},
year = {2024},
month = {Jan},
day = {16},
volume = {48},
number = {1},
pages = {14},
abstract = {Many automated approaches have been proposed in literature to quantify clinically relevant wound features based on image processing analysis, aiming at removing human subjectivity and accelerate clinical practice. In this work we present a fully automated image processing pipeline leveraging deep learning and a large wound segmentation dataset to perform wound detection and following prediction of the Photographic Wound Assessment Tool (PWAT), automatizing the clinical judgement of the adequate wound healing. Starting from images acquired by smartphone cameras, a series of textural and morphological features are extracted from the wound areas, aiming to mimic the typical clinical considerations for wound assessment. The resulting extracted features can be easily interpreted by the clinician and allow a quantitative estimation of the PWAT scores. The features extracted from the region-of-interests detected by our pre-trained neural network model correctly predict the PWAT scale values with a Spearman's correlation coefficient of 0.85 on a set of unseen images. The obtained results agree with the current state-of-the-art and provide a benchmark for future artificial intelligence applications in this research field.},
issn = {1573-689X},
doi = {10.1007/s10916-023-02029-9},
url = {https://doi.org/10.1007/s10916-023-02029-9}
}
```

or the related work about the transfer learning on pet-wound images

```BibTex
Expand Down
13 changes: 1 addition & 12 deletions deepskin/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,9 @@ def deepskin_model (verbose : bool = False) -> tf.keras.Model :
# define the efficientnetb3 model as encoder part
encoder = tf.keras.applications.efficientnet.EfficientNetB3(
include_top=False,
weights=None, # remove pre-processing ImageNet layers
input_shape=(IMG_SIZE, IMG_SIZE, 3),
)
# v2.8.0
if int(tf.__version__.replace('.', '')) > 284:
# in TF version greater than 2.8.4 there is an
# extra-layer in the pre-processing head of the model
# which perform an true-division rescaling of the
# input. To keep the retro-compatibility with the
# TF version used during the training of the model, we
# need to skip this step, replacing it with a simple
# dummy function.
# TODO: exclude this check and re-train the model with
# newer version of TF (!)
encoder.layers[3].function = lambda x, y : x

# get the feature layers
layers = [
Expand Down

0 comments on commit 77f27a9

Please sign in to comment.