Skip to content

Commit

Permalink
Reimplement (Fast)ResizeCropMirror in terms of Resize. Remove dead co…
Browse files Browse the repository at this point in the history
…de. (#5123)

* Remove old implementation
* Implement ResizeCropMirror in terms of Resize
    * calculate resize params
    * adjust ROI to only resize the cropped part
    * adjust ROI to accommodate flipping
* Extend mirror argument to handle other axes
* Extend to 3D, videos and CHW layout (this comes naturally from ResizeBase, ResizeAttr and CropAttr, all of which support these).
* Make FastResizeCropMirror an alias for ResizeCropMirror (just disable antialiasing to make it fast and backwards compatible)
* Fix classification of ResizeCropMirror in eager mode (it's not stateful and never was)
* Add python tests
     * tests vs separate operators (resize, crop mirror)
     * tests where there are two sources of flipping (mirror parameter & swapped RoI ends).
* Remove fast_resize_crop_mirror from eager op tests, because it's deprecated and no eager wrapper is generated for it.

---------

Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
  • Loading branch information
mzient committed Oct 31, 2023
1 parent b38bd6d commit 2bc5dbf
Show file tree
Hide file tree
Showing 15 changed files with 317 additions and 651 deletions.
5 changes: 3 additions & 2 deletions dali/benchmark/caffe_alexnet_bench.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2017-2023, NVIDIA CORPORATION & AFFILIATES. 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.
Expand Down Expand Up @@ -78,11 +78,12 @@ BENCHMARK_DEFINE_F(Alexnet, CaffePipe)(benchmark::State& st) { // NOLINT

// Add a resize+crop+mirror op
pipe.AddOperator(
OpSpec("FastResizeCropMirror")
OpSpec("ResizeCropMirror")
.AddArg("device", "cpu")
.AddArg("resize_x", 256)
.AddArg("resize_y", 256)
.AddArg("crop", vector<float>{224, 224})
.AddArg("antialias", false)
.AddInput("images", "cpu")
.AddArgumentInput("crop_pos_x", "uniform1")
.AddArgumentInput("crop_pos_y", "uniform2")
Expand Down
6 changes: 3 additions & 3 deletions dali/fuzzing/dali_harness.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2020-2023, NVIDIA CORPORATION & AFFILIATES. 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.
Expand Down Expand Up @@ -142,13 +142,13 @@ class ResNetHarness : public FileListHarness {
.AddArg("probability", 0.5f)
.AddOutput("mirror", "cpu"));

std::string resize_op = "FastResizeCropMirror";
// Add a resize+crop+mirror op
pipeline.AddOperator(
OpSpec(resize_op)
OpSpec("ResizeCropMirror")
.AddArg("device", "cpu")
.AddArg("crop", vector<float>{224, 224})
.AddInput("images", "cpu")
.AddArg("antialias", false)
.AddArgumentInput("mirror", "mirror")
.AddArgumentInput("crop_pos_x", "uniform1")
.AddArgumentInput("crop_pos_y", "uniform2")
Expand Down
217 changes: 0 additions & 217 deletions dali/image/transform.cc

This file was deleted.

78 changes: 0 additions & 78 deletions dali/image/transform.h

This file was deleted.

3 changes: 1 addition & 2 deletions dali/operators/image/crop/crop.cu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
// Copyright (c) 2019-2023, NVIDIA CORPORATION & AFFILIATES. 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.
Expand All @@ -13,7 +13,6 @@
// limitations under the License.

#include <vector>
#include "dali/image/transform.h"
#include "dali/kernels/slice/slice_gpu.cuh"
#include "dali/core/static_switch.h"
#include "dali/operators/image/crop/crop.h"
Expand Down
3 changes: 1 addition & 2 deletions dali/operators/image/resize/resize.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2017-2023, NVIDIA CORPORATION & AFFILIATES. 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.
Expand Down Expand Up @@ -41,7 +41,6 @@ Resize<Backend>::Resize(const OpSpec &spec)
: StatelessOperator<Backend>(spec)
, ResizeBase<Backend>(spec) {
save_attrs_ = this->spec_.HasArgument("save_attrs");
resample_params_.resize(num_threads_);
InitializeBackend();
}

Expand Down
7 changes: 1 addition & 6 deletions dali/operators/image/resize/resize.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright (c) 2017-2023, NVIDIA CORPORATION & AFFILIATES. 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.
Expand All @@ -23,18 +23,13 @@
#include "dali/pipeline/operator/common.h"
#include "dali/core/error_handling.h"
#include "dali/pipeline/operator/checkpointing/stateless_operator.h"
#include "dali/operators/image/resize/resize_crop_mirror.h"
#include "dali/operators/image/resize/resize_base.h"
#include "dali/operators/image/resize/resize_attr.h"
#include "dali/kernels/context.h"
#include "dali/kernels/scratch.h"
#include "dali/kernels/imgproc/resample/params.h"

namespace dali {
namespace detail {
kernels::ResamplingParams2D GetResamplingParams(
const TransformMeta &meta, kernels::FilterDesc min_filter, kernels::FilterDesc mag_filter);
} // namespace detail

template <typename Backend>
class Resize : public StatelessOperator<Backend>
Expand Down
Loading

0 comments on commit 2bc5dbf

Please sign in to comment.