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

Data required to create json #425

Open
johnatan151 opened this issue Oct 27, 2024 · 10 comments
Open

Data required to create json #425

johnatan151 opened this issue Oct 27, 2024 · 10 comments

Comments

@johnatan151
Copy link

Hello,

I am trying to manually pass the values of my model to a JSON file so that it is compatible with fd. I am running into this issue not sure how to fix it. I wanted to ask if any knows what I can do to solve it or what the JSON file should contain exactly.

terminate called after throwing an instance of 'nlohmann::json_abi_v3_11_2::detail::type_error'
what(): [json.exception.type_error.302] type must be string, but is null

@Dobiasd
Copy link
Owner

Dobiasd commented Oct 29, 2024

Can you post the code/data required to re-create the problem?

@johnatan151
Copy link
Author

I should first state what my goal is since I am unsure if it's possible. My goal is to create a Pytorch model and write my own JSON file in the same format that Keras would produce. So I could run the Pytorch model as inference.

@Dobiasd
Copy link
Owner

Dobiasd commented Oct 31, 2024

Thanks for the context. The project sounds interesting, but also quite non-trivial. Frugally-deep's file format is very specific (and might change with newer versions). Especially the order of dimensions in the weights' matrices can become fiddly. Have you already looked into trying to convert your PyTorch model to Keras using whatever tool/lib, and then going to fdeep from there? If this would work, it would likely be simpler.

@johnatan151
Copy link
Author

I have considered that solution, but I want to be able to gather results only with pytorch to get a better comparison between the two.

@Dobiasd
Copy link
Owner

Dobiasd commented Nov 3, 2024

Which two would you like to compare?

To get back to your original question on what the JSON file should contain exactly:
Frugally-deep's convert_model.py has the definition. For the architecture part, you'd have to look into the code of model.to_json in the Keras/TensorFlow source, or into the import_model.hpp of frugally-deep.

@johnatan151
Copy link
Author

Compare keras and pytorch

@Dobiasd
Copy link
Owner

Dobiasd commented Nov 4, 2024

Ah, ok. 👍

And why don't you compare them directly without frugally-deep?

@johnatan151
Copy link
Author

I'm hoping to create my own JSON file, as Keras saves models in .h5 format and PyTorch saves them in .pth. From my understanding, these formats differ because of the way each backend stores models based on their graph layout. I’d like to understand exactly what frugally-deep requires in its JSON file, since my Keras models work with frugally-deep, but my PyTorch models do not. Once this is complete I wont be using Fdeep and just pass my json files to C++ to run.

@Dobiasd
Copy link
Owner

Dobiasd commented Nov 4, 2024

I'm hoping to create my own JSON file, as Keras saves models in .h5 format and PyTorch saves them in .pth. From my understanding, these formats differ because of the way each backend stores models based on their graph layout.

Yes, Keras and PyTorch serialize their models differently.

I’d like to understand exactly what frugally-deep requires in its JSON file, since my Keras models work with frugally-deep, but my PyTorch models do not.

That's expected. Frugally-deep was built to allow running Keras models in C++ without using Keras/TensorFlow. It's not intended to be used with PyTorch models.

Once this is complete I wont be using Fdeep and just pass my json files to C++ to run.

How do you intend to achieve this? The JSON format you're targeting can only be used with frugally-deep.

Both, TensorFlow and PyTorch have C++ APIs:

Maybe this is more suitable for your use-case. If you want to compare Keras with PyTorch (performance, for example), frugally-deep would not help with this, because you would only compare frugally-deep with frugally-deep.

@johnatan151
Copy link
Author

I see thank you for the help I will take a look into these API's. Saved me time :)

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