Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect segmentation results? #2

Closed
abdullahbaa5 opened this issue Apr 24, 2024 · 12 comments
Closed

Incorrect segmentation results? #2

abdullahbaa5 opened this issue Apr 24, 2024 · 12 comments

Comments

@abdullahbaa5
Copy link

Just found this awesome easy to setup and use library but the results for segmentation are not correct, even when the image that was used for your example is used:

image

Any idea what might be causing this?

@danielcollura
Copy link

I am getting the exact same issue as you

@abdullahbaa5
Copy link
Author

**danielcollura ** commented

do you think it is related to the model or maybe something changed in the latest version of the requirments?

@Nico-Curti
Copy link
Owner

Hi @abdullahbaa5 and @danielcollura,

Sorry for the late reply, but this very strange issue took me a while to verify.
I checked the code on both the Windows and Unix OS to make sure it wasn't an operating system issue and on my computer it works fine on both.
This issue does not appear to be related to CPU or GPU usage, which is a fairly common source of errors like this.
After some tests I managed to replicate your problem by updating the Tensorflow version: in all my tests I used v2.8.0 (and everything works fine), while switching to v2.10.0 I got strange behavior like yours.

I'm still trying to understand the real cause of this problem, but in the meantime you can check the correctness of the code for older versions of tensorflow.

@abdullahbaa5
Copy link
Author

Hi @abdullahbaa5 and @danielcollura,

Sorry for the late reply, but this very strange issue took me a while to verify. I checked the code on both the Windows and Unix OS to make sure it wasn't an operating system issue and on my computer it works fine on both. This issue does not appear to be related to CPU or GPU usage, which is a fairly common source of errors like this. After some tests I managed to replicate your problem by updating the Tensorflow version: in all my tests I used v2.8.0 (and everything works fine), while switching to v2.10.0 I got strange behavior like yours.

I'm still trying to understand the real cause of this problem, but in the meantime you can check the correctness of the code for older versions of tensorflow.

Thank you for taking out your time to figure the issue out!

I will degrade the tensorflow version and get back to you.

@Nico-Curti
Copy link
Owner

Probably I found the error...
In the latest version of TF there is an additional layer at the top of the EfficientNetB3 model (ref here).
This layer performs further division of the input after normalization, changing the image values differently than during training.
The update about this topic is discussed here.

Retraining the model with newer TF versions takes me too long now, so I "fixed" this problem in the latest commit replacing the normalization function with a dummy one.
I tested this update with TF v2.9.3 and it seems to work fine now.

Let me know if the error persists.

@abdullahbaa5
Copy link
Author

Probably I found the error... In the latest version of TF there is an additional layer at the top of the EfficientNetB3 model (ref here). This layer performs further division of the input after normalization, changing the image values differently than during training. The update about this topic is discussed here.

Retraining the model with newer TF versions takes me too long now, so I "fixed" this problem in the latest commit replacing the normalization function with a dummy one. I tested this update with TF v2.9.3 and it seems to work fine now.

Let me know if the error persists.

thank you! it works great now.

@danielcollura
Copy link

@abdullahbaa5 how do you downgrade TF to 2.9.3? what version of python are you using?

@Nico-Curti
Copy link
Owner

Now it should work also with higher TF versions but I didn't test it yet.
However, you should easily downgrade it re-installing the package and forcing the desired version with pip install tensorflow==2.9.3.
I'm working with Python 3.10 but the version shouldn't affect the results.

@danielcollura
Copy link

@Nico-Curti Thanks for your response. I tested on Saturday with the latest version and got the incorrect segmentation as displayed in the beginning. I was using the Jupyter notebook in the repo and just provided the path to the image. I am also using M1 MacBook Pro.

@Nico-Curti
Copy link
Owner

Did you reinstall also the package after the pull?
Which is your TF version?
Which is your Python version?
If you are working with a different TF version, please check also with the downgraded version and let me know if the issue persists

@danielcollura
Copy link

I reinstalled the package. My TF version is 2.16.1. My python version is 3.11.8.

@Nico-Curti
Copy link
Owner

Hi @danielcollura

I checked all the latest versions of tensorflow and now the code should work fine up to v2.15.1.
In the latest version of TF (2.16.1), the authors change the default version of the keras backend, switching to the new Keras 3 support.
Probably, there are still some issues due to retro-compatibility of functions, but I couldn't find the exact point.
However, I have added a dedicated section in the FAQ documentation that exaplina possible way to overcome this issue using the current version of the deepskin package and the newer version of TF.

I hope this can help you in your work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants