コード例 #1
0
        public void GivenIHaveTheLengthOfABigArray_WhenICreateABigArrayTest_AnInstanceIsCreated(int xLength, int yLength, int zLength,
                                                                                                int filledIndex)
        {
            var random       = new Random();
            var filledValues = new Dictionary <string, GeneratedValues>();

            for (int i = 0; i < filledIndex; i++)
            {
                var x = random.Next(xLength - 1);
                var y = random.Next(yLength - 1);
                var z = random.Next(zLength - 1);
                filledValues[$"{x},{y},{z}"] = new GeneratedValues(x, y, z, random.NextDouble());
            }

            using (var array = new NoLohArray3D <double>(xLength, yLength, zLength, true))
            {
                foreach (var item in filledValues)
                {
                    array[item.Value.X, item.Value.Y, item.Value.Z] = item.Value.Value;
                }

                foreach (var item in filledValues)
                {
                    array[item.Value.X, item.Value.Y, item.Value.Z].Should().Be(item.Value.Value);
                }
            }
        }
コード例 #2
0
        public void GivenIHaveABigArray_WhenISetAnIndexGreaterThanLength_AnExceptionIsThrow(int xLength, int yLength, int zLength,
                                                                                            int xIndex, int yIndex, int zIndex)
        {
            Action action = () =>
            {
                using (var noLohArray = new NoLohArray3D <double>(xLength, yLength, zLength))
                {
                    noLohArray[xIndex, yIndex, zIndex] = 10;
                }
            };

            action.ShouldThrow <ArgumentException>();
        }
コード例 #3
0
        public void GivenIHaveABigArray_WhenIGetANegativeIndex_AnExceptionIsThrow(int xLength, int yLength, int zLength,
                                                                                  int xIndex, int yIndex, int zIndex)
        {
            Action action = () =>
            {
                using (var noLohArray = new NoLohArray3D <double>(xLength, yLength, zLength))
                {
                    var value = noLohArray[xIndex, yIndex, zIndex];
                }
            };

            action.ShouldThrow <ArgumentException>();
        }
コード例 #4
0
        public static IEnumerable <Box> CreateFromMtcnnHeatMap(NoLohArray3D <float> probabilities, NoLohArray4D <float> heatmap, float scale, float threshold)
        {
            const float stride    = 2f;
            const float cellSize  = 12f;
            const int   zIndex    = 1;
            var         positions = new ConcurrentBag <(int X, int Y, float Score)>();

            Parallel.For(0, probabilities.XLength, x =>
            {
                for (int y = 0; y < probabilities.YLength; y++)
                {
                    if (probabilities[x, y, zIndex] > threshold)
                    {
                        positions.Add((x, y, probabilities[x, y, zIndex]));
                    }
コード例 #5
0
        public static float[,,] NormalizeBatch(this NoLohArray3D <float> image)
        {
            float[,,] normalizedBatch = new float[image.XLength, image.YLength, image.ZLength];

            Parallel.For(0, image.XLength, Bootstrapper.Instance.MaxDegreeOfParalelism, row =>
            {
                for (int column = 0; column < image.YLength; column++)
                {
                    for (int channel = 0; channel < image.ZLength; channel++)
                    {
                        normalizedBatch[row, column, channel] = (image[row, column, channel] - 127.5f) * 0.0078125f;
                    }
                }
            });
            return(normalizedBatch);
        }
コード例 #6
0
        public void ReturnBoundingBoxes_WhenAHeatmapProbabilityIsSupplied()
        {
            const float threshold = 0.7f;
            const float scale     = 0.5f;

            using (var probabilities = new NoLohArray3D <float>(50, 50, 2))
                using (var heatmap = new NoLohArray4D <float>(1, 50, 50, 4))
                {
                    probabilities[2, 4, 1] = 0.8f;
                    probabilities[4, 8, 1] = 0.9f;

                    var boxes = Box.CreateFromMtcnnHeatMap(probabilities, heatmap, scale, threshold);

                    boxes.Should().NotBeEmpty();
                    boxes.Should().HaveCount(2);
                    boxes.Should().Contain(item =>
                                           item.MinX == 8 && item.MaxX == 32 && item.MinY == 16 && item.MaxY == 40 && Math.Abs(item.Score - 0.8f) < Bootstrapper.FloatTolerance);
                    boxes.Should().Contain(item =>
                                           item.MinX == 16 && item.MaxX == 40 && item.MinY == 32 && item.MaxY == 56 && Math.Abs(item.Score - 0.9f) < Bootstrapper.FloatTolerance);
                }
        }