0
$\begingroup$

I have trained a mobilenet on diamond images to count diamonds in broswer. I then converted the SavedModel format to TFJS format. I have the following code in my JS file.

async function initialize() {
try{
    model = await tf.loadGraphModel('trained-model/model.json');
}catch(e) {
   console.log("The model is not loaded") 
}

classifierElement.style.display = 'block';
loaderElement.style.display = 'none';

document.getElementById('predict').addEventListener('click', () => predictOnClick());
}

async function predictOnClick () {

  const imageElement = document.getElementById('img');
  let tensorImg = tf.browser.fromPixels(imageElement,3).cast('int32').resizeNearestNeighbor([640, 640]);//.expandDims();
  const t4d=tensorImg.expandDims(0);
  t4d.print() 
  data = await t4d.data()

  prediction = model.executeAsync(t4d).data().then(prediction=> { 
  console.log("FULL STRUCTURE",prediction)})

I am getting the following in console output enter image description here

The tensorflow model Non-Javascript version returns the following dict

['detection_multiclass_scores', 'detection_classes', 'detection_boxes', 'raw_detection_boxes', 'detection_scores', 'raw_detection_scores', 'detection_anchor_indices', 'num_detections'])

So how do I obtain the scores and detection boxes data from the TFJS model rather than (8)[e,e,e,e,e,e,e,e] format?

Thanks

$\endgroup$
5
  • $\begingroup$ What data is contained in each of the e records? I.e. what do you see when you click open one of the 8 arrows? $\endgroup$ – Oxbowerce Mar 2 at 11:07
  • $\begingroup$ @Oxbowerce, when I open for example 4 which i studied and came to know that those are the detection_scores, but i am getting the following: dataId: {id: 1320} dtype: "float32" id: 841 isDisposedInternal: false kept: false rankType: "2" scopeId: 783 shape: (2) [1, 1000] size: 1000 strides: [1000] isDisposed: (...) rank: (...) proto: Object $\endgroup$ – uNIKx Mar 2 at 12:40
  • $\begingroup$ And when is console predictions[4], then it consoles the complete array of the predictions. $\endgroup$ – uNIKx Mar 2 at 12:42
  • $\begingroup$ So if example 4 holds the detection_scores then each example links back to the list you get back in the non-js version, which is what you want right? Also have a look at this stackoverflow question. $\endgroup$ – Oxbowerce Mar 2 at 12:47
  • $\begingroup$ Everytime I restart the server, this time its 4, then sometimes its 6 that holds the prediction_scores. How to resolve this ? COCOSSD has something like prediction.scores, predictions.bbox. How to know about MobileNet $\endgroup$ – uNIKx Mar 2 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.