
ort:run( $session as node, $inputs as node, [$options as map:map] ) as map:map
Perform inference of a session, based on supplied input values. Returns a
map:map of output names and their values.
xquery version "1.0-ml";
let $session := ort:session(fn:doc("testmodel.onnx"))
let $input-count := ort:session-input-count($session)
let $output-count := ort:session-output-count($session)
let $input-names :=
for $i in (0 to $input-count - 1) return ort:session-input-name($session,
$i) let $output-names := for $i in (0 to $output-count - 1) return
ort:session-output-name($session, $i) let $input-types := for $i in (0 to
$input-count - 1) return ort:session-input-type($session, $i) let $output-types
:= for $i in (0 to $output-count - 1) return ort:session-output-type($session,
$i)
let $input-values :=
for $i in (1 to $input-count)
(: generate some arbitrary input data. :)
let $data := (1 to fn:fold-left(function($a, $b) { $a * $b }, 1,
map:get($input-types, "shape"))) return ort:value($data, map:get($input-types,
"shape"), map:get($input-types, "tensor-type"))
let $input-map := map:map()
let $input-maps :=
for $i in (1 to $input-count)
return map:with($input-map, $input-names[$i], $input-values[$i])
let $input-map := $input-maps[$input-count]
return ort:run($session, $input-map)
=>
<map:map xmlns:map="http://marklogic.com/xdmp/map"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"> <map:entry key="output_0">
<map:value xsi:type="ort:value"
xmlns:ort="http://marklogic.com/onnxruntime">OrtValue(Shape:[1, 1000, 1, 1],
Type: FLOAT)
</map:value>
</map:entry>
</map:map>
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.