Exemplo n.º 1
0
            public void OnResult(Java.Lang.Object result)
            {
                EventReadAdapter.CalendarInfo[] calendars = result.ToArray <EventReadAdapter.CalendarInfo> ();
                string[] calendarIDs = new string[calendars.Length];
                for (int i = 0; i < calendars.Length; i++)
                {
                    calendarIDs [i] = calendars [i].Id;
                }

                adapter.EventsQueryToken = EventQueryToken.GetCalendarsById(calendarIDs);
                adapter.ReadEventsAsync();
            }
Exemplo n.º 2
0
        public List <ImageClassificationModel> Classify(byte[] image)
        {
            MappedByteBuffer mappedByteBuffer = GetModelAsMappedByteBuffer();

            // TODO: Find a solution that is not being deprecated.
            Xamarin.TensorFlow.Lite.Interpreter interpreter = new Xamarin.TensorFlow.Lite.Interpreter(mappedByteBuffer);

            //To resize the image, we first need to get its required width and height
            Xamarin.TensorFlow.Lite.Tensor tensor = interpreter.GetInputTensor(0);
            int[] shape = tensor.Shape();

            int width  = shape[1];
            int height = shape[2];

            ByteBuffer byteBuffer = GetPhotoAsByteBuffer(image, width, height);

            //use StreamReader to import the labels from labels.txt
            StreamReader streamReader = new StreamReader(Application.Context.Assets.Open("labels.txt"));

            //Transform labels.txt into List<string>
            List <string> labels = streamReader.ReadToEnd().Split('\n').Select(s => s.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToList();

            //Convert our two-dimensional array into a Java.Lang.Object, the required input for Xamarin.TensorFlow.List.Interpreter
            float[][]        outputLocations = new float[1][] { new float[labels.Count] };
            Java.Lang.Object outputs         = Java.Lang.Object.FromArray(outputLocations);

            interpreter.Run(byteBuffer, outputs);
            float[][] classificationResult = outputs.ToArray <float[]>();

            //Map the classificationResult to the labels and sort the result to find which label has the highest probability
            List <ImageClassificationModel> classificationModelList = new List <ImageClassificationModel>();

            for (int i = 0; i < labels.Count; i++)
            {
                string label = labels[i]; classificationModelList.Add(new ImageClassificationModel(label, classificationResult[0][i]));
            }

            return(classificationModelList);
        }
Exemplo n.º 3
0
 int IArrayAdapterInterface.GetArrayLength(Java.Lang.Object p0)
 {
     return(GetArrayLength(p0.ToArray <byte>()));
 }
Exemplo n.º 4
0
 public virtual unsafe bool Handles(Java.Lang.Object model)
 {
     return(Handles(model?.ToArray <byte>()));
 }
Exemplo n.º 5
0
 public virtual unsafe Model.ModelLoaderLoadData BuildLoadData(Java.Lang.Object model, int width, int height, Load.Options options)
 {
     return(BuildLoadData(model?.ToArray <byte>(), width, height, options));
 }
Exemplo n.º 6
0
 protected override void Free(Java.Lang.Object obj)
 {
     Free(obj.ToArray <byte>());
 }
Exemplo n.º 7
0
 protected override int GetBucketedSizeForValue(Java.Lang.Object obj)
 {
     return(GetBucketedSizeForValue(obj.ToArray <byte>()));
 }