1

ML / Tensorflow beginner.

I'm having trouble trying to get one of the layers from the coco ssd model imported as a package in a React application. I'm following the Pacman tensorflow.js example to retrain the model.

  const modelPromise = cocoSsd.load();
  Promise.all([modelPromise])
    .then(cocoModel => {
      console.log(cocoModel[0]);

      var cocoModel = cocoModel[0].model;
      console.log(cocoModel);

      const layer = cocoModel.getLayer('conv_pw_13_relu');
      this.truncatedCocoModel = tf.model({inputs: cocoModel.inputs, outputs:
                                                              layer.output});
   })
   .catch(error => {
      console.error(error);
   });

In the const layer line I get the error message that 'cocoModel.getLayer is not a function'. The Pacman example is using the mobilenet model which I guess has this function.

What are my options here? I looked around using the browser console but I can't find this function anywhere and looking online didn't help much (is there any place online where I can see the whole structure of the cocoSSD model by Google?)

model functions

serv-inc
  • 35,772
  • 9
  • 166
  • 188
avd
  • 45
  • 7

1 Answers1

0

Using the npm package https://cdn.jsdelivr.net/npm/@tensorflow-models/coco-ssd, you cannot retrieve any layer.

load returns an instance of ObjectDetection which does not have the getLayer property.

If you want to retrieve the layer, you would have to load the graph model as described here

edkeveked
  • 17,989
  • 10
  • 55
  • 93
  • Got it. However when looking at the model URLs returned by cocoSSD's load() function, it seems that there's only the .pb file, not the model's .json file. Would you happen to know where can I find the model.json file for the cocossd model? I can only find the weights_manifest.json but I guess passing that as MODEL_URL will return an error just like the .pb one. – avd Mar 03 '19 at 13:04
  • As far as I know the Coco-SSD model is not available in Keras JSON form. In addition, I am not at all sure that following the Pacman example will give good results in this case. If you want to train an object detector on your own images, you may be better of doing that server-side; see https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/running_pets.md. – David Soergel Mar 06 '19 at 20:52
  • Yeah, I also think the same, in fact my initial approach was to train the thing in Anaconda with Python using my GPU but I'm pretty much Python illiterate and I was running into too many issues, so I decided to see if I could do something with JS. I obviously need to go back to Python. Thanks for the article, I've followed it but it doesn't tackle the re-train issue (the link is missing in 'What's next'). I'll accept the answer because what's asked is covered by it. Thanks to both! – avd Mar 08 '19 at 16:06