constfaceapi=require('../dist/face-api.node-wasm.js');// use this when using face-api in dev mode
asyncfunctionreadImage(imageFile){
constbuffer=fs.readFileSync(imageFile);// read image from disk
constcanvas=awaitimage.imageFromBuffer(buffer);// decode to canvas
constimageData=image.getImageData(canvas);// read decoded image data from canvas
consttensor=tf.tidy(()=>{// create tensor from image data
constdata=tf.tensor(Array.from(imageData?.data||[]),[canvas.height,canvas.width,4],'int32');// create rgba image tensor from flat array and flip to height x width
constchannels=tf.split(data,4,2);// split rgba to channels
constrgb=tf.stack([channels[0],channels[1],channels[2]],2);// stack channels back to rgb
constsqueeze=tf.squeeze(rgb);// move extra dim from the end of tensor and use it as batch number instead