!2532 adding random-resize-with-bbox-op and resize-with-bbox-op
Merge pull request !2532 from ava/NNNewMasterpull/2532/MERGE
commit
b0a10c26a4
@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "dataset/kernels/image/random_resize_with_bbox_op.h"
|
||||||
|
#include "dataset/kernels/image/resize_with_bbox_op.h"
|
||||||
|
#include "dataset/util/status.h"
|
||||||
|
|
||||||
|
namespace mindspore {
|
||||||
|
namespace dataset {
|
||||||
|
const int32_t RandomResizeWithBBoxOp::kDefTargetWidth = 0;
|
||||||
|
|
||||||
|
Status RandomResizeWithBBoxOp::Compute(const TensorRow &input, TensorRow *output) {
|
||||||
|
// Randomly selects from the following four interpolation methods
|
||||||
|
// 0-bilinear, 1-nearest_neighbor, 2-bicubic, 3-area
|
||||||
|
interpolation_ = static_cast<InterpolationMode>(distribution_(random_generator_));
|
||||||
|
RETURN_IF_NOT_OK(ResizeWithBBoxOp::Compute(input, output));
|
||||||
|
return Status::OK();
|
||||||
|
}
|
||||||
|
} // namespace dataset
|
||||||
|
} // namespace mindspore
|
@ -0,0 +1,56 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DATASET_KERNELS_IMAGE_RANDOM_RESIZE_WITH_BBOX_OP_H
|
||||||
|
#define DATASET_KERNELS_IMAGE_RANDOM_RESIZE_WITH_BBOX_OP_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
|
#include "dataset/core/tensor.h"
|
||||||
|
#include "dataset/kernels/image/resize_op.h"
|
||||||
|
#include "dataset/kernels/image/resize_with_bbox_op.h"
|
||||||
|
#include "dataset/kernels/tensor_op.h"
|
||||||
|
#include "dataset/util/random.h"
|
||||||
|
#include "dataset/util/status.h"
|
||||||
|
|
||||||
|
namespace mindspore {
|
||||||
|
namespace dataset {
|
||||||
|
class RandomResizeWithBBoxOp : public ResizeWithBBoxOp {
|
||||||
|
public:
|
||||||
|
// Default values, also used by python_bindings.cc
|
||||||
|
static const int32_t kDefTargetWidth;
|
||||||
|
explicit RandomResizeWithBBoxOp(int32_t size_1, int32_t size_2 = kDefTargetWidth) : ResizeWithBBoxOp(size_1, size_2) {
|
||||||
|
random_generator_.seed(GetSeed());
|
||||||
|
}
|
||||||
|
|
||||||
|
~RandomResizeWithBBoxOp() = default;
|
||||||
|
|
||||||
|
// Description: A function that prints info about the node
|
||||||
|
void Print(std::ostream &out) const override {
|
||||||
|
out << "RandomResizeWithBBoxOp: " << ResizeWithBBoxOp::size1_ << " " << ResizeWithBBoxOp::size2_;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status Compute(const TensorRow &input, TensorRow *output) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::mt19937 random_generator_;
|
||||||
|
std::uniform_int_distribution<int> distribution_{0, 3};
|
||||||
|
};
|
||||||
|
} // namespace dataset
|
||||||
|
} // namespace mindspore
|
||||||
|
|
||||||
|
#endif // DATASET_KERNELS_IMAGE_RANDOM_RESIZE_WITH_BBOX_OP_H
|
@ -0,0 +1,53 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "dataset/kernels/image/resize_with_bbox_op.h"
|
||||||
|
#include <utility>
|
||||||
|
#include <memory>
|
||||||
|
#include "dataset/kernels/image/resize_op.h"
|
||||||
|
#include "dataset/kernels/image/image_utils.h"
|
||||||
|
#include "dataset/core/cv_tensor.h"
|
||||||
|
#include "dataset/core/pybind_support.h"
|
||||||
|
#include "dataset/core/tensor.h"
|
||||||
|
#include "dataset/kernels/tensor_op.h"
|
||||||
|
#include "dataset/util/status.h"
|
||||||
|
|
||||||
|
namespace mindspore {
|
||||||
|
namespace dataset {
|
||||||
|
|
||||||
|
Status ResizeWithBBoxOp::Compute(const TensorRow &input, TensorRow *output) {
|
||||||
|
IO_CHECK_VECTOR(input, output);
|
||||||
|
BOUNDING_BOX_CHECK(input);
|
||||||
|
|
||||||
|
int32_t input_h = input[0]->shape()[0];
|
||||||
|
int32_t input_w = input[0]->shape()[1];
|
||||||
|
|
||||||
|
output->resize(2);
|
||||||
|
(*output)[1] = std::move(input[1]); // move boxes over to output
|
||||||
|
|
||||||
|
std::shared_ptr<CVTensor> input_cv = CVTensor::AsCVTensor(std::move(input[0]));
|
||||||
|
|
||||||
|
RETURN_IF_NOT_OK(ResizeOp::Compute(std::static_pointer_cast<Tensor>(input_cv), &(*output)[0]));
|
||||||
|
|
||||||
|
int32_t output_h = (*output)[0]->shape()[0]; // output height if ResizeWithBBox
|
||||||
|
int32_t output_w = (*output)[0]->shape()[1]; // output width if ResizeWithBBox
|
||||||
|
|
||||||
|
size_t bboxCount = input[1]->shape()[0]; // number of rows in bbox tensor
|
||||||
|
RETURN_IF_NOT_OK(UpdateBBoxesForResize((*output)[1], bboxCount, output_w, output_h, input_w, input_h));
|
||||||
|
return Status::OK();
|
||||||
|
}
|
||||||
|
} // namespace dataset
|
||||||
|
} // namespace mindspore
|
@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
#ifndef DATASET_KERNELS_IMAGE_RESIZE_WITH_BBOX_OP_H
|
||||||
|
#define DATASET_KERNELS_IMAGE_RESIZE_WITH_BBOX_OP_H
|
||||||
|
|
||||||
|
#include "dataset/core/tensor.h"
|
||||||
|
#include "dataset/kernels/image/image_utils.h"
|
||||||
|
#include "dataset/kernels/tensor_op.h"
|
||||||
|
#include "dataset/util/status.h"
|
||||||
|
#include "dataset/kernels/image/resize_op.h"
|
||||||
|
|
||||||
|
namespace mindspore {
|
||||||
|
namespace dataset {
|
||||||
|
class ResizeWithBBoxOp : public ResizeOp {
|
||||||
|
public:
|
||||||
|
// Constructor for ResizeWithBBoxOp, with default value and passing to base class constructor
|
||||||
|
explicit ResizeWithBBoxOp(int32_t size_1, int32_t size_2 = kDefWidth,
|
||||||
|
InterpolationMode mInterpolation = kDefInterpolation)
|
||||||
|
: ResizeOp(size_1, size_2, mInterpolation) {}
|
||||||
|
|
||||||
|
~ResizeWithBBoxOp() override = default;
|
||||||
|
|
||||||
|
void Print(std::ostream &out) const override { out << "ResizeWithBBoxOp: " << size1_ << " " << size2_; }
|
||||||
|
|
||||||
|
Status Compute(const TensorRow &input, TensorRow *output) override;
|
||||||
|
};
|
||||||
|
} // namespace dataset
|
||||||
|
} // namespace mindspore
|
||||||
|
|
||||||
|
#endif // DATASET_KERNELS_IMAGE_RESIZE_WITH_BBOX_OP_H
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue