public Result[] GetResults() { // Name alias float[,,] scores = outputs0; float[,,] offsets = outputs1; float stride = scores.GetLength(0) - 1; ApplySigmoid(scores); var argmax = ArgMax2D(scores); // Add offsets for (int part = 0; part < results.Length; part++) { ArgMaxResult arg = argmax[part]; Result res = results[part]; float offsetX = offsets[arg.y, arg.x, part * 2]; float offsetY = offsets[arg.y, arg.x, part * 2 + 1]; res.x = ((float)arg.x / stride * width + offsetX) / width; res.y = ((float)arg.y / stride * height + offsetY) / height; res.confidence = arg.score; res.part = (Part)part; results[part] = res; } return(results); }
static ArgMaxResult[] ArgMax2D(float[,,] scores) { int rows = scores.GetLength(0); //y int cols = scores.GetLength(1); //x int parts = scores.GetLength(2); // Init with minimum float if (argMaxResults == null) { argMaxResults = new ArgMaxResult[parts]; } for (int i = 0; i < parts; i++) { argMaxResults[i].score = float.MinValue; } // ArgMax for (int y = 0; y < rows; y++) { for (int x = 0; x < cols; x++) { for (int part = 0; part < parts; part++) { float current = scores[y, x, part]; if (current > argMaxResults[part].score) { argMaxResults[part] = new ArgMaxResult() { x = x, y = y, score = current, }; } } } } return(argMaxResults); }