Converting an image to tensor for onnx in my javascript file #5779
Unanswered
shivampandya67
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
// Function to convert an image to a tensor
async function convertImageToTensor(image) {
return new Promise((resolve, reject) => {
if (!(image instanceof Blob)) {
reject(new Error('Invalid image parameter'));
return;
}
}
// Function to process the output tensor
function processOutput(outputTensor) {
// Assuming outputTensor is a Map with numeric keys and Float32Array values
const predictedEmotion = getPredictedEmotion(outputTensor);
}
// Function to get the predicted emotion from the output tensor
function getPredictedEmotion(outputTensor) {
let maxIndex = -1;
let maxScore = Number.NEGATIVE_INFINITY;
}
// Declare the ONNX session outside the runInference function
let session;
// Function to run inference on the uploaded image
async function runInference() {
// Get the input image from the file input
const fileInput = document.getElementById("imageInput");
const image = fileInput.files[0];
}
// Add event listener for the file input change
document.getElementById("imageInput").addEventListener("change", runInference);
Beta Was this translation helpful? Give feedback.
All reactions