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

fix paddleOCR size issue #775

Merged
merged 1 commit into from
Mar 26, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public String processOutput(TranslatorContext ctx, NDList list) throws IOExcepti
@Override
public NDList processInput(TranslatorContext ctx, Image input) {
NDArray img = input.toNDArray(ctx.getNDManager());
int[] hw = resize32(input.getHeight(), input.getWidth());
int[] hw = resize32(input.getWidth());
img = NDImageUtils.resize(img, hw[1], hw[0]);
img = NDImageUtils.toTensor(img).sub(0.5f).div(0.5f);
img = img.expandDims(0);
Expand All @@ -77,14 +77,9 @@ public Batchifier getBatchifier() {
return null;
}

private int[] resize32(double h, double w) {
double min = Math.min(h, w);
if (min < 32) {
h = 32.0 / min * h;
w = 32.0 / min * w;
}
int h32 = (int) h / 32;
int w32 = (int) w / 32;
return new int[] {h32 * 32, w32 * 32};
private int[] resize32(double w) {
// Paddle doesn't rely on aspect ratio
int width = ((int) Math.max(32, w)) / 32 * 32;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct. This basically keep the original width and removed the remainder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it trimmed the width to a 32 based number. The apect ratio didn't help on the inference result

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is weird, Can you add a comments here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

return new int[] {32, width};
}
}