public async Task GetResponse_WhenAMessageIsSent()
        {
            const int width  = 615;
            const int height = 384;

            float[,,] normalizedValues;
            PNetResponseDto expectedPNetResponse;

            var image = await BaseImage
                        .CreateAsync("ServiceBusBridge/Tensorflow/Evaluation/Resources/image_020_1.jpg")
                        .ConfigureAwait(false);

            using (var rgbValues = image.ToColorPixelsArray(width, height))
            {
                normalizedValues = rgbValues.NormalizeBatch();
            }
            using (var streamReader = File.OpenText("ServiceBusBridge/Tensorflow/Evaluation/Resources/PNetResponse.json"))
            {
                string json = await streamReader.ReadToEndAsync().ConfigureAwait(false);

                expectedPNetResponse = JsonConvert.DeserializeObject <PNetResponseDto>(json);
            }
            using (var rpcClient = new PNetClient("localhost"))
            {
                var response = await rpcClient.SendAsync(new PNetRequestDto(normalizedValues, LoadWeightsMode.FromJson, "/facerec/Tests/PNet.json")).ConfigureAwait(false);

                response.IsSuccess.Should().BeTrue();
                response.ErrorMessage.Should().BeEmpty();
                response.OutputValues.Count().Should().Be(expectedPNetResponse.OutputValues.Count());
                foreach (var outputValue in response.OutputValues)
                {
                    var expectedOutputValue = expectedPNetResponse.OutputValues.SingleOrDefault(v => v.Name == outputValue.Name);
                    expectedOutputValue.Should().NotBeNull();
                    outputValue.Value.GetLength(0).Should().Be(expectedOutputValue.Value.GetLength(0));
                    outputValue.Value.GetLength(1).Should().Be(expectedOutputValue.Value.GetLength(1));
                    outputValue.Value.GetLength(2).Should().Be(expectedOutputValue.Value.GetLength(2));
                    outputValue.Value.GetLength(3).Should().Be(expectedOutputValue.Value.GetLength(3));
                    for (int c = 0; c < outputValue.Value.GetLength(0); c++)
                    {
                        for (int x = 0; x < outputValue.Value.GetLength(1); x++)
                        {
                            for (int y = 0; y < outputValue.Value.GetLength(2); y++)
                            {
                                for (int z = 0; z < outputValue.Value.GetLength(3); z++)
                                {
                                    (outputValue.Value[c, x, y, z] - outputValue.Value[c, x, y, z]).Should()
                                    .BeLessOrEqualTo(Bootstrapper.FloatTolerance);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        public async Task GivenIHaveAnImage_WhenIUseItWithTheMtcnnAlgorithm_ThenFaceLocationAndLandmarksAreReturned()
        {
            using (var testImage = new TestResource(GetType().Assembly, "FaceRecognition.UnitTests.FaceDetections.Algorithms.Resources.image_020_1.jpg"))
            {
                var image = await BaseImage.CreateAsync(testImage.ResourcePath).ConfigureAwait(false);

                var mtcnnAlgorithm = new Mtcnn();

                await mtcnnAlgorithm.LocateFacesAsync(image).ConfigureAwait(false);
            }
        }
Exemple #3
0
        public async Task GivenIHaveAnImage_WhenIConvertItToPixelsArray_RgbValuesAreReturnedInTheArray()
        {
            using (var testImage = new TestResource(GetType().Assembly, "FaceRecognition.UnitTests.Images.Resources.Anthony_Hopkins_0001.jpg"))
            {
                var image = await BaseImage.CreateAsync(testImage.ResourcePath).ConfigureAwait(false);

                using (var rgbPixels = image.ToColorPixelsArray(4, 4))
                {
                    rgbPixels.XLength.Should().Be(4);
                    rgbPixels.YLength.Should().Be(4);
                    rgbPixels.ZLength.Should().Be(3);
                }
            }
        }
Exemple #4
0
        public async Task GenerateNormalizedBatchArray_WhenAnRgbImageIsSupplied()
        {
            await Task.CompletedTask.ConfigureAwait(false);

            const int width  = 615;
            const int height = 384;

            float[,,] normalizedValues;
            float[,,] expectedValues;

            var image = await BaseImage.CreateAsync("Domain/Helpers/Resources/image_020_1.jpg", copyToFileServer : true).ConfigureAwait(false);

            using (var rgbValues = image.ToColorPixelsArray(width, height))
            {
                normalizedValues = rgbValues.NormalizeBatch();
            }
            using (var sReader = File.OpenText("Domain/Helpers/Resources/NormalizedImageValues.json"))
            {
                var json = await sReader.ReadToEndAsync().ConfigureAwait(false);

                expectedValues = JsonConvert.DeserializeObject <float[, , ]>(json);
            }

            normalizedValues.Should().NotBeNull();
            normalizedValues.GetLength(0).Should().Be(width);
            normalizedValues.GetLength(1).Should().Be(height);
            normalizedValues.GetLength(2).Should().Be(3);
            for (int i = 0; i < normalizedValues.GetLength(0); i++)
            {
                for (int j = 0; j < normalizedValues.GetLength(1); j++)
                {
                    for (int k = 0; k < normalizedValues.GetLength(2); k++)
                    {
                        normalizedValues[i, j, k].Should().Be(expectedValues[i, j, k]);
                    }
                }
            }
        }