[tensor_filter] Fix tensorfilter fail
authorJihoon Lee <jhoon.it.lee@samsung.com>
Tue, 24 Aug 2021 07:31:52 +0000 (16:31 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Thu, 26 Aug 2021 03:58:26 +0000 (12:58 +0900)
This patch fixes tensor filter fail due to two critical bugs

- readModel was broken
- tensor getSharedDataTensor was broken

**Self evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Jihoon Lee <jhoon.it.lee@samsung.com>
nntrainer/models/neuralnet.cpp
nntrainer/tensor/tensor.cpp
nntrainer/tensor/tensor.h
packaging/nntrainer.spec

index 6b0df0a..5c5817b 100644 (file)
@@ -424,8 +424,6 @@ void NeuralNetwork::readModel() {
   if (!initialized)
     throw std::runtime_error("Cannot save the model before initialize.");
 
-  NeuralNetwork tmp(*this);
-
   std::ifstream model_file(save_path, std::ios::in | std::ios::binary);
 
   for (auto iter = model_graph.cbegin(); iter != model_graph.cend(); iter++) {
@@ -435,9 +433,9 @@ void NeuralNetwork::readModel() {
   try {
     /// this is assuming that the failure is allowed at the end of the file
     /// read. so, after this line, additional read shouldn't be called
-    checkedRead(model_file, (char *)&tmp.epoch_idx, sizeof(epoch_idx),
+    checkedRead(model_file, (char *)&epoch_idx, sizeof(epoch_idx),
                 "[NeuralNetwork::readModel] failed to read epoch_idx");
-    checkedRead(model_file, (char *)&tmp.iter, sizeof(iter),
+    checkedRead(model_file, (char *)&iter, sizeof(iter),
                 "[NeuralNetwork::readModel] failed to read iteration");
   } catch (...) {
     model_file.close();
@@ -446,8 +444,6 @@ void NeuralNetwork::readModel() {
 
   model_file.close();
   ml_logi("read modelfile: %s", save_path.c_str());
-
-  swap(tmp, *this);
 }
 
 void NeuralNetwork::setBatchSize(unsigned int batch) {
@@ -520,8 +516,8 @@ std::vector<float *> NeuralNetwork::inference(std::vector<float *> &input) {
 
   input_tensors.reserve(input.size());
   for (unsigned int idx = 0; idx < in_dim.size(); idx++) {
-    input_tensors.emplace_back(MAKE_SHARED_TENSOR(
-      Tensor::Map(input[idx], in_dim[idx].getDataLen(), in_dim[idx], 0)));
+    input_tensors.emplace_back(MAKE_SHARED_TENSOR(Tensor::Map(
+      input[idx], in_dim[idx].getDataLen() * sizeof(float), in_dim[idx], 0)));
   }
 
   sharedConstTensors output_tensors = inference(input_tensors, false);
index fa8f4cf..e2bfb1f 100644 (file)
@@ -560,7 +560,7 @@ Tensor Tensor::getSharedDataTensor(const TensorDim dim_, unsigned int offset,
   Tensor ret = *this;
   ret.dim = dim_;
 
-  if (ret.bytes() + offset > bytes())
+  if (dim_.getDataLen() + offset > dim.getDataLen())
     throw std::invalid_argument(
       "Creating shared tensor of size bigger than tensor memory.");
 
index 0ab4598..3a12558 100644 (file)
@@ -823,7 +823,7 @@ public:
    * shape
    *
    * @param dim new dimension to be set for this tensor
-   * @param offset offset to be used from the start of the data in bytes
+   * @param offset offset to be used from the start of the data in elements
    * @note The new tensor will share the same data as the current tensor but
    * can have different size.
    * @note New size added with offset must be less than the size of the original
index 51bd1b8..38a79c3 100644 (file)
@@ -360,8 +360,7 @@ meson test -C build -t 2.0 --print-errorlogs
 # todo: migrate this to meson test soon
 %if 0%{?nnstreamer_filter}
 pushd test/nnstreamer
-# TODO: enable after layer_v2 refactor
-# ssat
+ssat
 popd
 %endif #nnstreamer_filter
 %endif #unit_test