From 9e1231ac8dc499c2779ce5044a1db053f91ecf18 Mon Sep 17 00:00:00 2001 From: Vladimir Dudnik Date: Tue, 12 Oct 2021 18:17:58 +0300 Subject: [PATCH] limit supported formats by MNIST database only, added lenet.labels file (#7947) * limit supported formats by NIST database only, added lenet.labels file * shortened line * apply code style fix --- .../samples/ngraph_function_creation_sample/README.md | 6 +++--- .../ngraph_function_creation_sample/lenet.labels | 10 ++++++++++ .../samples/ngraph_function_creation_sample/main.cpp | 6 ++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 inference-engine/samples/ngraph_function_creation_sample/lenet.labels diff --git a/inference-engine/samples/ngraph_function_creation_sample/README.md b/inference-engine/samples/ngraph_function_creation_sample/README.md index ad10a9d5f82..74c8b7c9637 100644 --- a/inference-engine/samples/ngraph_function_creation_sample/README.md +++ b/inference-engine/samples/ngraph_function_creation_sample/README.md @@ -2,7 +2,7 @@ This sample demonstrates how to execute an synchronous inference using [nGraph function feature](../../../docs/nGraph_DG/build_function.md) to create a network, which uses weights from LeNet classification network, which is known to work well on digit classification tasks. -The sample supports only single-channel `ubyte` images as an input. +The sample supports only single-channel [MNIST database](http://yann.lecun.com/exdb/mnist) images as an input. You do not need an XML file to create a network. The API of ngraph::Function allows to create a network on the fly from the source code. @@ -21,7 +21,7 @@ Basic Inference Engine API is covered by [Hello Classification C++ sample](../he |:--- |:--- | Validated Models | LeNet | Model Format | Network weights file (\*.bin) -| Validated images | single-channel `ubyte` images +| Validated images | single-channel `MNIST ubyte` images | Supported devices | [All](../../../docs/IE_DG/supported_plugins/Supported_Devices.md) | | Other language realization | [Python](../../ie_bridges/python/sample/ngraph_function_creation_sample/README.md) | @@ -37,7 +37,7 @@ To build the sample, please use instructions available at [Build the Sample Appl ## Running -To run the sample, you need specify a model wights and ubyte image: +To run the sample, you need specify a model wights and MNIST ubyte image: - you can use LeNet model weights in the sample folder: `lenet.bin` with FP32 weights file - you can use images from the media files collection available at https://storage.openvinotoolkit.org/data/test_data. diff --git a/inference-engine/samples/ngraph_function_creation_sample/lenet.labels b/inference-engine/samples/ngraph_function_creation_sample/lenet.labels new file mode 100644 index 00000000000..f55b5c9eef3 --- /dev/null +++ b/inference-engine/samples/ngraph_function_creation_sample/lenet.labels @@ -0,0 +1,10 @@ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 \ No newline at end of file diff --git a/inference-engine/samples/ngraph_function_creation_sample/main.cpp b/inference-engine/samples/ngraph_function_creation_sample/main.cpp index 8afc44783d7..021cdef56b8 100644 --- a/inference-engine/samples/ngraph_function_creation_sample/main.cpp +++ b/inference-engine/samples/ngraph_function_creation_sample/main.cpp @@ -338,6 +338,12 @@ int main(int argc, char* argv[]) { slog::warn << "Image " + i + " cannot be read!" << slog::endl; continue; } + + if (reader->size() != inputInfoItem.second->getTensorDesc().getDims()[2] * + inputInfoItem.second->getTensorDesc().getDims()[3]) { + throw std::logic_error("Not supported format. Only MNist ubyte images supported."); + } + /** Store image data **/ std::shared_ptr data(reader->getData(inputInfoItem.second->getTensorDesc().getDims()[3], inputInfoItem.second->getTensorDesc().getDims()[2]));