Ejemplo n.º 1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var jsonArray   = JArray.Load(reader);
            var firstDim    = jsonArray.Count;
            var secondArray = jsonArray[0] as JArray;
            var secondDim   = secondArray?.Count;
            var thirdArray  = secondArray?[0] as JArray;
            var thirdDim    = thirdArray?.Count;
            var fourArray   = thirdArray?[0] as JArray;
            var fourDim     = fourArray?.Count;

            if (secondDim == null || thirdDim == null || fourDim == null)
            {
                return(null);
            }

            var netArray = new NoLohArray4D <float>(firstDim, secondDim.Value, thirdDim.Value, fourDim.Value);

            for (int x = 0; x < firstDim; x++)
            {
                secondArray = jsonArray[x] as JArray;
                if (secondArray == null)
                {
                    throw new Exception("The json is malformed");
                }
                for (int y = 0; y < secondDim; y++)
                {
                    thirdArray = secondArray[y] as JArray;
                    if (thirdArray == null)
                    {
                        throw new Exception("The json is malformed");
                    }
                    for (int z = 0; z < thirdDim; z++)
                    {
                        fourArray = thirdArray[z] as JArray;
                        if (fourArray == null)
                        {
                            throw new Exception("The json is malformed");
                        }
                        for (int w = 0; w < fourDim; w++)
                        {
                            netArray[x, y, z, w] = fourArray[w].Value <float>();
                        }
                    }
                }
            }
            return(netArray);
        }
Ejemplo n.º 2
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);
                }
        }
Ejemplo n.º 3
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]));
                    }