Fix caffe blob import (#1211)
authorEfimov Alexander/AI Tools Lab/./Samsung Electronics <a.efimov@samsung.com>
Tue, 28 Aug 2018 14:57:55 +0000 (17:57 +0300)
committerРоман Михайлович Русяев/AI Tools Lab /SRR/Staff Engineer/삼성전자 <r.rusyaev@samsung.com>
Tue, 28 Aug 2018 14:57:55 +0000 (17:57 +0300)
Replace copy of float into char array with float to float copy

Signed-off-by: Efimov Alexander <a.efimov@samsung.com>
contrib/nnc/plugin/frontend/caffe/src/caffe_model_visitor.cpp

index eaa812e..5934480 100644 (file)
@@ -152,14 +152,21 @@ std::shared_ptr<IrTensor> ModelVisitor::createTensor(const BlobProto &bp)
   IrTensor::DTYPE type = IrTensor::DTYPE::FLOAT;
   size_t elementSize;
 
+  const char *srcData;
+  size_t bufferSize;
+
   if (bp.data_size() != 0)
   {
     assert(bp.double_data_size() == 0);
     elementSize = sizeof(float);
+    bufferSize = bp.data_size() * elementSize;
+    srcData = reinterpret_cast<const char *>(bp.data().data());
   }
   else if (bp.double_data_size() != 0)
   {
     elementSize = sizeof(double);
+    bufferSize = bp.double_data_size() * elementSize;
+    srcData = reinterpret_cast<const char *>(bp.double_data().data());
   }
   else
   {
@@ -167,10 +174,11 @@ std::shared_ptr<IrTensor> ModelVisitor::createTensor(const BlobProto &bp)
   }
 
   // Create untyped tensor. Note, tensor contents will be *copied* here.
-  std::shared_ptr<char> tensorBufferCopy(new char[bp.data().size() * elementSize],
-                                         [](char *d) { delete[] d; });
+  std::shared_ptr<char> tensorBufferCopy(new char[bufferSize],
+                                         std::default_delete<char[]>());
 
-  std::copy(bp.data().begin(), bp.data().end(), tensorBufferCopy.get());
+  char *dstData = tensorBufferCopy.get();
+  memcpy(dstData, srcData, bufferSize);
 
   Shape tensorShape = common::ShapeHelper::createShape(
           bp.shape().dim(), static_cast<size_t>(bp.shape().dim_size()));