public static File getTFLiteAddModel() {
String root = Environment.getExternalStorageDirectory().getAbsolutePath();
File model = new File(root + "/nnstreamer/test/add.tflite");
+ File meta = new File(root + "/nnstreamer/test/metadata/MANIFEST");
- if (!model.exists()) {
+ if (!model.exists() || !meta.exists()) {
fail();
}
public void enumNNFWType() {
assertEquals(NNStreamer.NNFWType.TENSORFLOW_LITE, NNStreamer.NNFWType.valueOf("TENSORFLOW_LITE"));
assertEquals(NNStreamer.NNFWType.SNAP, NNStreamer.NNFWType.valueOf("SNAP"));
+ assertEquals(NNStreamer.NNFWType.NNFW, NNStreamer.NNFWType.valueOf("NNFW"));
assertEquals(NNStreamer.NNFWType.UNKNOWN, NNStreamer.NNFWType.valueOf("UNKNOWN"));
}
}
runSNAPCaffe(true);
}
+
+ @Test
+ public void testNNFWTFLite() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.NNFW)) {
+ /* cannot run the test */
+ return;
+ }
+
+ File model = APITestCommon.getTFLiteAddModel();
+ String desc = "appsrc name=srcx ! " +
+ "other/tensor,dimension=(string)1:1:1:1,type=(string)float32,framerate=(fraction)0/1 ! " +
+ "tensor_filter framework=nnfw model=" + model.getAbsolutePath() + " ! " +
+ "tensor_sink name=sinkx";
+
+ try (Pipeline pipe = new Pipeline(desc)) {
+ TensorsInfo info = new TensorsInfo();
+ info.addTensorInfo(NNStreamer.TensorType.FLOAT32, new int[]{1,1,1,1});
+
+ /* register sink callback */
+ pipe.registerSinkCallback("sinkx", new Pipeline.NewDataCallback() {
+ @Override
+ public void onNewDataReceived(TensorsData data) {
+ if (data == null || data.getTensorsCount() != 1) {
+ mInvalidState = true;
+ return;
+ }
+
+ ByteBuffer buffer = data.getTensorData(0);
+ float expected = buffer.getFloat(0);
+
+ /* check received data */
+ if (expected != 3.5f) {
+ mInvalidState = true;
+ }
+
+ mReceived++;
+ }
+ });
+
+ /* start pipeline */
+ pipe.start();
+
+ /* push input buffer */
+ TensorsData input = info.allocate();
+
+ ByteBuffer buffer = input.getTensorData(0);
+ buffer.putFloat(0, 1.5f);
+
+ input.setTensorData(0, buffer);
+
+ pipe.inputData("srcx", input);
+
+ /* sleep 1000 to invoke */
+ Thread.sleep(1000);
+
+ /* check received data from sink */
+ assertFalse(mInvalidState);
+ assertTrue(mReceived > 0);
+ } catch (Exception e) {
+ fail();
+ }
+ }
}
import org.junit.runner.RunWith;
import java.io.File;
+import java.nio.ByteBuffer;
import static org.junit.Assert.*;
runSNAPCaffe(true);
}
+
+ @Test
+ public void testNNFWTFLite() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.NNFW)) {
+ /* cannot run the test */
+ return;
+ }
+
+ try {
+ File model = APITestCommon.getTFLiteAddModel();
+
+ SingleShot single = new SingleShot(model, NNStreamer.NNFWType.NNFW);
+ TensorsInfo in = single.getInputInfo();
+
+ /* let's ignore timeout (set 60 sec) */
+ single.setTimeout(60000);
+
+ /* single-shot invoke */
+ for (int i = 0; i < 5; i++) {
+ /* input data */
+ TensorsData input = in.allocate();
+
+ ByteBuffer buffer = input.getTensorData(0);
+ buffer.putFloat(0, i + 1.5f);
+
+ input.setTensorData(0, buffer);
+
+ /* invoke */
+ TensorsData output = single.invoke(input);
+
+ /* check output */
+ float expected = i + 3.5f;
+ assertTrue(expected == output.getTensorData(0).getFloat(0));
+
+ Thread.sleep(30);
+ }
+
+ single.close();
+ } catch (Exception e) {
+ fail();
+ }
+ }
}