forked from NVIDIA/DALI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Flip operator Signed-off-by: Serge Panev <spanev@nvidia.com> * Enable support arguments for Flip operator Signed-off-by: Serge Panev <spanev@nvidia.com> * Add flip operator unit test Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com> * Extend Augumentation gallery example by flip operation Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com> Signed-off-by: Andrei <andreii@nvidia.com>
- Loading branch information
Showing
7 changed files
with
137 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved. | ||
// | ||
// 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 "dali/pipeline/operators/displacement/flip.h" | ||
#include "dali/pipeline/operators/displacement/displacement_filter_impl_cpu.h" | ||
|
||
namespace dali { | ||
|
||
DALI_REGISTER_OPERATOR(Flip, Flip<CPUBackend>, CPU); | ||
|
||
DALI_SCHEMA(Flip) | ||
.DocStr("Flip the image on the horizontal and/or vertical axes.") | ||
.NumInput(1) | ||
.NumOutput(1) | ||
.AllowMultipleInputSets() | ||
.AddOptionalArg("horizontal", | ||
R"code(Perform a horizontal flip. Default value is True.)code", true, true) | ||
.AddOptionalArg("vertical", | ||
R"code(Perform a vertical flip. Default value is False.)code", false, true) | ||
.AddParent("DisplacementFilter"); | ||
|
||
} // namespace dali | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved. | ||
// | ||
// 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 "dali/pipeline/operators/displacement/flip.h" | ||
#include "dali/pipeline/operators/displacement/displacement_filter_impl_gpu.cuh" | ||
|
||
namespace dali { | ||
|
||
DALI_REGISTER_OPERATOR(Flip, Flip<GPUBackend>, GPU); | ||
|
||
} // namespace dali | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved. | ||
// | ||
// 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 DALI_PIPELINE_OPERATORS_DISPLACEMENT_FLIP_H_ | ||
#define DALI_PIPELINE_OPERATORS_DISPLACEMENT_FLIP_H_ | ||
|
||
#include <vector> | ||
#include <cmath> | ||
#include "dali/pipeline/operators/operator.h" | ||
#include "dali/pipeline/operators/displacement/warpaffine.h" | ||
|
||
namespace dali { | ||
|
||
class FlipAugment : public WarpAffineAugment { | ||
public: | ||
explicit FlipAugment(const OpSpec& spec) { | ||
use_image_center = true; | ||
} | ||
|
||
void Prepare(Param* p, const OpSpec& spec, ArgumentWorkspace *ws, int index) { | ||
float horizontal = (spec.GetArgument<bool>("horizontal", ws, index)) ? -1.0 : 1.0; | ||
float vertical = (spec.GetArgument<bool>("vertical", ws, index)) ? -1.0 : 1.0; | ||
p->matrix[0] = 1.0 * horizontal; | ||
p->matrix[1] = 0.0; | ||
p->matrix[2] = 0.0; | ||
p->matrix[3] = 0.0; | ||
p->matrix[4] = 1.0 * vertical; | ||
p->matrix[5] = 0.0; | ||
} | ||
}; | ||
|
||
template <typename Backend> | ||
class Flip : public DisplacementFilter<Backend, FlipAugment> { | ||
public: | ||
inline explicit Flip(const OpSpec &spec) | ||
: DisplacementFilter<Backend, FlipAugment>(spec) {} | ||
|
||
virtual ~Flip() = default; | ||
}; | ||
|
||
} // namespace dali | ||
|
||
#endif // DALI_PIPELINE_OPERATORS_DISPLACEMENT_FLIP_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.