How to use the @tensorflow/tfjs-node-gpu.cast function in @tensorflow/tfjs-node-gpu

To help you get started, we’ve selected a few @tensorflow/tfjs-node-gpu examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alibaba / pipcook / packages / pipcook-plugins-image-class-data-access / src / index.ts View on Github external
console.log(`access ${type} image data...`);
  const bar1 = new _cliProgress.SingleBar({}, _cliProgress.Presets.shades_classic);
  bar1.start(fileNames.length, 0);
  for (let j = 0; j < fileNames.length; j++) {
    const jsonData = await parseAnnotation(fileNames[j]);
    bar1.update(j);
    let image = await Jimp.read(path.join(imagePath, jsonData.annotation.filename[0]));
    image = image.resize(imgSize[0], imgSize[1]);
    const trainImageBuffer = await image.getBufferAsync(Jimp.MIME_JPEG);
    const imageArray = new Uint8Array(trainImageBuffer);
    let label:any = jsonData.annotation.object[0].name[0];
    if (Object.keys(oneHotMap).length > 1) {
      label = tf.oneHot(tf.scalar(oneHotMap[label], 'int32'), Object.keys(oneHotMap).length);
    }
    dataFlows.push({
      xs: tf.cast(tf.node.decodeImage(imageArray, 3), 'float32'),
      ys: label
    })
  }
  bar1.stop();
}
github alibaba / pipcook / packages / pipcook-plugins-image-detection-data-access / src / index.ts View on Github external
let target = [];
    jsonData.annotation.object.forEach((item: any) => {
      target.push(oneHotMap[item.name[0]])
      target.push(parseFloat(item.bndbox[0].xmin[0]) * xratio )
      target.push(parseFloat(item.bndbox[0].xmax[0]) * xratio ) 
      target.push(parseFloat(item.bndbox[0].ymin[0]) * yratio ) 
      target.push(parseFloat(item.bndbox[0].ymax[0]) * yratio ) 
    });
    for (let ii = jsonData.annotation.object.length; ii < 10; ii++) {
      target.push(-1)
      for (let jj = 0; jj < 4; jj++) {
        target.push(0);
      }
    }
    dataFlows.push({
      xs: tf.cast(tf.node.decodeImage(imageArray, 3), 'float32'),
      ys: tf.tensor1d(target)
    })
  }
  bar1.stop();
}