• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020-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 #include <algorithm>
17 
18 #include "minddata/dataset/kernels/ir/vision/random_resize_with_bbox_ir.h"
19 
20 #ifndef ENABLE_ANDROID
21 #include "minddata/dataset/kernels/image/random_resize_with_bbox_op.h"
22 #endif
23 
24 #include "minddata/dataset/kernels/ir/validators.h"
25 
26 namespace mindspore {
27 namespace dataset {
28 namespace vision {
29 #ifndef ENABLE_ANDROID
30 // RandomResizeWithBBoxOperation
RandomResizeWithBBoxOperation(const std::vector<int32_t> & size)31 RandomResizeWithBBoxOperation::RandomResizeWithBBoxOperation(const std::vector<int32_t> &size)
32     : TensorOperation(true), size_(size) {}
33 
34 RandomResizeWithBBoxOperation::~RandomResizeWithBBoxOperation() = default;
35 
Name() const36 std::string RandomResizeWithBBoxOperation::Name() const { return kRandomResizeWithBBoxOperation; }
37 
ValidateParams()38 Status RandomResizeWithBBoxOperation::ValidateParams() {
39   RETURN_IF_NOT_OK(ValidateVectorSize("RandomResizeWithBBox", size_));
40   return Status::OK();
41 }
42 
Build()43 std::shared_ptr<TensorOp> RandomResizeWithBBoxOperation::Build() {
44   constexpr size_t dimension_zero = 0;
45   constexpr size_t dimension_one = 1;
46   constexpr size_t size_two = 2;
47 
48   // If size is a single value, the smaller edge of the image will be
49   // resized to this value with the same image aspect ratio.
50   int32_t height = size_[dimension_zero];
51   int32_t width = 0;
52 
53   // User specified the width value.
54   if (size_.size() == size_two) {
55     width = size_[dimension_one];
56   }
57 
58   std::shared_ptr<RandomResizeWithBBoxOp> tensor_op = std::make_shared<RandomResizeWithBBoxOp>(height, width);
59   return tensor_op;
60 }
61 
to_json(nlohmann::json * out_json)62 Status RandomResizeWithBBoxOperation::to_json(nlohmann::json *out_json) {
63   (*out_json)["size"] = size_;
64   return Status::OK();
65 }
66 
from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)67 Status RandomResizeWithBBoxOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
68   CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("size") != op_params.end(), "Failed to find size");
69   std::vector<int32_t> size = op_params["size"];
70   *operation = std::make_shared<vision::RandomResizeWithBBoxOperation>(size);
71   return Status::OK();
72 }
73 #endif
74 }  // namespace vision
75 }  // namespace dataset
76 }  // namespace mindspore
77