Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat center like non-center on 1x1 images when resizing using resize_bilinear #7111

Merged
merged 1 commit into from Feb 5, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions libnd4j/include/ops/declarable/helpers/cpu/image_resize.cpp
Expand Up @@ -133,6 +133,11 @@ namespace helpers {
return ND4J_STATUS_OK;
}

// Special case for TF compatibility
if((center && inHeight < 2) || (center && inWidth < 2)){
center = false;
}

if ((center && inHeight < 2) || (inHeight < 1) || (outHeight < 1) || (center && outHeight < 2) ||
(center && inWidth < 2) || (inWidth < 1) || (outWidth < 1) || (center && outWidth < 2)) {
// wrong input data
Expand Down
Expand Up @@ -10,7 +10,7 @@
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

public class TestPad {
public class CustomOpTests {

@Test
public void testPad(){
Expand All @@ -31,4 +31,22 @@ public void testPad(){

Nd4j.getExecutioner().exec(op); //Crash here
}

@Test
public void testResizeBilinearEdgeCase(){
INDArray in = Nd4j.ones(DataType.FLOAT, 1, 1, 1, 3);
INDArray size = Nd4j.createFromArray(8, 8);
INDArray out = Nd4j.create(DataType.FLOAT, 1, 8, 8, 3);

DynamicCustomOp op = DynamicCustomOp.builder("resize_bilinear")
.addInputs(in, size)
.addOutputs(out)
.addIntegerArguments(1) //1 = center. Though TF works with align_corners == false or true
.build();

Nd4j.getExecutioner().exec(op);

INDArray exp = Nd4j.ones(DataType.FLOAT, 1, 8, 8, 3);
assertEquals(exp, out);
}
}