From 4d9a08b6c25a486dde2a979b3bb9353d8912609f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=85?= Date: Tue, 6 Mar 2018 16:35:46 +0800 Subject: [PATCH] Check: image shape >:> tensor shape --- mace/core/tensor.h | 28 +++++++++++++++++++++++----- mace/core/workspace.cc | 6 ++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/mace/core/tensor.h b/mace/core/tensor.h index 47fa3d11..f1acb799 100644 --- a/mace/core/tensor.h +++ b/mace/core/tensor.h @@ -68,17 +68,20 @@ class Tensor { : allocator_(alloc), dtype_(type), buffer_(nullptr), - is_buffer_owner_(true) {}; + is_buffer_owner_(true), + name_("") {}; Tensor(BufferBase *buffer, DataType dtype) : dtype_(dtype), buffer_(buffer), - is_buffer_owner_(false) {} + is_buffer_owner_(false), + name_("") {} Tensor(const BufferSlice &buffer_slice, DataType dtype) : dtype_(dtype), buffer_slice_(buffer_slice), - is_buffer_owner_(false) { + is_buffer_owner_(false), + name_("") { buffer_ = &buffer_slice_; } @@ -184,8 +187,18 @@ class Tensor { } else { MACE_CHECK(has_opencl_image(), "Cannot ResizeImage buffer, use Resize."); Image *image = dynamic_cast(buffer_); - MACE_CHECK(image_shape[0] <= image->image_shape()[0] - && image_shape[1] <= image->image_shape()[1]); + MACE_CHECK(shape[0] <= image->image_shape()[0] + && shape[1] <= image->image_shape()[1], + "tensor (source op ", + name_, + "): current image shape: ", + image->image_shape()[0], + ", ", + image->image_shape()[1], + " < resize tensor shape: ", + shape[0], + ", ", + shape[1]); } } @@ -238,6 +251,10 @@ class Tensor { return buffer_; } + inline void SetSourceOpName(const std::string name) { + name_ = name; + } + inline void DebugPrint() const { using namespace numerical_chars; std::stringstream os; @@ -293,6 +310,7 @@ class Tensor { BufferBase *buffer_; BufferSlice buffer_slice_; bool is_buffer_owner_; + std::string name_; DISABLE_COPY_AND_ASSIGN(Tensor); }; diff --git a/mace/core/workspace.cc b/mace/core/workspace.cc index a7adb939..59c509e7 100644 --- a/mace/core/workspace.cc +++ b/mace/core/workspace.cc @@ -143,6 +143,12 @@ void Workspace::CreateImageOutputTensor(const NetDef &net_def) { if (op.has_mem_id()) { std::unique_ptr tensor (new Tensor(preallocated_allocator_.GetBuffer(op.mem_id()), dtype)); + tensor->SetSourceOpName(op.name()); + VLOG(3) << "Tensor: " << op.name() << "(" << op.type() << ")" << "; Mem: " + << op.mem_id() << "; Image shape: " + << dynamic_cast(tensor->UnderlyingBuffer())->image_shape()[0] + << ", " + << dynamic_cast(tensor->UnderlyingBuffer())->image_shape()[1]; tensor_map_[op.output(0)] = std::move(tensor); } } -- GitLab