示例#1
0
        /// <summary>
        /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
        /// </summary>
        /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                // release managed objects
                _infoList.Clear();
            }

            // release unmanaged objects
            if (_handle != IntPtr.Zero)
            {
                NNStreamerError ret = NNStreamerError.None;
                ret = Interop.Util.DestroyTensorsInfo(_handle);
                if (ret != NNStreamerError.None)
                {
                    Log.Error(NNStreamer.TAG, "failed to destroy TensorsInfo object");
                }
            }
            _disposed = true;
        }
示例#2
0
        /**
         * @brief get output from the tensor_sink and update the orientation
         */
        private void SinkxDataReceived(object sender, DataReceivedEventArgs args)
        {
            TensorsData data_from_sink = args.Data;

            if (data_from_sink == null)
            {
                Log.Error(TAG, "Cannot get TensorsData");
                return;
            }

            byte[] out_buffer;
            out_buffer = data_from_sink.GetTensorData(0);
            float[] output = new float[4];
            Buffer.BlockCopy(out_buffer, 0, output, 0, out_buffer.Length);

            orientation = 0;

            for (int i = 1; i < 4; ++i)
            {
                if (output[orientation] < output[i])
                {
                    orientation = i;
                }
            }

            orientation *= 3;
            if (orientation == 0)
            {
                orientation = 12;
            }
        }
示例#3
0
        /// <summary>
        /// Creates a TensorsInfo instance.
        /// </summary>
        /// <feature>http://tizen.org/feature/machine_learning.inference</feature>
        /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
        /// <since_tizen> 6 </since_tizen>
        public TensorsInfo()
        {
            NNStreamer.CheckNNStreamerSupport();

            Log.Info(NNStreamer.TAG, "TensorsInfo is created");
            _infoList = new List <TensorInfo>();
        }
示例#4
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += UnhandledException;

            try
            {
                UdpLoggerManager.Configure();
                if (!UdpLoggerManager.IsRunning)
                {
                    TizenLoggerManager.Configure();
                }

                ReactNativeApp app = new ReactNativeApp();
                app.Run(args);
            }
            catch (Exception e)
            {
                Log.Error(Tag, e.ToString());
            }
            finally
            {
                if (UdpLoggerManager.IsRunning)
                {
                    UdpLoggerManager.Terminate();
                }
            }
        }
示例#5
0
 protected override void OnCreate()
 {
     base.OnCreate();
     Log.Error(Tag, "OnCreate()...");
     Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
     ServicePointManager.DefaultConnectionLimit = 100;
     RootView.BackgroundColor = ElmSharp.Color.Transparent;
 }
示例#6
0
 static void Main(string[] args)
 {
     try
     {
         TizenLoggerManager.Configure();
         AppDomain.CurrentDomain.UnhandledException += UnhandledException;
         ReactNativeApp app = new ReactNativeApp();
         app.Run(args);
     }
     catch (Exception e)
     {
         Log.Error(Tag, e.ToString());
     }
 }
        /**
         * @brief Event when "Get result" button is clicked.
         */
        public async void CreateClicked(object sender, EventArgs args)
        {
            Button button = (Button)sender;

            InputLabel.Text = Comment;
            float[] input;
            float[] output = new float[2];

            /* Initialize the model */
            TextModel.init_model();
            /* Convert user input to float array */
            input = TextModel.SplitStr(Comment);

            if (string.IsNullOrEmpty(Comment))
            {
                Log.Warn(TAG, "User input is empty");
                /* Check wrong Input parameter */
                await DisplayAlert("Error!", "Please enter your comment", "OK");
            }
            else if (Equals(button.Text, "Single-shot"))
            {
                /*Invoke the model */
                API.Text = "Single-shot";
                output   = TextModel.invoke_mode(input);
            }
            else if (Equals(button.Text, "Pipeline"))
            {
                Log.Warn(TAG, "Unsupported API");
                await DisplayAlert("Error!", "Pipeline API will be supported soon.", "OK");
            }
            else
            {
                Log.Error(TAG, "Unknown button is pressed");
            }

            /* Show text classification resut */
            if (output[0].Equals(0) && output[1].Equals(0))
            {
                Out_neg.Text = "Invalid result";
                Out_pos.Text = "InValid result";
            }
            else
            {
                Out_neg.Text = output[0].ToString();
                Out_pos.Text = output[1].ToString();
            }
        }
