コード例 #1
0
        /**
         * @brief Invoke text classification model and return result
         */
        public float[] invoke_mode(float[] input)
        {
            byte[]      in_buffer = new byte[4 * 256];
            byte[]      out_buffer;
            float[]     output = new float[2];
            TensorsInfo in_info;
            TensorsInfo out_info;
            TensorsData in_data;
            TensorsData out_data;

            string model_path = ResourcePath + "models/text_classification.tflite";

            if (!File.Exists(model_path))
            {
                Log.Error(TAG, "Model file is not exist");
                return(output);
            }

            Buffer.BlockCopy(input, 0, in_buffer, 0, in_buffer.Length);

            /* Set input & output TensorsInfo */
            in_info = new TensorsInfo();
            in_info.AddTensorInfo(TensorType.Float32, new int[4] {
                256, 1, 1, 1
            });

            out_info = new TensorsInfo();
            out_info.AddTensorInfo(TensorType.Float32, new int[4] {
                2, 1, 1, 1
            });

            /* Create single inference engine */
            SingleShot single = new SingleShot(model_path, in_info, out_info);

            /* Set input data */
            in_data = in_info.GetTensorsData();
            in_data.SetTensorData(0, in_buffer);

            /* Single shot invoke */
            out_data = single.Invoke(in_data);

            /* Get output data from TensorsData */
            out_buffer = out_data.GetTensorData(0);
            Buffer.BlockCopy(out_buffer, 0, output, 0, out_buffer.Length);

            return(output);
        }
コード例 #2
0
ファイル: SingleTest.cs プロジェクト: yunmiha/TizenFX
        public static bool BasicSingleTest_Success00()
        {
            byte[] in_buffer = new byte[3 * 224 * 224 * 1];
            byte[] out_buffer;
            string model_path = ResourcePath + "models/mobilenet_v1_1.0_224_quant.tflite";

            TensorsInfo in_info;
            TensorsInfo out_info;
            TensorsData in_data;
            TensorsData out_data;

            /* Set input & output TensorsInfo */
            in_info = new TensorsInfo();
            in_info.AddTensorInfo(TensorType.UInt8, new int[4] {
                3, 224, 224, 1
            });

            out_info = new TensorsInfo();
            out_info.AddTensorInfo(TensorType.UInt8, new int[4] {
                1001, 1, 1, 1
            });

            /* Create single inference engine */
            SingleShot single = new SingleShot(model_path, in_info, out_info);

            /* Set input data */
            in_data = in_info.GetTensorsData();
            in_data.SetTensorData(0, in_buffer);

            /* Single shot invoke */
            out_data = single.Invoke(in_data);

            /* Get output data from TensorsData */
            out_buffer = out_data.GetTensorData(0);

            /* Release Single inference instance */
            single.Dispose();

            /* clean up */
            in_data.Dispose();
            out_data.Dispose();
            in_info.Dispose();
            out_info.Dispose();

            return(true);
        }
コード例 #3
0
ファイル: TensorsInfoTest.cs プロジェクト: yunmiha/TizenFX
        public static bool BasicTensorTest_Success01()
        {
            TensorsInfo tensorsInfo;
            TensorsData tensorsData;

            int[] in_dim = new int[4] {
                10, 1, 1, 1
            };
            byte[] buffer_in = new byte[] { 17, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            byte[] buffer_out;

            tensorsInfo = new TensorsInfo();
            tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim);
            Log.Info(TAG, "Current Count: " + tensorsInfo.Count);

            tensorsData = tensorsInfo.GetTensorsData();
            tensorsData.SetTensorData(0, buffer_in);

            buffer_out = tensorsData.GetTensorData(0);

            if (buffer_in.Length != buffer_out.Length)
            {
                Log.Error(TAG, "The size of buffers is different");
                return(false);
            }

            for (int i = 0; i < buffer_in.Length; ++i)
            {
                if (buffer_in[i] != buffer_out[i])
                {
                    Log.Error(TAG, "The value of " + i.ToString() + " th element is different");
                    return(false);
                }
            }

            return(true);
        }
コード例 #4
0
ファイル: TensorsInfoTest.cs プロジェクト: yunmiha/TizenFX
        public static bool BasicTensorTest_Success02()
        {
            TensorsInfo tensorsInfo;
            TensorsData tensorsData;

            int[] in_dim = new int[4] {
                10, 1, 1, 1
            };
            byte[] buffer_in = new byte[] { 17, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            byte[] buffer_out;

            tensorsInfo = new TensorsInfo();
            tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim);

            tensorsData = tensorsInfo.GetTensorsData();
            tensorsData.SetTensorData(0, buffer_in);
            buffer_out = tensorsData.GetTensorData(0);

            if (buffer_in.Length != buffer_out.Length)
            {
                Log.Error(TAG, "The size of buffers is different");
                return(false);
            }

            for (int i = 0; i < buffer_in.Length; ++i)
            {
                if (buffer_in[i] != buffer_out[i])
                {
                    Log.Error(TAG, "The value of " + i.ToString() + " th element is different");
                    return(false);
                }
            }
            tensorsData.Dispose();

            /* Add new tensor */
            int[] in2_dim = new int[4] {
                5, 1, 1, 1
            };
            byte[] buffer_in2 = new byte[] { 10, 20, 30, 40, 50 };
            byte[] buffer_out2;


            tensorsInfo.AddTensorInfo(TensorType.UInt8, in2_dim);

            tensorsData = tensorsInfo.GetTensorsData();
            tensorsData.SetTensorData(0, buffer_in);
            buffer_out = tensorsData.GetTensorData(0);
            tensorsData.SetTensorData(1, buffer_in2);
            buffer_out2 = tensorsData.GetTensorData(1);

            if (buffer_in2.Length != buffer_out2.Length)
            {
                Log.Error(TAG, "The size of buffers is different");
                return(false);
            }

            for (int i = 0; i < buffer_in2.Length; ++i)
            {
                if (buffer_in2[i] != buffer_out2[i])
                {
                    Log.Error(TAG, "The value of " + i.ToString() + " th element is different");
                    return(false);
                }
            }

            return(true);
        }