Skip to content

Commit

Permalink
update paddleOCR (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
lanking520 authored Mar 26, 2021
1 parent 04baa15 commit 7f66ab1
Showing 1 changed file with 5 additions and 10 deletions.
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;
return new int[] {32, width};
}
}

0 comments on commit 7f66ab1

Please sign in to comment.