ImageSparkTransform { public Base64NDArrayBody toArray(SingleImageRecord record) throws IOException { ImageWritable record2 = imageTransformProcess.transformFileUriToInput(record.getUri()); INDArray finalRecord = imageTransformProcess.executeArray(record2); return new Base64NDArrayBody(Nd4jBase64.base64String(finalRecord)); }  Base64NDArrayBody toArray(SingleImageRecord record); Base64NDArrayBody toArray(BatchImageRecord batch);  }
@Test public void testSingleImageSparkTransform() throws Exception { int seed = 12345; File f1 = new ClassPathResource("/testimages/class1/A.jpg").getFile(); SingleImageRecord imgRecord = new SingleImageRecord(f1.toURI()); ImageTransformProcess imgTransformProcess = new ImageTransformProcess.Builder().seed(seed) .scaleImageTransform(10).cropImageTransform(5).build(); ImageSparkTransform imgSparkTransform = new ImageSparkTransform(imgTransformProcess); Base64NDArrayBody body = imgSparkTransform.toArray(imgRecord); INDArray fromBase64 = Nd4jBase64.fromBase64(body.getNdarray()); System.out.println("Base 64ed array " + fromBase64); assertEquals(1, fromBase64.size(0)); }
@Test public void testBatchImageSparkTransform() throws Exception { int seed = 12345; File f0 = new ClassPathResource("/testimages/class1/A.jpg").getFile(); File f1 = new ClassPathResource("/testimages/class1/B.png").getFile(); File f2 = new ClassPathResource("/testimages/class1/C.jpg").getFile(); BatchImageRecord batch = new BatchImageRecord(); batch.add(f0.toURI()); batch.add(f1.toURI()); batch.add(f2.toURI()); ImageTransformProcess imgTransformProcess = new ImageTransformProcess.Builder().seed(seed) .scaleImageTransform(10).cropImageTransform(5).build(); ImageSparkTransform imgSparkTransform = new ImageSparkTransform(imgTransformProcess); Base64NDArrayBody body = imgSparkTransform.toArray(batch); INDArray fromBase64 = Nd4jBase64.fromBase64(body.getNdarray()); System.out.println("Base 64ed array " + fromBase64); assertEquals(3, fromBase64.size(0)); }