示例#8
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);
        }
示例#9
0
        static void UnhandledException(object sender, UnhandledExceptionEventArgs evt)
        {
            if (evt.ExceptionObject is Exception e)
            {
                if (e.InnerException != null)
                {
                    e = e.InnerException;
                }

                Log.Error(Tag, e.Message);
                Log.Error(Tag, e.StackTrace);
            }
            else
            {
                Log.Error(Tag, "Got unhandled exception event: " + evt);
            }
        }
示例#10
0
        /// <summary>
        /// Creates a TensorsData instance based on informations of TensorsInfo
        /// </summary>
        /// <returns>TensorsData instance</returns>
        /// <feature>http://tizen.org/feature/machine_learning.inference</feature>
        /// <exception cref="ArgumentException">Thrown when the method failed due to TensorsInfo's information is invalid.</exception>
        /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
        /// <since_tizen> 6 </since_tizen>
        public TensorsData GetTensorsData()
        {
            IntPtr          tensorsData_h;
            TensorsData     retTensorData;
            NNStreamerError ret = NNStreamerError.None;

            if (_handle == IntPtr.Zero)
            {
                Log.Info(NNStreamer.TAG, "_handle is IntPtr.Zero\n" + "  GetTensorsInfoHandle() is called");
                GetTensorsInfoHandle();
            }

            ret = Interop.Util.CreateTensorsData(_handle, out tensorsData_h);
            NNStreamer.CheckException(ret, "unable to create the tensorsData object");
            Log.Info(NNStreamer.TAG, "success to CreateTensorsData()\n");

            retTensorData = TensorsData.CreateFromNativeHandle(tensorsData_h);

            return(retTensorData);
        }
        async void GetClipImage()
        {
            var imageSource  = ImageSource.FromResource("Tizen.Wearable.CircularUI.Forms.Renderer.res.circle.png", GetType().Assembly);
            var streamsource = imageSource as StreamImageSource;

            if (streamsource != null && streamsource.Stream != null)
            {
                using (var streamImage = await((IStreamImageSource)streamsource).GetStreamAsync())
                {
                    if (streamImage != null)
                    {
                        _circleImage.SetStream(streamImage);
                    }
                    else
                    {
                        TLog.Error(FormsCircularUI.Tag, $"streamImage == null ");
                    }
                }
            }
        }
示例#12
0
        /// <summary>
        /// Event when "Get result" button is clicked.
        /// </summary>
        /// <param name="sender">Instance of the object which invokes event.</param>
        /// <param name="args"> Event argument.</param>
        public async void CreateClicked(object sender, EventArgs args)
        {
            Button button = (Button)sender;

            InputLabel.Text = UserCommentEntry.Text;
            float[] input;
            float[] output = new float[2];

            /// Initialize the model
            TextModel.Init_model();
            /// Convert user input to float array
            input = TextModel.SplitStr(UserCommentEntry.Text);

            if (string.IsNullOrEmpty(UserCommentEntry.Text))
            {
                Log.Warn(TAG, "User input is empty");
                /// Check wrong Input parameter
                await DisplayAlert("Error!", "Please enter your comment", "OK");

                return;
            }
            else
            {
                /// Invoke the model
                API.Text = "Single-shot";
                output   = TextModel.Invoke_model(input);
            }

            /// Show text classification resut
            if (output[0].Equals(0) && output[1].Equals(0))
            {
                Out_neg.Text = "Invalid result";
                Out_pos.Text = "InValid result";
            }
            else
            {
                Out_neg.Text = output[0].ToString();
                Out_pos.Text = output[1].ToString();
            }
        }
