Пример #1
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;
            }
        }
Пример #2
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();
                }
            }
        }
Пример #3
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;
        }
Пример #4
0
 protected override void OnCreate()
 {
     base.OnCreate();
     Log.Error(Tag, "OnCreate()...");
     Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
     ServicePointManager.DefaultConnectionLimit = 100;
     RootView.BackgroundColor = ElmSharp.Color.Transparent;
 }
Пример #5
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();
            }
        }
Пример #7
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);
        }
Пример #8
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);
            }
        }
        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 ");
                    }
                }
            }
        }
Пример #10
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");
            }
        }
Пример #11
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;
        }
Пример #12
0
        public void Error(string message, string file = "", string func = "", int line = 0)
        {
#if PRINT_DEBUG
            Native.Error("Clock#", message, file, func, line);
#endif
        }