|
const fs = require('fs');
|
|
const sharp = require('sharp');
|
|
const ort = require('onnxruntime-node');
|
|
|
|
(async () => {
|
|
try {
|
|
|
|
const imageBuffer = await sharp('./training_images/shirt/00e745c9-97d9-429d-8c3f-d3db7a2d2991.jpg')
|
|
.resize(128, 128)
|
|
.raw()
|
|
.toBuffer();
|
|
|
|
|
|
const imgArray = Float32Array.from(imageBuffer).map(value => value / 255.0);
|
|
|
|
|
|
const inputTensor = new ort.Tensor('float32', imgArray, [1, 128, 128, 3]);
|
|
|
|
|
|
const session = await ort.InferenceSession.create('./saved-model/model.onnx');
|
|
|
|
|
|
const results = await session.run({ [session.inputNames[0]]: inputTensor });
|
|
|
|
console.log('Inference outputs:', results[session.outputNames[0]]);
|
|
} catch (err) {
|
|
console.error('Error:', err);
|
|
}
|
|
})();
|
|
|