ml5js / ml5-examples

A collection of ml5.js examples

Home Page:https://examples.ml5js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Screen Shot 2019-10-30 at 11 12 10

β†’ 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 tried, doesn't work:
Screen Shot 2019-10-30 at 15 53 24

The only thing I was able to load, was the imageClassifier example, where the 'path' to the model is 'MobileNet'. I'm assuming that is a 'built-in' model or something?

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:

  1. Put your dinomodel into the public directory
  2. 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!