Release 9.0.0.16564
[platform/core/csapi/tizenfx.git] / test / Tizen.MachineLearning.Inference.Test / SingleTest.cs
1 using System;
2 using System.IO;
3 using System.Text;
4 using System.Threading.Tasks;
5 using Tizen.MachineLearning.Inference;
6
7 namespace Tizen.MachineLearning.Inference.Test
8 {
9     class SingleShotTest
10     {
11         const string TAG = "ML.Inference.Test";
12         private static string ResourcePath = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
13
14         public static bool BasicSingleTest_Success00()
15         {
16             byte[] in_buffer = new byte[3 * 224 * 224 * 1];
17             byte[] out_buffer;
18             string model_path = ResourcePath + "models/mobilenet_v1_1.0_224_quant.tflite";
19
20             TensorsInfo in_info;
21             TensorsInfo out_info;
22             TensorsData in_data;
23             TensorsData out_data;
24
25             /* Set input & output TensorsInfo */
26             in_info = new TensorsInfo();
27             in_info.AddTensorInfo(TensorType.UInt8, new int[4] { 3, 224, 224, 1 });
28
29             out_info = new TensorsInfo();
30             out_info.AddTensorInfo(TensorType.UInt8, new int[4] { 1001, 1, 1, 1 });
31
32             /* Create single inference engine */
33             SingleShot single = new SingleShot(model_path, in_info, out_info);
34
35             /* Set input data */
36             in_data = in_info.GetTensorsData();
37             in_data.SetTensorData(0, in_buffer);
38
39             /* Single shot invoke */
40             out_data = single.Invoke(in_data);
41
42             /* Get output data from TensorsData */
43             out_buffer = out_data.GetTensorData(0);
44
45             /* Release Single inference instance */
46             single.Dispose();
47
48             /* clean up */
49             in_data.Dispose();
50             out_data.Dispose();
51             in_info.Dispose();
52             out_info.Dispose();
53
54             return true;
55         }
56     }
57 }