Skip to content

Commit c531eab

Browse files
Merge pull request #296 from microsoft/user/xianz/batchSample
unbound output
2 parents 8356a2b + f413b62 commit c531eab

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

Samples/BatchSupport/BatchSupport/main.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,15 @@ int main(int argc, char *argv[]) {
6363
binding.Bind(inputFeatureDescriptor.Current().Name(), inputVideoFrames);
6464
}
6565

66-
// bind output tensor
67-
auto outputShape = std::vector<int64_t>{BATCH_SIZE, 1000, 1, 1};
66+
// bind output tensor, this step is optional, conmented out in the sample
67+
/*
68+
auto outputShape = std::vector<int64_t>{ BATCH_SIZE, 1000, 1, 1 };
6869
auto outputValue = TensorFloat::Create(outputShape);
6970
std::wstring outputDataBindingName =
70-
std::wstring(model.OutputFeatures().First().Current().Name());
71+
std::wstring(model.OutputFeatures().First().Current().Name());
7172
binding.Bind(outputDataBindingName, outputValue);
73+
*/
74+
7275

7376
// now run the model
7477
printf("Running the model...\n");
@@ -78,6 +81,13 @@ int main(int argc, char *argv[]) {
7881
printf("model run took %d ticks\n", ticks);
7982

8083
// Print Results
84+
85+
// conment out three lines below if bind output
86+
auto outputValue = results.Outputs().Lookup(L"softmaxout_1").as<TensorFloat>(); // Get outputs by output name
87+
auto outputShape = outputValue.Shape();
88+
printf("output dimensions [%d, %d, %d, %d]\n", outputShape.GetAt(0), outputShape.GetAt(1), outputShape.GetAt(2), outputShape.GetAt(3));
89+
// conment out three lines above if bind output
90+
8191
SampleHelper::PrintResults(outputValue.GetAsVectorView());
8292
}
8393

Samples/BatchSupport/readme.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,16 @@ Take binding batches of VideoFrame as example:
9393
9494
// Bind
9595
binding.Bind(inputFeatureDescriptor.Current().Name(), inputVideoFrames);
96+
```
97+
98+
### 3. Bind Outputs(optional)
99+
100+
The sample does not bind the output, but you could also bind the output as below:
101+
```C++
102+
auto outputShape = std::vector<int64_t>{BATCH_SIZE, 1000, 1, 1};
103+
auto outputValue = TensorFloat::Create(outputShape);
104+
std::wstring outputDataBindingName =
105+
std::wstring(model.OutputFeatures().First().Current().Name());
106+
binding.Bind(outputDataBindingName, outputValue);
107+
SampleHelper::PrintResults(outputValue.GetAsVectorView()); // Print Results
96108
```

0 commit comments

Comments
 (0)