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 #include "minddata/dataset/kernels/image/slice_patches_op.h"
17 #include "minddata/dataset/kernels/image/image_utils.h"
18 #include "minddata/dataset/util/status.h"
19
20 namespace mindspore {
21 namespace dataset {
22 const int32_t SlicePatchesOp::kDefNumH = 1;
23 const int32_t SlicePatchesOp::kDefNumW = 1;
24 const uint8_t SlicePatchesOp::kDefFillV = 0;
25 const SliceMode SlicePatchesOp::kDefSliceMode = SliceMode::kPad;
26
SlicePatchesOp(int32_t num_height,int32_t num_width,SliceMode slice_mode,uint8_t fill_value)27 SlicePatchesOp::SlicePatchesOp(int32_t num_height, int32_t num_width, SliceMode slice_mode, uint8_t fill_value)
28 : num_height_(num_height), num_width_(num_width), slice_mode_(slice_mode), fill_value_(fill_value) {}
29
Compute(const TensorRow & input,TensorRow * output)30 Status SlicePatchesOp::Compute(const TensorRow &input, TensorRow *output) {
31 IO_CHECK_VECTOR(input, output);
32 CHECK_FAIL_RETURN_UNEXPECTED(input.size() == 1, "Input tensor size should be 1.");
33
34 auto in_tensor = input[0];
35 auto in_type = in_tensor->type();
36 auto in_shape = in_tensor->shape();
37
38 CHECK_FAIL_RETURN_UNEXPECTED(in_type.IsNumeric(), "Input Tensor type should be numeric.");
39 CHECK_FAIL_RETURN_UNEXPECTED(in_shape.Rank() >= 2, "Input Tensor rank should be greater than 2.");
40
41 std::vector<std::shared_ptr<Tensor>> out;
42 RETURN_IF_NOT_OK(SlicePatches(in_tensor, &out, num_height_, num_width_, slice_mode_, fill_value_));
43 (void)std::copy(out.begin(), out.end(), std::back_inserter(*output));
44 return Status::OK();
45 }
46 } // namespace dataset
47 } // namespace mindspore
48