Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions core/src/ops/nn/resize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub enum CoordTransformer {
Asymmetric,
PytorchHalfPixel,
HalfPixelSymmetric,
TfHalfPixelForNn,
}

impl CoordTransformer {
Expand Down Expand Up @@ -37,6 +38,7 @@ impl CoordTransformer {
let offset = len_in as f32 / 2.0 * (1.0 - adjustment);
offset + (x_out as f32 + 0.5) / scale - 0.5
}
CoordTransformer::TfHalfPixelForNn => (x_out as f32 + 0.5) / scale,
}
}

Expand All @@ -47,6 +49,7 @@ impl CoordTransformer {
CoordTransformer::Asymmetric => "asymmetric",
CoordTransformer::PytorchHalfPixel => "pytorch_half_pixel",
CoordTransformer::HalfPixelSymmetric => "half_pixel_symmetric",
CoordTransformer::TfHalfPixelForNn => "tf_half_pixel_for_nn",
}
}

Expand All @@ -57,6 +60,7 @@ impl CoordTransformer {
"asymmetric" => CoordTransformer::Asymmetric,
"pytorch_half_pixel" => CoordTransformer::PytorchHalfPixel,
"half_pixel_symmetric" => CoordTransformer::HalfPixelSymmetric,
"tf_half_pixel_for_nn" => CoordTransformer::TfHalfPixelForNn,
s => bail!("coordinate_transformation_mode: {s}"),
})
}
Expand Down Expand Up @@ -466,12 +470,14 @@ impl TypedOp for Resize {
}
}

/// An axis length to build a probe plan on. `HalfPixel` and `Asymmetric` map
/// coordinates without consulting the axis lengths, so a symbolic axis can
/// still be probed on a stand-in; the others cannot.
/// An axis length to build a probe plan on. `HalfPixel`, `Asymmetric` and
/// `TfHalfPixelForNn` map coordinates without consulting the axis lengths, so a
/// symbolic axis can still be probed on a stand-in; the others cannot.
pub fn probe_length(coord_transformer: &CoordTransformer, len: &TDim) -> Option<usize> {
len.to_usize().ok().or(match coord_transformer {
CoordTransformer::HalfPixel | CoordTransformer::Asymmetric => Some(4),
CoordTransformer::HalfPixel
| CoordTransformer::Asymmetric
| CoordTransformer::TfHalfPixelForNn => Some(4),
_ => None,
})
}
Expand Down
3 changes: 2 additions & 1 deletion onnx/src/ops/resize.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::model::ParsingContext;
use crate::pb::*;
use tract_hir::internal::*;
use tract_nnef::tract_core::ops::nn::resize::Interpolator;
use tract_nnef::tract_core::ops::nn::resize::{CoordTransformer, Interpolator};
use tract_nnef::tract_num_traits::Zero as _;
use tract_onnx_opl::resize::{AspectRatio, CoordTransform, Nearest, Resize};

Expand All @@ -21,6 +21,7 @@ pub fn resize(

fn resize_10(node: &NodeProto) -> TractResult<Resize> {
Ok(Resize {
coord_transformer: CoordTransform::Plain(CoordTransformer::Asymmetric),
optional_roi_input: None,
optional_scales_input: Some(1),
optional_sizes_input: None,
Expand Down
4 changes: 4 additions & 0 deletions test-rt/suite-onnx/node.txt
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ test_reshape_reordered_dims
test_reshape_reordered_last_dims input:data
test_reshape_zero_and_negative_dim input:data
test_reshape_zero_dim input:data
test_resize_upsample_nearest input:X since:11
test_resize_upsample_sizes_nearest_ceil_half_pixel input:X since:12
test_resize_upsample_sizes_nearest_floor_align_corners input:X since:12
test_resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric input:X since:12
test_resize.* input:X
test_rnn_seq_length
test_round
Expand Down
Loading