Skip to content

Commit 87f4e40

Browse files
committed
Use Wasm backend (via ORT Web) for Scala.js backend
1 parent a8c1197 commit 87f4e40

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ Supported ONNX input and output tensor data types:
123123
* String
124124

125125
Supported ONNX ops:
126-
* ONNX-Scala, Fine-grained API: 87/178 total (69/178 when using Scala.js / ORT Web backend)
127-
* ONNX-Scala, Full model API: Same as below, depending on backend
126+
* ONNX-Scala, Fine-grained API: 87/178 total
127+
* ONNX-Scala, Full model API: Same as below
128128

129-
* ONNX Runtime Web (using WebGL backend): 69/178 total.
129+
* ONNX Runtime Web (using Wasm backend): 165/178 total.
130130
* ONNX Runtime: 165/178 total
131131

132132
See the [ONNX backend scoreboard](http://onnx.ai/backend-scoreboard/index.html)

backends/.js/src/main/scala/ORTWebOperatorBackend.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ trait ORTWebOperatorBackend extends OpToONNXBytesConverter {
4040
InferenceSession
4141
] = IO.fromFuture(IO { OrtSession.create(bytesArrayBuffer, {
4242
val opts = InferenceSession.SessionOptions()
43-
opts.executionProviders = scala.scalajs.js.Array("webgl")
43+
opts.executionProviders = scala.scalajs.js.Array("wasm")
4444
opts
4545
}
4646
).toFuture })

backends/.js/src/test/scala/SqueezeNetTest.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import org.scalatest.flatspec.AsyncFlatSpec
1616
import org.scalatest.freespec.AsyncFreeSpec
1717
import org.scalatest.matchers.should._
1818
import cats.effect.testing.scalatest.AsyncIOSpec
19+
import org.emergentorder.onnx.onnxruntimeCommon.inferenceSessionMod.InferenceSession
1920

2021
class ONNXScalaSpec extends AsyncFreeSpec with AsyncIOSpec with Matchers {
2122

@@ -24,7 +25,13 @@ class ONNXScalaSpec extends AsyncFreeSpec with AsyncIOSpec with Matchers {
2425
// TODO: push this inside ORTWebModelBackend, and use other create() which takes arraybufferlike
2526
val session: IO[
2627
org.emergentorder.onnx.onnxruntimeCommon.inferenceSessionMod.InferenceSession
27-
] = IO.fromFuture(IO { OrtSession.create("squeezenet1.0-12.onnx").toFuture })
28+
] = IO.fromFuture(IO { OrtSession.create("squeezenet1.0-12.onnx",
29+
{
30+
val opts = InferenceSession.SessionOptions()
31+
opts.executionProviders = scala.scalajs.js.Array("wasm")
32+
opts
33+
}
34+
).toFuture })
2835

2936
"SqueezeNet ONNX-Scala model should predict dummy image class" in {
3037
val squeezenet = new ORTWebModelBackend(session)

0 commit comments

Comments
 (0)