diff --git a/paddlepaddle/paddlepaddle-model-zoo/src/main/java/ai/djl/paddlepaddle/zoo/cv/wordrecognition/PpWordRecognitionTranslator.java b/paddlepaddle/paddlepaddle-model-zoo/src/main/java/ai/djl/paddlepaddle/zoo/cv/wordrecognition/PpWordRecognitionTranslator.java index 2e52de8bc68..a9c59774608 100644 --- a/paddlepaddle/paddlepaddle-model-zoo/src/main/java/ai/djl/paddlepaddle/zoo/cv/wordrecognition/PpWordRecognitionTranslator.java +++ b/paddlepaddle/paddlepaddle-model-zoo/src/main/java/ai/djl/paddlepaddle/zoo/cv/wordrecognition/PpWordRecognitionTranslator.java @@ -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); @@ -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}; } }