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

Failed to parse model JSON #7

Closed
krushal-kyada opened this issue Nov 18, 2021 · 14 comments
Closed

Failed to parse model JSON #7

krushal-kyada opened this issue Nov 18, 2021 · 14 comments

Comments

@krushal-kyada
Copy link

Hi!
I'm getting Error as Unhandled Rejection (Error): Failed to parse model JSON on this repo example.
Can please help me fix it.?

I don't have experience working with JS if some can provide steps to fix it will be helpful.

Version details : 
tensorflow==2.6.0
tensorflowjs==3.11.0

npm -v
8.1.3

Screenshot from 2021-11-18 12-23-37

Thnks

@zldrobit
Copy link
Owner

@krushal-kyada Hi! Could you confirm the web of this repo works correctly in a browser? Could you provide a minimal reproducible example? From the messages above, you are calling the web application by an HTTP JSON method, but I am afraid that the web application of this repo does not provide an HTTP JSON interface.

@krushal-kyada
Copy link
Author

Hi, I have just cloned the repo and trying to run that.
npm start opens up Mozilla firefox
http://localhost:3000/tfjs-yolov5-example

Screenshot from 2021-11-23 15-38-28

Let me know if I am missing out on anything.

Thanks.

@zldrobit
Copy link
Owner

It seems that you haven't exported the tfjs yolov5 model yet. Plz follow the instruction in the repo README.md.
I excerpted it for convenience:
image

First, clone YOLO v5 repo and export a tfjs yolov5 model.
Second, clone this repo and link the model path.
Third, run npm install && npm start.

@krushal-kyada
Copy link
Author

Hi

I have followed the above steps,

Also, have the converted model linked

Converted model using


git clone https://github.com/ultralytics/yolov5.git
python export.py --weights yolov5s.pt --include tfjs

Screenshot from 2021-11-24 12-16-40

Linked model using
ln -s ../../yolov5/yolov5s_web_model public/web_model

Screenshot from 2021-11-24 12-13-59

Just for reference :
npm install
image

Then too it's not working.
Let me know if I am missing anything.

Thanks

Krushal

@zldrobit
Copy link
Owner

From the messages you provided, there seems to be no errors. Could you provide the output message from terminal after the command npm start? This message should contain some debug information needed to resolve the problem.

@krushal-kyada
Copy link
Author

Please refer to the below snippet.
Mozilla Firefox and terminal window
Screenshot from 2021-11-25 09-01-40

@zldrobit
Copy link
Owner

My terminal output is different from yours considering the URL.
image
It has no tfjs-yolov5-example suffix. Did you change any code in the repo?

@krushal-kyada
Copy link
Author

krushal-kyada commented Nov 29, 2021

Hi

I have not made any changes to the code file.
Followed the steps, cloned the repos, and npm start.

Below is my project structure,
Please verify the directory locations of both repo,

└── zldrobit
    ├── tfjs-yolov5-example
    │   ├── node_modules
    │   ├── package.json
    │   ├── package-lock.json
    │   ├── public
    │   │   ├── index.html
    │   │   └── web_model -> /home/krushalkyada/Project/TF_JS/Yolo/zldrobit/yolov5/yolov5s_web_model
    │   ├── README.md
    │   └── src
    │       ├── index.js
    │       └── styles.css
    └── yolov5
        ├── CONTRIBUTING.md
        ├── data
        ├── detect.py
        ├── Dockerfile
        ├── export.py
        ├── hubconf.py
        ├── LICENSE
        ├── models
        ├── README.md
        ├── requirements.txt
        ├── setup.cfg
        ├── train.py
        ├── tutorial.ipynb
        ├── utils
        ├── val.py
        ├── venv
        │   ├── bin
        │   ├── lib
        │   ├── pyvenv.cfg
        │   └── share
        ├── yolov5s.pb
        ├── yolov5s.pt
        ├── yolov5s_saved_model
        │   ├── assets
        │   ├── keras_metadata.pb
        │   ├── saved_model.pb
        │   └── variables
        └── yolov5s_web_model
            ├── group1-shard1of7.bin
            ├── group1-shard2of7.bin
            ├── group1-shard3of7.bin
            ├── group1-shard4of7.bin
            ├── group1-shard5of7.bin
            ├── group1-shard6of7.bin
            ├── group1-shard7of7.bin
            └── model.json

Thanks
Krushal

@zldrobit
Copy link
Owner

Hi.
I found that your web_model directory is linked to /home/Project/TF_JS/Yolo/zldrobit/yolov5/yolov5s_web_model. I think it should be linked to /home/krushalkyada/Project/TF_JS/Yolo/zldrobit/yolov5/yolov5s_web_model, if your home directory is /home/krushalkyada. Maybe you have to relink the directory, and plz check the web_model directory with ls command.

@krushal-kyada
Copy link
Author

It is connected to the web model from the Yolo folder.
update :

web_model -> /home/krushalkyada/Project/TF_JS/Yolo/zldrobit/yolov5/yolov5s_web_model

Screenshot from 2021-11-29 14-29-59

Content of the linked folder
Screenshot from 2021-11-29 14-29-45

@zldrobit
Copy link
Owner

Please share more messages to find the cause of the problem:

  • Press F12 in the browser to show the debug window and share the full debug stack.
  • Run curl http://localhost:3000/web_model/model.json and curl http://localhost:3000/tfjs-yolov5-example/web_model/model.json on terminal, and share the output messages in terminal.

@krushal-kyada
Copy link
Author

Hi
Please refer to the below screenshots:
F12 in the browser to show the debug window and share the full debug stack.

Screenshot from 2021-11-29 16-01-14

Output for the following command :

curl http://localhost:3000/web_model/model.json 

Screenshot from 2021-11-29 16-09-18

curl http://localhost:3000/tfjs-yolov5-example/web_model/model.json

this command gives the content of the model.json file.
The below screenshot is part of the whole thing...

Screenshot from 2021-11-29 16-16-21

Looking at the response of curl http://localhost:3000/tfjs-yolov5-example/web_model/model.json

I have updated the index.js.
as

const weights = 'http://localhost:3000/tfjs-yolov5-example/web_model/model.json';

instead of

const weights = '/web_model/model.json';

And i was able to run the project,

Is this a correct way to load the weights?

Thanks

Krushal Kyada

@zldrobit
Copy link
Owner

Yes, that's the right way to load weights. As I remember, it's also the original code in this repo. You're welcome :D

@krushal-kyada
Copy link
Author

Thanks a lot.

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