public async Task <ArcFaceOutput> EvaluateAsync(ArcFaceInput input) { binding.Bind("data", input.data); var result = await session.EvaluateAsync(binding, "0"); var output = new ArcFaceOutput(); output.fc1 = result.Outputs["fc1"] as TensorFloat; return(output); }
private async Task <List <float> > ArcFace(SoftwareBitmap softwareBitmap) { // Encapsulate the image within a VideoFrame to be bound and evaluated VideoFrame inputImage = VideoFrame.CreateWithSoftwareBitmap(softwareBitmap); int height = inputImage.SoftwareBitmap.PixelHeight; int width = inputImage.SoftwareBitmap.PixelWidth; float[] data = new float[1 * 3 * ARC_FACE_INPUT * ARC_FACE_INPUT]; byte[] imageBytes = new byte[4 * height * width]; inputImage.SoftwareBitmap.CopyToBuffer(imageBytes.AsBuffer()); int id = 0; for (int i = 0; i < data.Length; i += 4) { float blue = (float)imageBytes[i]; float green = (float)imageBytes[i + 1]; float red = (float)imageBytes[i + 2]; data[id++] = blue; data[id++] = green; data[id++] = red; } _arcFaceInput.data = TensorFloat.CreateFromArray(new List <long> { 1, 3, ARC_FACE_INPUT, ARC_FACE_INPUT }, data); // Process the frame with the model _arcFaceOutput = await _arcFaceModel.EvaluateAsync(_arcFaceInput); IReadOnlyList <float> vectorImage = _arcFaceOutput.fc1.GetAsVectorView(); return(vectorImage.ToList()); }