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

Remove manual fetching of NN model.json and weights.bin files and use tf.io.http instead #114

Merged
merged 2 commits into from
Mar 27, 2024

Conversation

lindapaiste
Copy link
Contributor

Ref #113

Ref #84 (comment)

TBH this entire section of the code feels a bit odd and unnecessary. We are fetching the files, creating File objects, and then passing them to the TF model with tf.io.browserFiles. But TF is definitely capable of fetching files on its own so it seems like we shouldn't have to do that on our end. It seems like we should just be able to pass the URLs. That's a discussion for another time though, because maybe there's a reason that this is necessary and I'm just not seeing it.

Changes:

  • Remove manual fetching of files via axios.get and conversion to File objects.
  • Change tf.io.browserFiles to tf.io.http.
  • Set the weightUrlConverter option to use the path from the user's object instead of the path that TFJS finds in weightsManifest section of the model.json file.

Note: weightUrlConverter is specified as an async function but I wrote it as a normal function. We can throw in an async keyword if there is concern.

I did try it out and it worked.

image

I even modified the path in the model.json file (to "paths":["./not-the-right-path/model.weights.bin"]) because in this example the override URL is the same as what's in the weightsManifest. We do this in order to support the p5.js Web Editor, where the actual file path is a remote Amazon S3 URL.

@shiffman
Copy link
Member

Thank you @lindapaiste this seems like a much more concise way to load files, I tested all the examples and am going ahead to merge.

@shiffman shiffman merged commit a12fa18 into ml5js:main Mar 27, 2024
@lindapaiste lindapaiste deleted the cleanup/nn-load-http branch March 27, 2024 20:25
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

Successfully merging this pull request may close these issues.

2 participants