1 /**
2 * Copyright 2020 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 <map>
18 #include <string>
19 #include <vector>
20 #include <memory>
21 #include "ops/resize.h"
22 #include "ops/op_utils.h"
23 #include "utils/check_convert_utils.h"
24 #include "abstract/primitive_infer_map.h"
25
26 namespace mindspore {
27 namespace ops {
Init(const Format format,const ResizeMethod method,const int64_t new_height,const int64_t new_width,const bool preserve_aspect_ratio,const CoordinateTransformMode coordinate_transform_mode,const float cubic_coeff,const int64_t exclude_outside,const float extrapolation_value,const NearestMode nearest_mode)28 void Resize::Init(const Format format, const ResizeMethod method, const int64_t new_height, const int64_t new_width,
29 const bool preserve_aspect_ratio, const CoordinateTransformMode coordinate_transform_mode,
30 const float cubic_coeff, const int64_t exclude_outside, const float extrapolation_value,
31 const NearestMode nearest_mode) {
32 this->set_format(format);
33 this->set_method(method);
34 this->set_new_height(new_height);
35 this->set_new_width(new_width);
36 this->set_preserve_aspect_ratio(preserve_aspect_ratio);
37 this->set_coordinate_transform_mode(coordinate_transform_mode);
38 this->set_cubic_coeff(cubic_coeff);
39 this->set_exclude_outside(exclude_outside);
40 this->set_extrapolation_value(extrapolation_value);
41 this->set_nearest_mode(nearest_mode);
42 }
set_format(const Format format)43 void Resize::set_format(const Format format) {
44 int64_t swi = format;
45 (void)this->AddAttr(kFormat, MakeValue(swi));
46 }
47
set_method(const ResizeMethod method)48 void Resize::set_method(const ResizeMethod method) {
49 auto swi = (int64_t)method;
50 (void)this->AddAttr(kMethod, MakeValue(swi));
51 }
52
set_new_height(const int64_t new_height)53 void Resize::set_new_height(const int64_t new_height) { (void)this->AddAttr(kNewHeight, MakeValue(new_height)); }
54
set_new_width(const int64_t new_width)55 void Resize::set_new_width(const int64_t new_width) { (void)this->AddAttr(kNewWidth, MakeValue(new_width)); }
56
set_preserve_aspect_ratio(const bool preserve_aspect_ratio)57 void Resize::set_preserve_aspect_ratio(const bool preserve_aspect_ratio) {
58 (void)this->AddAttr(kPreserveAspectRatio, MakeValue(preserve_aspect_ratio));
59 }
60
set_coordinate_transform_mode(const CoordinateTransformMode coordinate_transform_mode)61 void Resize::set_coordinate_transform_mode(const CoordinateTransformMode coordinate_transform_mode) {
62 int64_t swi = coordinate_transform_mode;
63 (void)this->AddAttr(kCoordinateTransformMode, MakeValue(swi));
64 }
65
set_cubic_coeff(const float cubic_coeff)66 void Resize::set_cubic_coeff(const float cubic_coeff) { (void)this->AddAttr(kCubicCoeff, MakeValue(cubic_coeff)); }
67
set_exclude_outside(const int64_t exclude_outside)68 void Resize::set_exclude_outside(const int64_t exclude_outside) {
69 (void)this->AddAttr(kExcludeOutside, MakeValue(exclude_outside));
70 }
71
set_extrapolation_value(const float extrapolation_value)72 void Resize::set_extrapolation_value(const float extrapolation_value) {
73 (void)this->AddAttr(kExtrapolationValue, MakeValue(extrapolation_value));
74 }
75
set_nearest_mode(const NearestMode nearest_mode)76 void Resize::set_nearest_mode(const NearestMode nearest_mode) {
77 int64_t swi = (int64_t)nearest_mode;
78 (void)this->AddAttr(kNearestMode, MakeValue(swi));
79 }
80
get_format() const81 Format Resize::get_format() const {
82 auto value_ptr = GetAttr(kFormat);
83 return Format(GetValue<int64_t>(value_ptr));
84 }
85
get_method() const86 ResizeMethod Resize::get_method() const {
87 auto value_ptr = GetAttr(kMethod);
88 return ResizeMethod(GetValue<int64_t>(value_ptr));
89 }
90
get_new_height() const91 int64_t Resize::get_new_height() const {
92 auto value_ptr = GetAttr(kNewHeight);
93 return GetValue<int64_t>(value_ptr);
94 }
95
get_new_width() const96 int64_t Resize::get_new_width() const {
97 auto value_ptr = GetAttr(kNewWidth);
98 return GetValue<int64_t>(value_ptr);
99 }
get_preserve_aspect_ratio() const100 bool Resize::get_preserve_aspect_ratio() const {
101 auto value_ptr = GetAttr(kPreserveAspectRatio);
102 return GetValue<bool>(value_ptr);
103 }
get_coordinate_transform_mode() const104 CoordinateTransformMode Resize::get_coordinate_transform_mode() const {
105 auto value_ptr = GetAttr(kCoordinateTransformMode);
106 return CoordinateTransformMode(GetValue<int64_t>(value_ptr));
107 }
108
get_cubic_coeff() const109 float Resize::get_cubic_coeff() const {
110 auto value_ptr = GetAttr(kCubicCoeff);
111 return GetValue<float>(value_ptr);
112 }
113
get_exclude_outside() const114 int64_t Resize::get_exclude_outside() const {
115 auto value_ptr = GetAttr(kExcludeOutside);
116 return GetValue<int64_t>(value_ptr);
117 }
118
get_extrapolation_value() const119 float Resize::get_extrapolation_value() const {
120 auto value_ptr = GetAttr(kExtrapolationValue);
121 return GetValue<float>(value_ptr);
122 }
123
get_nearest_mode() const124 NearestMode Resize::get_nearest_mode() const {
125 auto value_ptr = GetAttr(kNearestMode);
126 return NearestMode(GetValue<int64_t>(value_ptr));
127 }
128 REGISTER_PRIMITIVE_C(kNameResize, Resize);
129 } // namespace ops
130 } // namespace mindspore
131