/** Runs inference and returns the classification results. */
        public List <Recognition> recognizeImage(Bitmap bitmap)
        {
            // Log this method so that it can be analyzed with systrace.
            Trace.BeginSection("recognizeImage");

            Trace.BeginSection("preprocessBitmap");
            convertBitmapToByteBuffer(bitmap);
            Trace.EndSection();

            // Run the inference call.
            Trace.BeginSection("runInference");
            long startTime = SystemClock.UptimeMillis();

            runInference();
            long endTime = SystemClock.UptimeMillis();

            Trace.EndSection();
            //LOGGER.v("Timecost to run model inference: " + (endTime - startTime));

            // Find the best classifications.
            Queue <Recognition> pq = new Queue <Recognition>(3);

            //new PriorityQueue<Recognition>(
            //    3,
            //new Comparator<Recognition>()
            //{
            //  // override
            //      public int compare(Recognition lhs, Recognition rhs)
            //    {
            //        // Intentionally reversed to put high confidence at the head of the queue.
            //        return Float.compare(rhs.getConfidence(), lhs.getConfidence());
            //    }
            //});
            for (int i = 0; i < labels.Count; ++i)
            {
                pq.Enqueue(
                    new Recognition(
                        "" + i,
                        labels.Count > i ? labels[i] : "unknown",
                        getNormalizedProbability(i),
                        null));
            }
            var recognitions     = new List <Recognition>();
            int recognitionsSize = Math.Min(pq.Count, MAX_RESULTS);

            for (int i = 0; i < recognitionsSize; ++i)
            {
                recognitions.Add(pq.Dequeue());
            }
            Trace.EndSection();
            return(recognitions);
        }