@Test public void testBufferRealloc() throws Exception { Field f = NativeImageLoader.class.getDeclaredField("buffer"); Field m = NativeImageLoader.class.getDeclaredField("bufferMat"); f.setAccessible(true); m.setAccessible(true); File f1 = new ClassPathResource("datavec-data-image/voc/2007/JPEGImages/000005.jpg").getFile(); String f2 = new ClassPathResource("datavec-data-image/voc/2007/JPEGImages/000007.jpg").getFile().getAbsolutePath(); byte[] buffer = new byte[20*1024*1024]; Mat bufferMat = new Mat(buffer); NativeImageLoader loader = new NativeImageLoader(28, 28, 1); f.set(loader, buffer); m.set(loader, bufferMat); INDArray img1LargeBuffer = loader.asMatrix(f1); INDArray img2LargeBuffer = loader.asMatrix(f2); INDArray img1LargeBuffer2 = loader.asMatrix(f1); INDArray img1LargeBuffer3 = loader.asMatrix(f1); assertEquals(img1LargeBuffer2, img1LargeBuffer3); INDArray img2LargeBuffer2 = loader.asMatrix(f1); INDArray img2LargeBuffer3 = loader.asMatrix(f1); assertEquals(img2LargeBuffer2, img2LargeBuffer3); f.set(loader, null); INDArray img1NoBuffer1 = loader.asMatrix(f1); INDArray img1NoBuffer2 = loader.asMatrix(f1); assertEquals(img1LargeBuffer, img1NoBuffer1); assertEquals(img1LargeBuffer, img1NoBuffer2); f.set(loader, null); INDArray img2NoBuffer1 = loader.asMatrix(f2); INDArray img2NoBuffer2 = loader.asMatrix(f2); assertEquals(img2LargeBuffer, img2NoBuffer1); assertEquals(img2LargeBuffer, img2NoBuffer2); buffer = new byte[10]; bufferMat = new Mat(buffer); f.set(loader, buffer); m.set(loader, bufferMat); INDArray img1SmallBuffer1 = loader.asMatrix(f1); INDArray img1SmallBuffer2 = loader.asMatrix(f1); assertEquals(img1LargeBuffer, img1SmallBuffer1); assertEquals(img1LargeBuffer, img1SmallBuffer2); f.set(loader, buffer); m.set(loader, bufferMat); INDArray img2SmallBuffer1 = loader.asMatrix(f2); INDArray img2SmallBuffer2 = loader.asMatrix(f2); assertEquals(img2LargeBuffer, img2SmallBuffer1); assertEquals(img2LargeBuffer, img2SmallBuffer2); try(InputStream is = new FileInputStream(f1)){ byte[] temp = IOUtils.toByteArray(is); buffer = new byte[temp.length]; bufferMat = new Mat(buffer); } f.set(loader, buffer); m.set(loader, bufferMat); INDArray img1ExactBuffer = loader.asMatrix(f1); assertEquals(img1LargeBuffer, img1ExactBuffer); }
public INDArray asMatrix(String filename) throws IOException { return asMatrix(new File(filename)); }
NativeImageLoader extends BaseImageLoader { public INDArray asMatrix(String filename) throws IOException { return asMatrix(new File(filename)); } }
NativeImageLoader extends BaseImageLoader { public INDArray asMatrix(String filename) throws IOException { return asMatrix(new File(filename)); } NativeImageLoader();  NativeImageLoader(long height, long width);  NativeImageLoader(long height, long width, long channels);  NativeImageLoader(long height, long width, long channels, boolean centerCropIfNeeded);  NativeImageLoader(long height, long width, long channels, ImageTransform imageTransform);  NativeImageLoader(long height, long width, long channels, MultiPageMode mode); protected  NativeImageLoader(NativeImageLoader other); }
NativeImageLoader extends BaseImageLoader { public INDArray asMatrix(String filename) throws IOException { return asMatrix(new File(filename)); } NativeImageLoader();  NativeImageLoader(long height, long width);  NativeImageLoader(long height, long width, long channels);  NativeImageLoader(long height, long width, long channels, boolean centerCropIfNeeded);  NativeImageLoader(long height, long width, long channels, ImageTransform imageTransform);  NativeImageLoader(long height, long width, long channels, MultiPageMode mode); protected  NativeImageLoader(NativeImageLoader other); @Override String[] getAllowedFormats(); INDArray asRowVector(String filename); @Override INDArray asRowVector(File f); @Override INDArray asRowVector(InputStream is); INDArray asRowVector(Object image); INDArray asRowVector(Frame image); INDArray asRowVector(Mat image); INDArray asRowVector(org.opencv.core.Mat image); INDArray asMatrix(String filename); @Override INDArray asMatrix(File f); @Override INDArray asMatrix(File f, boolean nchw); @Override INDArray asMatrix(InputStream is); @Override INDArray asMatrix(InputStream inputStream, boolean nchw); Image asImageMatrix(String filename); @Override Image asImageMatrix(File f); @Override Image asImageMatrix(File f, boolean nchw); @Override Image asImageMatrix(InputStream is); @Override Image asImageMatrix(InputStream inputStream, boolean nchw); INDArray asMatrix(Object image); void asMatrixView(InputStream is, INDArray view); void asMatrixView(String filename, INDArray view); void asMatrixView(File f, INDArray view); void asMatrixView(Mat image, INDArray view); void asMatrixView(org.opencv.core.Mat image, INDArray view); INDArray asMatrix(Frame image); INDArray asMatrix(org.opencv.core.Mat image); INDArray asMatrix(Mat image); ImageWritable asWritable(String filename); ImageWritable asWritable(File f); INDArray asMatrix(ImageWritable writable); Frame asFrame(INDArray array); Frame asFrame(INDArray array, int dataType); Mat asMat(INDArray array); Mat asMat(INDArray array, int dataType); }
NativeImageLoader extends BaseImageLoader { public INDArray asMatrix(String filename) throws IOException { return asMatrix(new File(filename)); } NativeImageLoader();  NativeImageLoader(long height, long width);  NativeImageLoader(long height, long width, long channels);  NativeImageLoader(long height, long width, long channels, boolean centerCropIfNeeded);  NativeImageLoader(long height, long width, long channels, ImageTransform imageTransform);  NativeImageLoader(long height, long width, long channels, MultiPageMode mode); protected  NativeImageLoader(NativeImageLoader other); @Override String[] getAllowedFormats(); INDArray asRowVector(String filename); @Override INDArray asRowVector(File f); @Override INDArray asRowVector(InputStream is); INDArray asRowVector(Object image); INDArray asRowVector(Frame image); INDArray asRowVector(Mat image); INDArray asRowVector(org.opencv.core.Mat image); INDArray asMatrix(String filename); @Override INDArray asMatrix(File f); @Override INDArray asMatrix(File f, boolean nchw); @Override INDArray asMatrix(InputStream is); @Override INDArray asMatrix(InputStream inputStream, boolean nchw); Image asImageMatrix(String filename); @Override Image asImageMatrix(File f); @Override Image asImageMatrix(File f, boolean nchw); @Override Image asImageMatrix(InputStream is); @Override Image asImageMatrix(InputStream inputStream, boolean nchw); INDArray asMatrix(Object image); void asMatrixView(InputStream is, INDArray view); void asMatrixView(String filename, INDArray view); void asMatrixView(File f, INDArray view); void asMatrixView(Mat image, INDArray view); void asMatrixView(org.opencv.core.Mat image, INDArray view); INDArray asMatrix(Frame image); INDArray asMatrix(org.opencv.core.Mat image); INDArray asMatrix(Mat image); ImageWritable asWritable(String filename); ImageWritable asWritable(File f); INDArray asMatrix(ImageWritable writable); Frame asFrame(INDArray array); Frame asFrame(INDArray array, int dataType); Mat asMat(INDArray array); Mat asMat(INDArray array, int dataType); static final String[] ALLOWED_FORMATS; }