public Result GetResults(float scoreThreshold = 0.5f, float iouThreshold = 0.3f) { results.Clear(); int keypointsCount = KeypointsCount; for (int i = 0; i < anchors.Length; i++) { float score = MathTF.Sigmoid(output1[i]); if (score < scoreThreshold) { continue; } SsdAnchor anchor = anchors[i]; float sx = output0[i, 0]; float sy = output0[i, 1]; float w = output0[i, 2]; float h = output0[i, 3]; float cx = sx + anchor.x * width; float cy = sy + anchor.y * height; cx /= (float)width; cy /= (float)height; w /= (float)width; h /= (float)height; var keypoints = new Vector2[keypointsCount]; for (int j = 0; j < keypointsCount; j++) { float lx = output0[i, 4 + (2 * j) + 0]; float ly = output0[i, 4 + (2 * j) + 1]; lx += anchor.x * width; ly += anchor.y * height; lx /= (float)width; ly /= (float)height; keypoints[j] = new Vector2(lx, ly); } results.Add(new Result() { score = score, rect = new Rect(cx - w * 0.5f, cy - h * 0.5f, w, h), keypoints = keypoints, }); } // No result if (results.Count == 0) { return(Result.Negative); } return(results.First()); // return NonMaxSuppression(results, iouThreshold).First(); }
public List <Result> GetResults(float scoreThreshold = 0.7f, float iouThreshold = 0.3f) { results.Clear(); for (int i = 0; i < anchors.Length; i++) { float score = MathTF.Sigmoid(output0[i]); if (score < scoreThreshold) { continue; } SsdAnchor anchor = anchors[i]; float sx = output1[i, 0]; float sy = output1[i, 1]; float w = output1[i, 2]; float h = output1[i, 3]; float cx = sx + anchor.x * width; float cy = sy + anchor.y * height; cx /= (float)width; cy /= (float)height; w /= (float)width; h /= (float)height; var keypoints = new Vector2[7]; for (int j = 0; j < 7; j++) { float lx = output1[i, 4 + (2 * j) + 0]; float ly = output1[i, 4 + (2 * j) + 1]; lx += anchor.x * width; ly += anchor.y * height; lx /= (float)width; ly /= (float)height; keypoints[j] = new Vector2(lx, ly); } results.Add(new Result() { score = score, rect = new Rect(cx - w * 0.5f, cy - h * 0.5f, w, h), keypoints = keypoints, }); //Debug.Log(ToString(keypoints)); } return(NonMaxSuppression(results, iouThreshold)); }
static void ApplySigmoid(float[,,] arr) { int rows = arr.GetLength(0); // y int cols = arr.GetLength(1); // x int parts = arr.GetLength(2); // simgoid to get score for (int y = 0; y < rows; y++) { for (int x = 0; x < cols; x++) { for (int part = 0; part < parts; part++) { arr[y, x, part] = MathTF.Sigmoid(arr[y, x, part]); } } } }
public static void ApplyToRectTransform(Matrix4x4 mtx, RectTransform t) { mtx = POP_MATRIX * mtx.inverse * PUSH_MATRIX; var position = mtx.ExtractPosition() + new Vector3(0.5f, 0.5f, 0); var rotation = mtx.ExtractRotation(); var scale = mtx.ExtractScale(); var size = t.sizeDelta; var min = new Vector3(-size.x / 2, -size.y / 2, 0); var max = new Vector3(size.x / 2, size.y / 2, 0); // Modify RectTransfrom setting t.pivot = t.anchorMin = t.anchorMax = new Vector2(0.5f, 0.5f); t.sizeDelta = ((RectTransform)t.parent).rect.size; // Set TRS t.localPosition = MathTF.Leap3Unclamped(min, max, position); t.localRotation = rotation; t.localScale = scale; }