{
  "id": 399904,
  "title": "👨‍💻 Compute Distance & Angle Based Features using Keras Custom Layers ",
  "url": "/competitions/asl-signs/discussion/399904",
  "author_name": "",
  "post_date": "2023-04-06T02:43:37.275208100Z",
  "votes": 10,
  "comment_count": 8,
  "views": 0,
  "content": "<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F5746197%2F673f368534ac4288ee29c62c3748fc97%2FScreen%20Shot%202023-04-05%20at%201.19.31%20PM.png?generation=1680748842240338&amp;alt=media\" alt=\"\"></p>\n<p>In the following <a href=\"https://www.kaggle.com/code/josephzahar/distance-angle-based-features-using-keras\" target=\"_blank\">notebook</a>, I offer you modular subclasses that would allow you to introduce new relevant features to your models! More specifically, we will be appllying different layers to specific landmarks as explained below:</p>\n<ul>\n<li>The ChooseHand layer is responsible of only extracting the signing hand in the frames</li>\n<li>The GatherLayer layer can extract specific landarks (upper and lower lips) given a set of indices</li>\n<li>The HandKineticLayer layer is responsible of calculating the euclidean distance between non-consecutive joints of the signing hand</li>\n<li>The FaceKineticLayer layer will calculate the euclidean distance between non-consecutive joints of upper and lower lips</li>\n<li>The AngularLayer layer will compute the angle between the x and y vectors between non-consecutive joints of the hand</li>\n</ul>\n<p>Hope it will be useful for some of you!</p>",
  "messages": [
    {
      "id": "2211401",
      "postDate": "04/06/2023 02:43:37",
      "content": "<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F5746197%2F673f368534ac4288ee29c62c3748fc97%2FScreen%20Shot%202023-04-05%20at%201.19.31%20PM.png?generation=1680748842240338&amp;alt=media\" alt=\"\"></p>\n<p>In the following <a href=\"https://www.kaggle.com/code/josephzahar/distance-angle-based-features-using-keras\" target=\"_blank\">notebook</a>, I offer you modular subclasses that would allow you to introduce new relevant features to your models! More specifically, we will be appllying different layers to specific landmarks as explained below:</p>\n<ul>\n<li>The ChooseHand layer is responsible of only extracting the signing hand in the frames</li>\n<li>The GatherLayer layer can extract specific landarks (upper and lower lips) given a set of indices</li>\n<li>The HandKineticLayer layer is responsible of calculating the euclidean distance between non-consecutive joints of the signing hand</li>\n<li>The FaceKineticLayer layer will calculate the euclidean distance between non-consecutive joints of upper and lower lips</li>\n<li>The AngularLayer layer will compute the angle between the x and y vectors between non-consecutive joints of the hand</li>\n</ul>\n<p>Hope it will be useful for some of you!</p>",
      "rawMarkdown": "![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F5746197%2F673f368534ac4288ee29c62c3748fc97%2FScreen%20Shot%202023-04-05%20at%201.19.31%20PM.png?generation=1680748842240338&alt=media)\n\nIn the following [notebook](https://www.kaggle.com/code/josephzahar/distance-angle-based-features-using-keras), I offer you modular subclasses that would allow you to introduce new relevant features to your models! More specifically, we will be appllying different layers to specific landmarks as explained below:\n\n- The ChooseHand layer is responsible of only extracting the signing hand in the frames\n- The GatherLayer layer can extract specific landarks (upper and lower lips) given a set of indices\n- The HandKineticLayer layer is responsible of calculating the euclidean distance between non-consecutive joints of the signing hand\n- The FaceKineticLayer layer will calculate the euclidean distance between non-consecutive joints of upper and lower lips\n- The AngularLayer layer will compute the angle between the x and y vectors between non-consecutive joints of the hand\n\nHope it will be useful for some of you!",
      "votes": null
    },
    {
      "id": "2211611",
      "postDate": "04/06/2023 06:18:30",
      "content": "<p><img src=\"https://i.ibb.co/JHdXQ1C/Selection-999-1709.png\" alt=\"https://i.ibb.co/JHdXQ1C/Selection-999-1709.png\"></p>\n<p>example of distance and angle feature. These are local feature. you also need global feature</p>\n<p>A,C can be consecutive or non-consecutive points of B</p>",
      "rawMarkdown": "![https://i.ibb.co/JHdXQ1C/Selection-999-1709.png](https://i.ibb.co/JHdXQ1C/Selection-999-1709.png)\n\nexample of distance and angle feature. These are local feature. you also need global feature\n\nA,C can be consecutive or non-consecutive points of B",
      "votes": null
    },
    {
      "id": "2211730",
      "postDate": "04/06/2023 08:18:05",
      "content": "<p>There are some issues with angles in ML. Be aware, that Euler angles are cyclic (e.g. 360 = 0) but NN fails to understand this (since it is completely opposite values). A Gimbal lock sometimes appears, but we could neglect it here. Using quaternion representation of rotation may be a good idea, but there is a quaternion property </p>\n<pre><code>q == -q\n</code></pre>\n<p>It is a relatively rare case but appears time by time when 360 degrees rotation is performed. The 4x4 rotation matrix is the best choice in terms of continuous values, but it is some redundancy in values. Maybe, the exponential map is even better, or using some advanced 6D parametrization. It is a subject of research…</p>",
      "rawMarkdown": "There are some issues with angles in ML. Be aware, that Euler angles are cyclic (e.g. 360 = 0) but NN fails to understand this (since it is completely opposite values). A Gimbal lock sometimes appears, but we could neglect it here. Using quaternion representation of rotation may be a good idea, but there is a quaternion property \n\n```\nq == -q\n```\n\nIt is a relatively rare case but appears time by time when 360 degrees rotation is performed. The 4x4 rotation matrix is the best choice in terms of continuous values, but it is some redundancy in values. Maybe, the exponential map is even better, or using some advanced 6D parametrization. It is a subject of research...",
      "votes": null
    },
    {
      "id": "2212048",
      "postDate": "04/06/2023 13:43:04",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/meowmeowmeowmeowmeow\" target=\"_blank\">@meowmeowmeowmeowmeow</a>, thank you for your useful comment! For this project, what do you think about keeping the angle value as a cosines? Or convert the degree value to a radians, it may solve some of the issues you mentioned.<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F5746197%2F3d890ca87fb88ebed5b6ea7f647780d6%2FScreen%20Shot%202023-04-06%20at%209.43.48%20AM.png?generation=1680788645910981&amp;alt=media\" alt=\"\"></p>",
      "rawMarkdown": "Hi @meowmeowmeowmeowmeow, thank you for your useful comment! For this project, what do you think about keeping the angle value as a cosines? Or convert the degree value to a radians, it may solve some of the issues you mentioned.\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F5746197%2F3d890ca87fb88ebed5b6ea7f647780d6%2FScreen%20Shot%202023-04-06%20at%209.43.48%20AM.png?generation=1680788645910981&alt=media)",
      "votes": null
    },
    {
      "id": "2212066",
      "postDate": "04/06/2023 13:57:34",
      "content": "<p>That great idea. I was thinking a lot about it. Even I was trying to solve a more general task - convert an acyclic signal to a cyclic one (and keep inverse transformation without any data loss). Unfortunately, I haven't solved it yet.</p>\n<p>What about sin/cos of angle - I am worried it has non-unique values. Take a look at the picture below - there is <code>sin(0) = 0</code> and <code>sin(2pi) = 0</code>. That is exactly what we want, but unfortunately <code>sin(pi) = 0</code> as well. That means that having such features assimilates 0, 2pi, and pi. I guess it would be harmful to the model as well.</p>\n<p><img src=\"https://www.mathsisfun.com/algebra/images/sine-graph.svg\" alt=\"sin\"></p>",
      "rawMarkdown": "That great idea. I was thinking a lot about it. Even I was trying to solve a more general task - convert an acyclic signal to a cyclic one (and keep inverse transformation without any data loss). Unfortunately, I haven't solved it yet.\n\nWhat about sin/cos of angle - I am worried it has non-unique values. Take a look at the picture below - there is `sin(0) = 0` and `sin(2pi) = 0`. That is exactly what we want, but unfortunately `sin(pi) = 0` as well. That means that having such features assimilates 0, 2pi, and pi. I guess it would be harmful to the model as well.\n\n![sin](https://www.mathsisfun.com/algebra/images/sine-graph.svg)",
      "votes": null
    },
    {
      "id": "2212168",
      "postDate": "04/06/2023 15:06:20",
      "content": "<p>Interesting, maybe we could generate our own angle measure, like a function that would modify those non-unique values to unique ones. Lets take the case of angles in degrees, depending on which quarter the angle is located we could transform it to a value that the NN would understand.</p>\n<p>e.g., pseudo-code:<br>\nif angle == 360 -&gt; angle = 0<br>\nelif angle in quarter 3 -&gt; angle = angle - 180<br>\netc.</p>\n<p>In a more generalized manner of course</p>",
      "rawMarkdown": "Interesting, maybe we could generate our own angle measure, like a function that would modify those non-unique values to unique ones. Lets take the case of angles in degrees, depending on which quarter the angle is located we could transform it to a value that the NN would understand.\n\ne.g., pseudo-code:\nif angle == 360 -> angle = 0\nelif angle in quarter 3 -> angle = angle - 180\netc.\n\nIn a more generalized manner of course",
      "votes": null
    },
    {
      "id": "2212258",
      "postDate": "04/06/2023 16:39:05",
      "content": "<blockquote>\n  <p>modify those non-unique values to unique ones</p>\n</blockquote>\n<p>Here I would like to add that it is not enough to expect unique values. We need continuous (a.k.a Lyapunov stability). Your example gives me an idea of using a unit vector rotated to a specific angle. The sign of the first component will denote a (1, 4) or (2, 3) quadrant. And the second (1,2) or (3,4). Thus we satisfy unique and continuous values. </p>\n<p>Very is a relationship between rotations and complex numbers. Personally, I am passion about this <a href=\"https://www.youtube.com/watch?v=mvmuCPvRoWQ&amp;list=PLucNEDEq4z_AdqV1ii0vmH0clNhYPI4lK&amp;index=5\" target=\"_blank\">video</a>. </p>",
      "rawMarkdown": "> modify those non-unique values to unique ones\n\nHere I would like to add that it is not enough to expect unique values. We need continuous (a.k.a Lyapunov stability). Your example gives me an idea of using a unit vector rotated to a specific angle. The sign of the first component will denote a (1, 4) or (2, 3) quadrant. And the second (1,2) or (3,4). Thus we satisfy unique and continuous values. \n\nVery is a relationship between rotations and complex numbers. Personally, I am passion about this [video](https://www.youtube.com/watch?v=mvmuCPvRoWQ&list=PLucNEDEq4z_AdqV1ii0vmH0clNhYPI4lK&index=5).",
      "votes": null
    },
    {
      "id": "2212618",
      "postDate": "04/06/2023 23:24:37",
      "content": "<p>3Blue1Brown has definitely the best videos!</p>",
      "rawMarkdown": "3Blue1Brown has definitely the best videos!",
      "votes": null
    },
    {
      "id": "2213550",
      "postDate": "04/07/2023 16:49:28",
      "content": "<p>Very Interesting Approach, Thanks for that!</p>",
      "rawMarkdown": "Very Interesting Approach, Thanks for that!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2211611,
      "author_name": "hengck23",
      "author_url": "",
      "post_date": "04/06/2023 06:18:30",
      "content": "<p><img src=\"https://i.ibb.co/JHdXQ1C/Selection-999-1709.png\" alt=\"https://i.ibb.co/JHdXQ1C/Selection-999-1709.png\"></p>\n<p>example of distance and angle feature. These are local feature. you also need global feature</p>\n<p>A,C can be consecutive or non-consecutive points of B</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 2211730,
      "author_name": "meowmeowmeowmeowmeow",
      "author_url": "",
      "post_date": "04/06/2023 08:18:05",
      "content": "<p>There are some issues with angles in ML. Be aware, that Euler angles are cyclic (e.g. 360 = 0) but NN fails to understand this (since it is completely opposite values). A Gimbal lock sometimes appears, but we could neglect it here. Using quaternion representation of rotation may be a good idea, but there is a quaternion property </p>\n<pre><code>q == -q\n</code></pre>\n<p>It is a relatively rare case but appears time by time when 360 degrees rotation is performed. The 4x4 rotation matrix is the best choice in terms of continuous values, but it is some redundancy in values. Maybe, the exponential map is even better, or using some advanced 6D parametrization. It is a subject of research…</p>",
      "votes": null,
      "replies": [
        {
          "id": 2212048,
          "author_name": "josephzahar",
          "author_url": "",
          "post_date": "04/06/2023 13:43:04",
          "content": "<p>Hi <a href=\"https://www.kaggle.com/meowmeowmeowmeowmeow\" target=\"_blank\">@meowmeowmeowmeowmeow</a>, thank you for your useful comment! For this project, what do you think about keeping the angle value as a cosines? Or convert the degree value to a radians, it may solve some of the issues you mentioned.<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F5746197%2F3d890ca87fb88ebed5b6ea7f647780d6%2FScreen%20Shot%202023-04-06%20at%209.43.48%20AM.png?generation=1680788645910981&amp;alt=media\" alt=\"\"></p>",
          "votes": null,
          "replies": [
            {
              "id": 2212066,
              "author_name": "meowmeowmeowmeowmeow",
              "author_url": "",
              "post_date": "04/06/2023 13:57:34",
              "content": "<p>That great idea. I was thinking a lot about it. Even I was trying to solve a more general task - convert an acyclic signal to a cyclic one (and keep inverse transformation without any data loss). Unfortunately, I haven't solved it yet.</p>\n<p>What about sin/cos of angle - I am worried it has non-unique values. Take a look at the picture below - there is <code>sin(0) = 0</code> and <code>sin(2pi) = 0</code>. That is exactly what we want, but unfortunately <code>sin(pi) = 0</code> as well. That means that having such features assimilates 0, 2pi, and pi. I guess it would be harmful to the model as well.</p>\n<p><img src=\"https://www.mathsisfun.com/algebra/images/sine-graph.svg\" alt=\"sin\"></p>",
              "votes": null,
              "replies": [
                {
                  "id": 2212168,
                  "author_name": "josephzahar",
                  "author_url": "",
                  "post_date": "04/06/2023 15:06:20",
                  "content": "<p>Interesting, maybe we could generate our own angle measure, like a function that would modify those non-unique values to unique ones. Lets take the case of angles in degrees, depending on which quarter the angle is located we could transform it to a value that the NN would understand.</p>\n<p>e.g., pseudo-code:<br>\nif angle == 360 -&gt; angle = 0<br>\nelif angle in quarter 3 -&gt; angle = angle - 180<br>\netc.</p>\n<p>In a more generalized manner of course</p>",
                  "votes": null,
                  "replies": [
                    {
                      "id": 2212258,
                      "author_name": "meowmeowmeowmeowmeow",
                      "author_url": "",
                      "post_date": "04/06/2023 16:39:05",
                      "content": "<blockquote>\n  <p>modify those non-unique values to unique ones</p>\n</blockquote>\n<p>Here I would like to add that it is not enough to expect unique values. We need continuous (a.k.a Lyapunov stability). Your example gives me an idea of using a unit vector rotated to a specific angle. The sign of the first component will denote a (1, 4) or (2, 3) quadrant. And the second (1,2) or (3,4). Thus we satisfy unique and continuous values. </p>\n<p>Very is a relationship between rotations and complex numbers. Personally, I am passion about this <a href=\"https://www.youtube.com/watch?v=mvmuCPvRoWQ&amp;list=PLucNEDEq4z_AdqV1ii0vmH0clNhYPI4lK&amp;index=5\" target=\"_blank\">video</a>. </p>",
                      "votes": null,
                      "replies": [
                        {
                          "id": 2212618,
                          "author_name": "josephzahar",
                          "author_url": "",
                          "post_date": "04/06/2023 23:24:37",
                          "content": "<p>3Blue1Brown has definitely the best videos!</p>",
                          "votes": null,
                          "replies": []
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "id": 2213550,
      "author_name": "stanblake",
      "author_url": "",
      "post_date": "04/07/2023 16:49:28",
      "content": "<p>Very Interesting Approach, Thanks for that!</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "2211401": "![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F5746197%2F673f368534ac4288ee29c62c3748fc97%2FScreen%20Shot%202023-04-05%20at%201.19.31%20PM.png?generation=1680748842240338&alt=media)\n\nIn the following [notebook](https://www.kaggle.com/code/josephzahar/distance-angle-based-features-using-keras), I offer you modular subclasses that would allow you to introduce new relevant features to your models! More specifically, we will be appllying different layers to specific landmarks as explained below:\n\n- The ChooseHand layer is responsible of only extracting the signing hand in the frames\n- The GatherLayer layer can extract specific landarks (upper and lower lips) given a set of indices\n- The HandKineticLayer layer is responsible of calculating the euclidean distance between non-consecutive joints of the signing hand\n- The FaceKineticLayer layer will calculate the euclidean distance between non-consecutive joints of upper and lower lips\n- The AngularLayer layer will compute the angle between the x and y vectors between non-consecutive joints of the hand\n\nHope it will be useful for some of you!",
    "2211611": "![https://i.ibb.co/JHdXQ1C/Selection-999-1709.png](https://i.ibb.co/JHdXQ1C/Selection-999-1709.png)\n\nexample of distance and angle feature. These are local feature. you also need global feature\n\nA,C can be consecutive or non-consecutive points of B",
    "2211730": "There are some issues with angles in ML. Be aware, that Euler angles are cyclic (e.g. 360 = 0) but NN fails to understand this (since it is completely opposite values). A Gimbal lock sometimes appears, but we could neglect it here. Using quaternion representation of rotation may be a good idea, but there is a quaternion property \n\n```\nq == -q\n```\n\nIt is a relatively rare case but appears time by time when 360 degrees rotation is performed. The 4x4 rotation matrix is the best choice in terms of continuous values, but it is some redundancy in values. Maybe, the exponential map is even better, or using some advanced 6D parametrization. It is a subject of research...",
    "2212048": "Hi @meowmeowmeowmeowmeow, thank you for your useful comment! For this project, what do you think about keeping the angle value as a cosines? Or convert the degree value to a radians, it may solve some of the issues you mentioned.\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F5746197%2F3d890ca87fb88ebed5b6ea7f647780d6%2FScreen%20Shot%202023-04-06%20at%209.43.48%20AM.png?generation=1680788645910981&alt=media)",
    "2212066": "That great idea. I was thinking a lot about it. Even I was trying to solve a more general task - convert an acyclic signal to a cyclic one (and keep inverse transformation without any data loss). Unfortunately, I haven't solved it yet.\n\nWhat about sin/cos of angle - I am worried it has non-unique values. Take a look at the picture below - there is `sin(0) = 0` and `sin(2pi) = 0`. That is exactly what we want, but unfortunately `sin(pi) = 0` as well. That means that having such features assimilates 0, 2pi, and pi. I guess it would be harmful to the model as well.\n\n![sin](https://www.mathsisfun.com/algebra/images/sine-graph.svg)",
    "2212168": "Interesting, maybe we could generate our own angle measure, like a function that would modify those non-unique values to unique ones. Lets take the case of angles in degrees, depending on which quarter the angle is located we could transform it to a value that the NN would understand.\n\ne.g., pseudo-code:\nif angle == 360 -> angle = 0\nelif angle in quarter 3 -> angle = angle - 180\netc.\n\nIn a more generalized manner of course",
    "2212258": "> modify those non-unique values to unique ones\n\nHere I would like to add that it is not enough to expect unique values. We need continuous (a.k.a Lyapunov stability). Your example gives me an idea of using a unit vector rotated to a specific angle. The sign of the first component will denote a (1, 4) or (2, 3) quadrant. And the second (1,2) or (3,4). Thus we satisfy unique and continuous values. \n\nVery is a relationship between rotations and complex numbers. Personally, I am passion about this [video](https://www.youtube.com/watch?v=mvmuCPvRoWQ&list=PLucNEDEq4z_AdqV1ii0vmH0clNhYPI4lK&index=5).",
    "2212618": "3Blue1Brown has definitely the best videos!",
    "2213550": "Very Interesting Approach, Thanks for that!"
  },
  "source": "meta"
}