Skip to content

Commit

Permalink
testing applied lesson
Browse files Browse the repository at this point in the history
  • Loading branch information
jlooper committed Jun 15, 2021
1 parent 21d1d77 commit 7163906
Show file tree
Hide file tree
Showing 4 changed files with 297 additions and 345 deletions.
64 changes: 36 additions & 28 deletions 4-Classification/4-Applied/solution/index.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
<html>

<head> </head>

<body>
<!-- Load ONNX.js -->
<script src="https://cdn.jsdelivr.net/npm/onnxjs/dist/onnx.min.js"></script>
<!-- Code that consumes ONNX.js -->
<script>
// create a session
const myOnnxSession = new onnx.InferenceSession();
// load the ONNX model file
myOnnxSession.loadModel('./model-kn.onnx').then(() => {

// generate model input
const inferenceInputs = getInputs();
console.log(inferenceInputs)
// execute the model
myOnnxSession.run(inferenceInputs).then((output) => {
// consume the output
const outputTensor = output.values().next().value;
console.log(`model output tensor: ${outputTensor.data}.`);
});
});
</script>
</body>

</html>
<!DOCTYPE html>
<html>
<header>
<title>ONNX Runtime JavaScript examples: Quick Start - Web (using script tag)</title>
</header>
<body>
<!-- import ONNXRuntime Web from CDN -->
<!--script src="./dist/ort.min.js"></script-->
<script src="https://cdn.jsdelivr.net/npm/onnxruntime-web@1.8.0-dev.20210608.0/dist/ort.min.js"></script>
<script>
// use an async context to call onnxruntime functions.
async function main() {
try {
// create a new session and load the specific model.
//
const session = await ort.InferenceSession.create('./model.onnx');

const input = new ort.Tensor(new Float32Array([5, 10, 15, 20, 25, 30, 23, 35, 50, 200]), [1, 10]);
const feeds = { float_input: input };

// feed inputs and run
const results = await session.run(feeds);

// read from results
const output = JSON.stringify(results);
document.write(`data of result tensor 'c': ${output}`);

} catch (e) {
document.write(`failed to inference ONNX model: ${e}.`);
}
}

main();
</script>
</body>
</html>
Binary file added 4-Classification/4-Applied/solution/model.onnx
Binary file not shown.
Loading

0 comments on commit 7163906

Please sign in to comment.