justadudewhohacks / tfjs-tiny-yolov2

Tiny YOLO v2 object detection with tensorflow.js.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't load model

nukadelic opened this issue · comments

I have uploaded the coco model shard# files to remote server but can't seem to load it, please have a look at : https://codesandbox.io/s/y083p9nz39

The final url your loading the model from seems to be wrong: https://uploads.codesandbox.io/uploads/user/38363f64-0d83-4bc1-946f-9f741badbeed/1YLA-coco_model-weights_manifest_uploaded/-weights_manifest.json.

I think you forgot the .json file ending of the manifest file, that you are trying to load:

let modelWeightsManifest = "https://uploads.codesandbox.io/uploads/user/38363f64-0d83-4bc1-946f-9f741badbeed/1YLA-coco_model-weights_manifest_uploaded.json";

The extra string in the end ( /-weights_manifest.json ) will be added to any file. just to make sure I attempted to referenced a picture URL, and it included this string as well. After some digging through the developer console I found the file where it's done: https://github.com/justadudewhohacks/tfjs-image-recognition-base/blob/master/src/common/getModelUris.ts#L2

without over complicating things, is it possible to load model from an imported JSON string? , like so:

import CocoWeights from '../model/coco_model-weights_manifest.json';
import CocoConfig from '../model/coco_model_config.json';
...
const net = new yolo.TinyYolov2(CocoConfig);
await net.load( CocoWeights );

This setup will produce the following error:
TinyYolov2.load - expected model uri, or weights as Float32Array

I got a similar setup working this way via tf.loadModel( tf.io.browserFiles( [ ... here is an example https://codesandbox.io/s/kor4m66poo?module=%2Fsrc%2FModelLoader.ts

Maybe I did not fully understand, but as I said, you forgot the .json ending in your url. Thats why /-weights_manifest.json is appended to at the end, since what you give as input to the load function is not a valid uri to a json file.

To your second question, it will be possible to load the model from the json file as you suggested, once I publish the stuff I am currently working on.

Nope sorry, you had it right the first time, I didn't pay full attention to your answer and got carried away. Will be waiting for the update with anticipation.

It's now possible to load your model from the weight map using net.loadFromWeightMap(weightMap) where weightMap is what you retreive from tf.io.loadWeights.