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

Load model with keras #9

Closed
AzazelHD opened this issue Jan 2, 2021 · 12 comments
Closed

Load model with keras #9

AzazelHD opened this issue Jan 2, 2021 · 12 comments

Comments

@AzazelHD
Copy link

AzazelHD commented Jan 2, 2021

Hi.

Is there anyway i can load this model using keras.models.load_model?

Pls i will really appreciate it

@shreyas-bk
Copy link
Owner

shreyas-bk commented Jan 3, 2021

Hi, there are implementations like this that may help.

@AzazelHD
Copy link
Author

AzazelHD commented Jan 3, 2021

Mmmm I dont think so. The predicted mask is way different from the original mask. I just want to load U2NET.pth weights into keras model. The original weights

@shreyas-bk
Copy link
Owner

I have been able to convert to a TensorFlow .pb saved model (using ONNX) if that helps, but currently I am unable to convert to Keras h5. I will try again when I get more time.

@AzazelHD
Copy link
Author

AzazelHD commented Jan 3, 2021

Yeah same. From pth to onnx can be done. But I havent found a way to make it .h5.
Also, if you can train the model with same datasets on keras and share a link with keras model, I will appreciate a lot.

Btw, thanks for helping me with this

@shreyas-bk
Copy link
Owner

No problem
I was able to get a Keras h5 file using pytorch2keras, however I had to change the upsampling mode from bilinear to nearest. Nevertheless, the predicted masks seem the same. Let me know if you want me to share it.

@AzazelHD
Copy link
Author

AzazelHD commented Jan 4, 2021

Yeah! I got that error complaining about upsampling layers. And sure, if you could share you will make me big favour ^^

Thank you very much dude

@shreyas-bk
Copy link
Owner

I made this repository : U-2-Net-Keras. You can find both the Keras h5 saved model as well as the notebook I used to make it. With the code in the inference cell of the notebook, you should get the right results.
Let me know if it works, and please star if it helped :)
I will also upload the TensorFlow version if anyone requires it.

@AzazelHD AzazelHD closed this as completed Jan 4, 2021
@AzazelHD AzazelHD reopened this Jan 4, 2021
@AzazelHD
Copy link
Author

AzazelHD commented Jan 4, 2021

Omg sorry I am derping. Im new here. How can I give u stars?

@shreyas-bk
Copy link
Owner

shreyas-bk commented Jan 4, 2021

There are buttons at the top of the page, (watch, star and fork), you can just click star
BTW if there are any further issues with the keras version let me know

@AzazelHD
Copy link
Author

AzazelHD commented Jan 4, 2021

I mean, probably your code works perfectly. I think i am just idiot. Could I add you to discord by chance?
BTW Star given ^^ thanks for your time

@AzazelHD
Copy link
Author

AzazelHD commented Jan 4, 2021

Oh I just noticed... You uploaded U2NETP... Could I ask for U2NET?

@shreyas-bk
Copy link
Owner

For U2NET, you can just download the original weight file to the colab in the repo, then just change u2netp to u2net in the setup cell. Either way, I'll also upload the Keras h5 for it, probably tomorrow.
For discord related things let's first connect by email ([email protected]) so that I can close this issue?

@AzazelHD AzazelHD closed this as completed Jan 4, 2021
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

2 participants