Comments (2)
First off, the type params here are for the output. So it shouldn't be "Features" but (predicted) "Class" (or whatever your outputs are).
You can represent typed tensors with symbolic dimensions (i.e. for dynamic batch size) like so:
def input: Tensor[Float, Tuple3["ImageClassification", "Batch" ##: "Class" ##: TSNil, Dimension #: 512 #: SNil]] = ???
However, the fullModel
call and the fine-grained ops will not work directly on such tensors, as they need to get the value of the dimension via implicits (at compile-time).
You can either:
A) pad your inputs to the correct (static) dimension size or
B) Cast an Int to a Dimension:
val batch: Dimension = calcBatchSize().asInstanceOf[Dimension]
val data = Array.fill(batch*3*224*224){42f}
//In NCHW tensor image format
val shape = batch #: 3 #: 224 #: 224 #: SNil
val tensorShapeDenotation = "Batch" ##: "Features" ##: "Height" ##: "Width" ##: TSNil
val tensorDenotation: String & Singleton = "Image"
val imageTens = Tensor(data,tensorDenotation,tensorShapeDenotation,shape)
val out = model.fullModel[Float, "ImageClassification", "Batch" ##: "Class" ##: TSNil, batch.type #: 1000 #: SNil](Tuple(imageTens))
For this to work, the ONNX model has to represent the dimension we are concerned with correctly (as a symbolic dimension), just as the static dimensions in the code must match those in the model.
from onnx-scala.
I am working on Transfer-learning project, where last layer is deleted, so that output notation is "Features" in my case :-), but thank you for pointing out.
Option B is working fine for me. Thank your for answer.
from onnx-scala.
Related Issues (10)
- Errors When Building Project HOT 5
- Program generator dose'nt work for convert onnx file to scala HOT 3
- Platform not supported exception HOT 10
- why not use onnxruntime's Java API? HOT 6
- sbt console tab completion broken after importing io.kjaer.compiletime._ HOT 3
- object compiletime is not a member of package org.emergentorder HOT 2
- Accessing multiple outputs HOT 2
- Question: why does `Tensor#apply` return a value wrapped in `IO` effect? HOT 1
- Quick Questions HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from onnx-scala.