You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

decode_op.cc 2.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Copyright 2019 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 "dataset/kernels/image/decode_op.h"
  17. #include "dataset/kernels/image/image_utils.h"
  18. #include "dataset/util/status.h"
  19. namespace mindspore {
  20. namespace dataset {
  21. const bool DecodeOp::kDefRgbFormat = true;
  22. DecodeOp::DecodeOp(bool is_rgb_format) : is_rgb_format_(is_rgb_format) {
  23. if (is_rgb_format_) { // RGB colour mode
  24. MS_LOG(INFO) << "Decode colour mode is RGB.";
  25. } else {
  26. MS_LOG(INFO) << "Decode colour mode is BGR.";
  27. }
  28. }
  29. Status DecodeOp::Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output) {
  30. IO_CHECK(input, output);
  31. if (is_rgb_format_) { // RGB colour mode
  32. return Decode(input, output);
  33. } else { // BGR colour mode
  34. RETURN_STATUS_UNEXPECTED("Decode BGR is deprecated");
  35. }
  36. }
  37. Status DecodeOp::OutputShape(const std::vector<TensorShape> &inputs, std::vector<TensorShape> &outputs) {
  38. RETURN_IF_NOT_OK(TensorOp::OutputShape(inputs, outputs));
  39. outputs.clear();
  40. TensorShape out({-1, -1, 3}); // we don't know what is output image size, but we know it should be 3 channels
  41. if (inputs[0].Rank() == 1) outputs.emplace_back(out);
  42. if (!outputs.empty()) return Status::OK();
  43. return Status(StatusCode::kUnexpectedError, "Input has a wrong shape");
  44. }
  45. Status DecodeOp::OutputType(const std::vector<DataType> &inputs, std::vector<DataType> &outputs) {
  46. RETURN_IF_NOT_OK(TensorOp::OutputType(inputs, outputs));
  47. outputs[0] = DataType(DataType::DE_UINT8);
  48. return Status::OK();
  49. }
  50. } // namespace dataset
  51. } // namespace mindspore