package be.iminds.iot.dianne.tensor.util;

import org.junit.Test;

import be.iminds.iot.dianne.tensor.TensorFactory;
import be.iminds.iot.dianne.tensor.impl.java.JavaTensorFactory;

public class ImageConverterTest {
	
	private TensorFactory factory = new JavaTensorFactory();

	@Test
	public void testImageNetImages() {
		ImageConverter conv = new ImageConverter(factory);
		long t1 = System.currentTimeMillis();
		int start = 0;
		int n = 50000;
		for(int i=start;i<start+n;i++){
			String dir = "../tools/datasets/ImageNet/";
			String file = dir + "images/" + "ILSVRC2012_val_"
					+ String.format("%08d", i+1) + ".JPEG";
			try {
				conv.readFromFile(file);
			} catch(Exception e){
				System.out.println("Error with image "+file);
				e.printStackTrace();
			}
		}
		long t2 = System.currentTimeMillis();
		System.out.println("Avg read time: "+(t2-t1)/n+" ms");
	}
	
}

@@ -60,16 +60,59 @@
 .Test;%0A%0A
+import be.iminds.iot.dianne.tensor.Tensor;%0A
 import b
@@ -911,10 +911,357 @@
 );%0A%09%7D%0A%09%0A
+%09@Test%0A%09public void testReadWriteImage() throws Exception %7B%0A%09%09ImageConverter conv = new ImageConverter(factory);%0A%0A%09%09int i = 0;%0A%09%09String dir = %22../tools/datasets/ImageNet/%22;%0A%09%09String file = dir + %22images/%22 + %22ILSVRC2012_val_%22%0A%09%09%09%09+ String.format(%22%2508d%22, i+1) + %22.JPEG%22;%0A%09%0A%09%09Tensor t = conv.readFromFile(file);%0A%09%09conv.writeToFile(%22test.jpg%22, t);%0A%09%7D%0A
 %7D%0A

add simple test in tensor.util to read/write an image