public T Score <T>(IScoringRequest request) where T : class
        {
            var requestGrpc = request.MakePredictRequest();
            var result      = _client.Predict(requestGrpc);

            return(result.Outputs["output_alias"].Convert <T>());
        }
Ejemplo n.º 2
0
        public async Task <T> ScoreAsync <T>(IScoringRequest request) where T : class
        {
            var predictRequest = request.MakePredictRequest();

            return(await RetryAsync(async() => {
                var result = await _client.PredictAsync(predictRequest);
                return result.Outputs["output_alias"].Convert <T>();
            }));
        }
Ejemplo n.º 3
0
        public async Task <Dictionary <string, T> > PredictAsync <T>(IScoringRequest request, int retryCount = RetryCount) where T : class
        {
            var predictRequest = request.MakePredictRequest();

            return(await RetryAsync(async() =>
            {
                var result = await _client.PredictAsync(predictRequest);
                return result.Outputs.ToDictionary(
                    kvp => kvp.Key, kvp => kvp.Value.Convert <T>());
            }, retryCount));
        }
Ejemplo n.º 4
0
        public List <ImageFeature> Process(ByteString image)
        {
            List <ImageFeature> result = new List <ImageFeature>();

            try
            {
                IScoringRequest request = null;
                float[]         offsets = new float[] { 123, 117, 104 };
                using (MemoryStream stream = new MemoryStream(image.ToByteArray()))
                    using (Bitmap bitmap = new Bitmap(stream))
                    {
                        int     width     = bitmap.Width;
                        int     height    = bitmap.Height;
                        float[] values    = new float[3 * width * height];
                        int     valuesIdx = 0;

                        for (int i = 0; i < height; i++)
                        {
                            for (int j = 0; j < width; j++)
                            {
                                var pixel = bitmap.GetPixel(j, i);
                                values[valuesIdx++] = pixel.B - offsets[0];
                                values[valuesIdx++] = pixel.G - offsets[1];
                                values[valuesIdx++] = pixel.R - offsets[2];
                            }
                        }
                        int[] shape = new int[] { 1, 300, 300, 3 };
                        Tuple <float[], int[]> tuple = new Tuple <float[], int[]>(values, shape);
                        Dictionary <string, Tuple <float[], int[]> > inputs = new Dictionary <string, Tuple <float[], int[]> >
                        {
                            { "brainwave_ssd_vgg_1_Version_0.1_input_1:0", tuple }
                        };

                        request = new FloatRequest(inputs);
                    }

                PredictResponse response = Predict(request.MakePredictRequest());
                if (response != null)
                {
                    result = FpgaPostProcess.PostProcess(response, selectThreshold: 0.5F, jaccardThreshold: 0.45F);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Failed during FPGA Pre- or Post- Process: {ex.Message}");
            }

            return(result);
        }
        public List <ImageFeature> Process(ByteString image)
        {
            List <ImageFeature> result = new List <ImageFeature>();

            try
            {
                IScoringRequest request = null;
                float[]         values  = new float[image.Length];
                int             idx     = 0;
                while (idx < image.Length)
                {
                    values[idx] = image[idx] - rRefLevel;
                    idx++;
                    values[idx] = image[idx] - gRefLevel;
                    idx++;
                    values[idx] = image[idx] - bRefLevel;
                    idx++;
                }

                int[] shape = new int[] { 1, 300, 300, 3 };
                Tuple <float[], int[]> tuple = new Tuple <float[], int[]>(values, shape);
                Dictionary <string, Tuple <float[], int[]> > inputs = new Dictionary <string, Tuple <float[], int[]> >
                {
                    { "brainwave_ssd_vgg_1_Version_0.1_input_1:0", tuple }
                };

                request = new FloatRequest(inputs);

                PredictResponse response = Predict(request.MakePredictRequest());
                if (response != null)
                {
                    result = FpgaPostProcess.PostProcess(response, selectThreshold: 0.5F, jaccardThreshold: 0.45F);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Failed during FPGA Pre- or Post- Process: {ex.Message}");
            }

            return(result);
        }
Ejemplo n.º 6
0
 public async Task <T> ScoreAsync <T>(IScoringRequest request, int retryCount = RetryCount, string output_name = "output_alias") where T : class
 {
     return((await this.PredictAsync <T>(request, retryCount))[output_name]);
 }
Ejemplo n.º 7
0
 public async Task <float[]> ScoreAsync(IScoringRequest request, int retryCount = RetryCount, string output_name = "output_alias")
 {
     return(await ScoreAsync <float[]>(request, retryCount, output_name));
 }
Ejemplo n.º 8
0
 public async Task <float[]> ScoreAsync(IScoringRequest request, int retryCount = RetryCount)
 {
     return(await ScoreAsync <float[]>(request, retryCount));
 }
Ejemplo n.º 9
0
 public async Task <float[]> ScoreAsync(IScoringRequest request)
 {
     return(await ScoreAsync <float[]>(request));
 }
 public float[] Score(IScoringRequest request)
 {
     return(Score <float[]>(request));
 }