diff --git a/include/aidge/backend/opencv/utils/Utils.hpp b/include/aidge/backend/opencv/utils/Utils.hpp
index 3caa6f96e04f4c3bdc59de36d7a47fecceb2e6b1..ee525dc5a790147ce7bc7caad906e110d58629ab 100644
--- a/include/aidge/backend/opencv/utils/Utils.hpp
+++ b/include/aidge/backend/opencv/utils/Utils.hpp
@@ -36,37 +36,39 @@ namespace Aidge {
         std::vector<DimSize_t> matDims = std::vector<DimSize_t>({static_cast<DimSize_t>(mat.cols),
                                                                 static_cast<DimSize_t>(mat.rows),
                                                                 static_cast<DimSize_t>(mat.channels())});
-        // Create tensor from the dims of the Cv::Mat
-        std::shared_ptr<Tensor> tensor = std::make_shared<Tensor>(matDims);
-        // Set beackend opencv 
-        tensor->setBackend("opencv");
-        // Set Data Type
+        Aidge::DataType type;
         switch (mat.depth()) {
             case CV_8U:
-                tensor->setDataType(Aidge::DataType::UInt8);
+                type = Aidge::DataType::UInt8;
                 break;
             case CV_8S:
-                tensor->setDataType(Aidge::DataType::Int8);
+                type = Aidge::DataType::Int8;
                 break;
             case CV_16U:
-                tensor->setDataType(Aidge::DataType::UInt16);
+                type = Aidge::DataType::UInt16;
                 break;
             case CV_16S:
-                tensor->setDataType(Aidge::DataType::Int16);
+                type = Aidge::DataType::Int16;
                 break;
             case CV_32S:
-                tensor->setDataType(Aidge::DataType::Int32);
+                type = Aidge::DataType::Int32;
                 break;
             case CV_32F:
-                tensor->setDataType(Aidge::DataType::Float32);
+                type = Aidge::DataType::Float32;
                 break;
             case CV_64F:
-                tensor->setDataType(Aidge::DataType::Float64);
+                type = Aidge::DataType::Float64;
                 break;
             default:
                 throw std::runtime_error(
                     "Cannot convert cv::Mat to Tensor: incompatible types.");
             }
+        
+        // Create tensor from the dims of the Cv::Mat
+        std::shared_ptr<Tensor> tensor = std::make_shared<Tensor>(matDims,type);
+        
+        // Set beackend opencv 
+        tensor->setBackend("opencv");
 
         // Cast the tensorImpl to access setCvMat function
         TensorImpl_opencv_* tImpl_opencv = dynamic_cast<TensorImpl_opencv_*>(tensor->getImpl().get());