interpreter_plugin: fix input tensor initialization (#953)
authorVitaliy Cherepanov/AI Tools Lab /SRR/Engineer/삼성전자 <v.cherepanov@samsung.com>
Fri, 10 Aug 2018 09:14:10 +0000 (12:14 +0300)
committerSergey Vostokov/AI Tools Lab /SRR/Staff Engineer/삼성전자 <s.vostokov@samsung.com>
Fri, 10 Aug 2018 09:14:10 +0000 (12:14 +0300)
add tensor and input file sizes checking

Signed-off-by: Vitaliy Cherepanov <v.cherepanov@samsung.com>
contrib/nnc/libs/backend/interpreter/plugin/src/interpreter_plugin.cpp

index 641c167..cda86d7 100644 (file)
@@ -1,6 +1,7 @@
 #include <map>
 #include <vector>
 #include <fstream>
+#include <sstream>
 
 #include "PluginParam.h"
 #include "PluginInstance.h"
@@ -94,6 +95,15 @@ TensorVariant InterpreterPlugin::loadInput(const Shape &shape)
   auto f = fopen(params["filename"].c_str(), "rb");
   fseek(f, 0L, SEEK_END);
   auto len = ftell(f);
+  auto tensorSize = num_elements(shape) * sizeof(float);
+
+  // Check size
+  if (len != tensorSize) {
+    std::stringstream info;
+    info << "Wrong input file size <" << params["filename"] << "> = " << len << ". Should be :" << tensorSize;
+    throw PluginException(info.str());
+  }
+
   rewind(f);
   auto data = new char[len];
   auto rlen = fread(data, len, 1, f);