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 "minddata/dataset/kernels/ir/vision/decode_ir.h" 17 18 #include "minddata/dataset/kernels/image/decode_op.h" 19 20 #include "minddata/dataset/kernels/ir/validators.h" 21 22 namespace mindspore { 23 namespace dataset { 24 namespace vision { 25 // DecodeOperation DecodeOperation(bool rgb)26DecodeOperation::DecodeOperation(bool rgb) : rgb_(rgb) {} 27 28 DecodeOperation::~DecodeOperation() = default; 29 Name() const30std::string DecodeOperation::Name() const { return kDecodeOperation; } 31 ValidateParams()32Status DecodeOperation::ValidateParams() { return Status::OK(); } 33 Build()34std::shared_ptr<TensorOp> DecodeOperation::Build() { return std::make_shared<DecodeOp>(rgb_); } 35 to_json(nlohmann::json * out_json)36Status DecodeOperation::to_json(nlohmann::json *out_json) { 37 (*out_json)["rgb"] = rgb_; 38 return Status::OK(); 39 } from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)40Status DecodeOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) { 41 CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("rgb") != op_params.end(), "Failed to find rgb"); 42 bool rgb = op_params["rgb"]; 43 *operation = std::make_shared<vision::DecodeOperation>(rgb); 44 return Status::OK(); 45 } 46 } // namespace vision 47 } // namespace dataset 48 } // namespace mindspore 49