async function runAndVisualizeInference(model) {
  // Synthesize an input image and show it in the canvas.
  const synth = new ObjectDetectionImageSynthesizer(canvas, tf);

  const numExamples = 1;
  const numCircles = 10;
  const numLineSegments = 10;
  const {images, targets} = await synth.generateExampleBatch(
      numExamples, numCircles, numLineSegments);

  const t0 = tf.util.now();
  // Runs inference with the model.
  const modelOut = await model.predict(images).data();
  inferenceTimeMs.textContent = `${(tf.util.now() - t0).toFixed(1)}`;

  // Visualize the true and predicted bounding boxes.
  const targetsArray = Array.from(await targets.data());
  const boundingBoxArray = targetsArray.slice(1);
  drawBoundingBoxes(canvas, boundingBoxArray, modelOut.slice(1));

  // Display the true and predict object classes.
  const trueClassName = targetsArray[0] > 0 ? 'rectangle' : 'triangle';
  trueObjectClass.textContent = trueClassName;

  // The model predicts a number to indicate the predicted class
  // of the object. It is trained to predict 0 for triangle and
  // 224 (canvas.width) for rectangel. This is how the model combines
  // the class loss with the bounding-box loss to form a single loss
  // value. Therefore, at inference time, we threshold the number
  // by half of 224 (canvas.width).
  const shapeClassificationThreshold = canvas.width / 2;
  const predictClassName =
      (modelOut[0] > shapeClassificationThreshold) ? 'rectangle' : 'triangle';
  predictedObjectClass.textContent = predictClassName;

  if (predictClassName === trueClassName) {
    predictedObjectClass.classList.remove('shape-class-wrong');
    predictedObjectClass.classList.add('shape-class-correct');
  } else {
    predictedObjectClass.classList.remove('shape-class-correct');
    predictedObjectClass.classList.add('shape-class-wrong');
  }

  // Tensor memory cleanup.
  tf.dispose([images, targets]);
}
Synthesize an input image, run inference on it and visualize the results.

@param {tf.Model} model Model to be used for inference.