Not able to load local custom model (in React)
zegenerative opened this issue Β· comments
Dear ml5 community,
I'm submitting a new issue. Please see the details below.
β Step 1: Describe the issue π
Did you find a bug? Want to suggest an idea for a new example?
In React, I have a simple setup for a charRNN. When I try to load my model in the src/models/mymodel, it somehow does not load the model, even though the callback triggers.
β Step 2: Screenshots or Relevant Documentation πΌ
Here's some helpful screenshots and/or documentation of the new feature
β Step 3: Share an example of the issue π¦
Here's some example code or a demonstration of the issue in https://github.com/ml5js/ml5-examples OR in the https://editor.p5js.org or codepen/jsfiddle/etc...
clone the repo
npm i
npm start
git@github.com:zegenerative/ml5-lstm.git
Other relevant information, if applicable
β Describe your setup π¦
Here's some helpful information about my setup...
- Web browser & version:
- Operating System:
- ml5 version you're using:
- Any additional notes
Hi @zegenerative - one thing could be that the model
variable should rather be a path to the directory where your model and its associated weight files are living. I could be wrong about this, but maybe worth a try.
Thanks for your reply. What do you mean exactly? I tried all sorts of ways to point to the directory with its manifest.json and associated files. This directory lives in the src directory of the root directory.
Hmm oh I see you've tried that solution already. Would you be able to point to any of the error messages by chance?
Maybe one quick sanity check could be to check if one of the other models will load. So copy/paste this directory https://github.com/ml5js/ml5-examples/tree/release/p5js/CharRNN/CharRNN_Interactive/models/woolf
into your project and link to the path here when you create:
ml5.charRNN("https://github.com/ml5js/ml5-examples/tree/release/p5js/CharRNN/CharRNN_Interactive/models/woolf/")
I'd like to point to this repo where you could run it yourself:
git@github.com:zegenerative/ml5-lstm.git
one of the errors was:
When I do: ml5.charRNN('http://localhost:3000/src/models/mymodel/', modelLoaded) I get:
Uncaught SyntaxError: Unexpected token < in JSON at position 0
@zegenerative
Ah-hah!
Ok ok ok, so here's one solution:
- Put your
dinomodel
into thepublic
directory - in your
App.js
: you'll link to the public served assests
I made a PR here: zegenerative/dinosaurifier-reactredux#2
Hope this helps!
The idea is your models should be a static asset and you can just directly link to the URL where those assets are served :)
Please close this up when you've tested! Thanks!
Ah great! It is loading the model now. Thanks!