UNPKG

qtf

Version:

command for want to Quick use TensorFlow.js on cli.

29 lines (21 loc) 647 B
const fs = require('fs'); //const fsp = require('fs').promises; const { tf } = require('./qtf-tfjs-loader'); const PImage = require('pureimage'); const img_to_t3d = async (imagePath) => { //const imgFile = await fsp.readFile(imagePath); //const img_u8a = new Uint8Array(imgFile); //const img_Tensor3D = tf.node.decodeImage(img_u8a); const pimg = await PImage.decodeJPEGFromStream( fs.createReadStream(imagePath) ); const data = Array.from(pimg.data); const img_Tensor3D = await tf .tensor(data) .reshape([-1,pimg.width,4]) .slice([0,0,0],[-1,-1,3]); return img_Tensor3D; } module.exports = { img_to_t3d, }