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); }