• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "schema/model_v0_generated.h"
18 #include "src/ops/compat/attr_transfer_common.h"
19 
20 namespace mindspore {
21 namespace lite {
TransferNchw2NhwcAttr(LiteGraph::Node * node,std::vector<schema::Tensor * > * dst_tensors,std::vector<char * > * const tensor_bufs)22 int TransferNchw2NhwcAttr(LiteGraph::Node *node, std::vector<schema::Tensor *> *dst_tensors,
23                           std::vector<char *> *const tensor_bufs) {
24   if (node == nullptr || node->primitive_ == nullptr || dst_tensors == nullptr || tensor_bufs == nullptr) {
25     MS_LOG(ERROR) << "the parameter of this function is nullptr.";
26     return RET_ERROR;
27   }
28   if (node->input_indices_.size() != 1) {
29     MS_LOG(DEBUG) << "nchw2nhwc don't need to convert attr to tensor.";
30     return RET_OK;
31   }
32   dst_tensors->clear();
33   std::vector<int> dst_shape{0, 2, 3, 1};  // nchw to nhwc
34   auto dst_shape_tensor = AttrToTensor(dst_shape.data(), dst_shape.size(), true, kNumberTypeInt32, tensor_bufs);
35   if (dst_shape_tensor == nullptr) {
36     MS_LOG(ERROR) << "attr tensor is nullptr, transform is failed.";
37     return RET_NULL_PTR;
38   }
39   dst_tensors->push_back(dst_shape_tensor);
40   return RET_OK;
41 }
42 
43 Register Nchw2NhwcTransferRegistry(SCHEMA_VERSION::SCHEMA_V0, schema::v0::PrimitiveType_Nchw2Nhwc,
44                                    TransferNchw2NhwcAttr);
45 }  // namespace lite
46 }  // namespace mindspore
47