示例#13
0
        /**
         * @brief Load files and make hash table
         */
        public void init_model()
        {
            string label = ResourcePath + "models/labels.txt";
            string vocab = ResourcePath + "models/vocab.txt";

            if (File.Exists(label))
            {
                /* Load label file and tokenize */
                string rawLabel = File.ReadAllText(label);
                tokenized_label = rawLabel.Split('\n');
            }
            else
            {
                Log.Error(TAG, "Label file is not exist");
            }

            if (File.Exists(vocab))
            {
                /* Load vocab file and tokenize */
                string rawVocab = File.ReadAllText(vocab);
                tokenized_vocab = rawVocab.Split('\n');

                int len = tokenized_vocab.Length;
                /* Make vocab hash table to find word fast */
                for (int i = 0; i < len - 1; i++)
                {
                    string[] words = tokenized_vocab[i].Replace("\r", "").Split(' ');
                    if (!ht.ContainsKey(words[0]))
                    {
                        ht.Add(words[0], words[1]);
                    }
                }
            }
            else
            {
                Log.Error(TAG, "Vocab file is not exist");
            }
        }
示例#14
0
        /**
         * @brief Initialize the nnstreamer pipline and manage the handles
         */
        private void init_pipeline()
        {
            string model_path           = ResourcePath + "orientation_detection.tflite";
            string pipeline_description =
                "tensor_src_tizensensor type=accelerometer framerate=10/1 ! " +
                "tensor_filter framework=tensorflow-lite model=" + model_path + " ! " +
                "tensor_sink name=sinkx sync=true";

            pipeline_handle = new Pipeline(pipeline_description);
            if (pipeline_handle == null)
            {
                Log.Error(TAG, "Cannot create pipline");
                return;
            }

            sink_handle = pipeline_handle.GetSink("sinkx");
            if (sink_handle == null)
            {
                Log.Error(TAG, "Cannot get sink handle");
                return;
            }

            sink_handle.DataReceived += SinkxDataReceived;
        }
示例#15
0
        /**
         * @brief Split the input text and convert to float array.
         */
        public float[] SplitStr(string str)
        {
            float[] float_array = new float[256];
            int     cnt, len, start, unknown, pad, value;

            start   = Int32.Parse((string)ht["<START>"]);
            pad     = Int32.Parse((string)ht["<PAD>"]);
            unknown = Int32.Parse((string)ht["<UNKNOWN>"]);

            float_array[0] = (float)start;

            /*Split words and conver to lowercase */
            string[] words = str.ToLower().Split(' ');
            len = words.Length;

            for (cnt = 1; cnt <= len; cnt++)
            {
                /* Check words and fill the float array with proper values */
                if (ht.ContainsKey(words[cnt - 1]))
                {
                    value            = Int32.Parse((string)ht[words[cnt - 1]]);
                    float_array[cnt] = (float)value;
                }
                else
                {
                    Log.Debug(TAG, "Given word is not contained.");
                    float_array[cnt] = (float)unknown;
                }
            }
            /* Remainers are filled with 0*/
            while (cnt < 256)
            {
                float_array[cnt++] = (float)pad;
            }
            return(float_array);
        }
示例#16
0
        public void Error(string message, string file = "", string func = "", int line = 0)
        {
#if PRINT_DEBUG
            Native.Error("Clock#", message, file, func, line);
#endif
        }
示例#17
0
        public void Debug(string message, string file = "", string func = "", int line = 0)
        {
#if PRINT_DEBUG
            Native.Debug("ClockDotNet", message, file, func, line);
#endif
        }
示例#18
0
 /// <summary>
 /// Creates a TensorsInfo instance.
 /// </summary>
 /// <since_tizen> 6 </since_tizen>
 public TensorsInfo()
 {
     Log.Info(NNStreamer.TAG, "TensorsInfo is created");
     _infoList = new List <TensorInfo>();
 }