Answers.Body: <p>You could just go with any fully convolutional network that has the same output resolution as the image input resolution (e.g. from semantic segmentation) as your backbone.</p>
  <p>Then</p>
  <p><strong>Solution 1:</strong> You could adapt the last layer to have 4 feature maps where the first 2 maps represent the proability of existance or non-existance of point 1. And the last 2 maps represent the proability of existance or non-existance of point 2. This then gives you a heatmap of the existance of such points. Here you should also do non-maximum supression to only get single likely points instead of areas. Furthermore you need to apply the softmax function correctly only on each 2 points separately. Or use a sigmoid layer where you only solve a binary problem and use 2 feature maps instead of 4.</p>
  <p><strong>Solution 2:</strong> If there is no clear physical/unique explaination of wich point should be regarded as point 1 and which point as point 2 then solution 1 might be problematic since you force the model to decide on that (by having dedicated point 1 and point 2 feature maps) which is then actually not possible.</p>
  <p>In that case you could do e.g. this approach:</p>
  <p>Use 4 feature maps where the first two maps represent the probability of existance or non-existance of a point in general. Then use the last 2 maps to represent the normalized x/y vector that points to the corresponding other point. Then afterwards you can filter out corresponding points by looking if their regression vector points towards each other. (This is somewhat similar and adapted to what center point net does). Here only the first 2 layers should be sigmoided and the last 2 are regression layers, but normalized. Non-max suppression should also be done here to filter out only single points.</p>
  <p>These both approaches have the nice property of being fully convolutional and therefore translation invariant. It means for example you can easily adapt it to other image resolutions.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-12T16:00:33.133Z
Answers.LastActivityDate: 2022-01-12T16:00:33.133Z
Answers.UserDisplayName: Marcel_marcel1991
Answers.Body: <p>Recent work achieves a similar task: Object recognition together with the bounding box (e.g. <a href="https://pjreddie.com/darknet/yolo/" rel="nofollow noreferrer">YOLO</a>---there are quite a few on Github too). The bounding box is not enough in your case, but it is an interesting pattern: Recognition plus some form of measurement. Such architectures could be good candidate to start with, and repurpose for stick orientation.</p>
  
  <p>The problem could also leverage the current results in gait recognition. In fact, this looks closer to the problem at hand than object recognition. An example is this <a href="https://arxiv.org/abs/1601.06931" rel="nofollow noreferrer">model based on multiview (many pictures input) recognition</a>, with a <a href="https://github.com/marian-margeta/gait-recognition" rel="nofollow noreferrer">demonstration on Github</a>. Gait recognition is also popular these days, and many inspiring papers and OSS implementations are available.</p>
  
  <p>The above presents two approaches your problem could benefit from, as a "combination". My gut feeling is that tilt and orientations may be easier than direction (i.e. where is the tip?).</p>
  
  <hr>
  
  <p>The question calls for training a model. An alternative approach, perhaps to start with and get more insight, could be to go with "standard" computer vision algorithms, such as the <a href="https://en.wikipedia.org/wiki/Hough_transform" rel="nofollow noreferrer">Hough Transform</a>. This transforms allows to find lines in an image. The mathematics are at reach, and it may work well enough for a quick demo. Also, your handle name suggests "embedded mobile" engineer, and a simple Hough Transform could be cheap on mobile.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-01T03:16:46.523Z
Answers.Text: Appreciate the feedback.  I am considering a modified version of any bounding box model.  Instead of the coordinates defining the box, it would just be the coordinates for the tip and end of the instrument.  So for instance, for a pencil, the tip would be the sharp lead writing part while the end would be the eraser.  For forceps, the tip would be the clamp of the forceps while the end would be the handle, where the forceps are attached.  I just do not know if this approach can work.  I wanted to get some confidence before labeling all the training data before going ahead with this approach.
Answers.UserDisplayName: iOScoder
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-01T03:19:33.303Z
Answers.Text: Hough transform would be great for lines (like these), but cannot determine orientation.  You're right though, it is indeed good for mobile. :)
Answers.UserDisplayName: iOScoder
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-01T03:34:07.237Z
Answers.Text: Is there a way to update the question to get more specific answers, and perhaps refine mine? As for the Hough transform, sorry if the explanation was vague (possible edit too). The transform detects lines only. The orientation takes a bit more work, but knowing two points on each line, and the orientation of the photo (e.g. EXIF metadata) are enough.
Answers.UserDisplayName: Eric Platon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-05T06:38:25.480Z
Answers.Text: I've updated the question to be more specific.  Thanks.
Answers.UserDisplayName: iOScoder
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-05T07:15:13.117Z
Answers.Text: I would say pose recognition is also very similar to OP's requirement. E.g. https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/42237.pdf  - although achieving results like the paper requires a lot of labelled data, it might be achieved for simpler objects via using a game engine renderer.
Answers.UserDisplayName: Neil Slater
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-05T08:51:56.087Z
Answers.Text: @NeilSlater Your interesting comment could be a terrific alternative answer. How about posting an answer, perhaps elaborating a bit more?
Answers.UserDisplayName: Eric Platon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-29T09:07:33.450Z
Answers.LastActivityDate: 2018-05-29T09:07:33.450Z
Answers.UserDisplayName: Eric Platon
Body: <p>I am looking to detect thin objects, like pens, pencils, and surgical instruments. The bounding box is not important, but I am looking to see if I can train a model to detect both the object as well as its orientation.</p>
  <p>Typical object detection networks, like R-CNN, YOLO, and SSD encode the class name and bounding boxes. Instead of bounding boxes, I'm looking to encode only 2 points, one starting <span class="math-container">$x,y$</span> point and one ending <span class="math-container">$x,y$</span> point.  The start point for objects is where one would grip the object.  For instance:</p>
  <ul>
  <li>The pencil eraser(start point) is pointed 50 degrees to the top right.</li>
  <li>The surgical instrument is 10 degrees from the x-axis and the handle is pointed to the bottom right.</li>
  <li>Pen tip (endpoint) is pointing vertically upwards.</li>
  <li>Fork, the start point would be the grip handle part, and the endpoint would be in the middle where the 4 prongs are.</li>
  </ul>
  <p>As long as I can encode the start and endpoints, then I can determine the orientation. I would need to define these points during training.</p>
  <p>The question is whether there is an existing model (mobile net/inception/RCNN) that I can encode this information in?  One potential way I was thinking was to use YOLO and for the bounding box, the top left <span class="math-container">$x,y$</span> would be the starting point <span class="math-container">$x,y$</span> (handle), whereas the bounding box's width and height would be replaced with the endpoint <span class="math-container">$x,y$</span> (pencil writing tip, fork prongs.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-12-22T21:45:36.327Z
Comments.Text: I am looking for a solution for the same question.. I trained on YOLO4 and looking for orientation,,, Any update?
Comments.UserDisplayName: Mona
Tags: <convolutional-neural-networks><computer-vision><object-detection><yolo><model-request>
Title: How can I detect thin objects (like pens and pencils) without a bounding box but only 2 endpoints and the orientation?
UserDisplayName: iOScoder
ThreadText: # How can I detect thin objects (like pens and pencils) without a bounding box but only 2 endpoints and the orientation?
  
  (Asked by: username_0 on 2018-05-25)
  
  I am looking to detect thin objects, like pens, pencils, and surgical instruments. The bounding box is not important, but I am looking to see if I can train a model to detect both the object as well as its orientation.
  
  Typical object detection networks, like R-CNN, YOLO, and SSD encode the class name and bounding boxes. Instead of bounding boxes, I'm looking to encode only 2 points, one starting $x,y$ point and one ending $x,y$ point. The start point for objects is where one would grip the object. For instance:
  
  * The pencil eraser(start point) is pointed 50 degrees to the top right.
  * The surgical instrument is 10 degrees from the x-axis and the handle is pointed to the bottom right.
  * Pen tip (endpoint) is pointing vertically upwards.
  * Fork, the start point would be the grip handle part, and the endpoint would be in the middle where the 4 prongs are.
  
  As long as I can encode the start and endpoints, then I can determine the orientation. I would need to define these points during training.
  
  The question is whether there is an existing model (mobile net/inception/RCNN) that I can encode this information in? One potential way I was thinking was to use YOLO and for the bounding box, the top left $x,y$ would be the starting point $x,y$ (handle), whereas the bounding box's width and height would be replaced with the endpoint $x,y$ (pencil writing tip, fork prongs.
  
  **Tags:** convolutional-neural-networks, computer-vision, object-detection, yolo, model-request
  
  > **Comments:**
  > **username_1**: I am looking for a solution for the same question.. I trained on YOLO4 and looking for orientation,,, Any update?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2022-01-12. Score: 1 | Accepted answer
  
  You could just go with any fully convolutional network that has the same output resolution as the image input resolution (e.g. from semantic segmentation) as your backbone.
  
  Then
  
  **Solution 1:** You could adapt the last layer to have 4 feature maps where the first 2 maps represent the proability of existance or non-existance of point 1. And the last 2 maps represent the proability of existance or non-existance of point 2. This then gives you a heatmap of the existance of such points. Here you should also do non-maximum supression to only get single likely points instead of areas. Furthermore you need to apply the softmax function correctly only on each 2 points separately. Or use a sigmoid layer where you only solve a binary problem and use 2 feature maps instead of 4.
  
  **Solution 2:** If there is no clear physical/unique explaination of wich point should be regarded as point 1 and which point as point 2 then solution 1 might be problematic since you force the model to decide on that (by having dedicated point 1 and point 2 feature maps) which is then actually not possible.
  
  In that case you could do e.g. this approach:
  
  Use 4 feature maps where the first two maps represent the probability of existance or non-existance of a point in general. Then use the last 2 maps to represent the normalized x/y vector that points to the corresponding other point. Then afterwards you can filter out corresponding points by looking if their regression vector points towards each other. (This is somewhat similar and adapted to what center point net does). Here only the first 2 layers should be sigmoided and the last 2 are regression layers, but normalized. Non-max suppression should also be done here to filter out only single points.
  
  These both approaches have the nice property of being fully convolutional and therefore translation invariant. It means for example you can easily adapt it to other image resolutions.
  
  
  ---
  
  ### Answer by username_3 on 2018-05-29. Score: 1
  
  Recent work achieves a similar task: Object recognition together with the bounding box (e.g. [YOLO](https://pjreddie.com/darknet/yolo/)---there are quite a few on Github too). The bounding box is not enough in your case, but it is an interesting pattern: Recognition plus some form of measurement. Such architectures could be good candidate to start with, and repurpose for stick orientation.
  
  The problem could also leverage the current results in gait recognition. In fact, this looks closer to the problem at hand than object recognition. An example is this [model based on multiview (many pictures input) recognition](https://arxiv.org/abs/1601.06931), with a [demonstration on Github](https://github.com/marian-margeta/gait-recognition). Gait recognition is also popular these days, and many inspiring papers and OSS implementations are available.
  
  The above presents two approaches your problem could benefit from, as a "combination". My gut feeling is that tilt and orientations may be easier than direction (i.e. where is the tip?).
  
  ---
  
  The question calls for training a model. An alternative approach, perhaps to start with and get more insight, could be to go with "standard" computer vision algorithms, such as the [Hough Transform](https://en.wikipedia.org/wiki/Hough_transform). This transforms allows to find lines in an image. The mathematics are at reach, and it may work well enough for a quick demo. Also, your handle name suggests "embedded mobile" engineer, and a simple Hough Transform could be cheap on mobile.
  
  > **Comments:**
  > **username_0**: Appreciate the feedback.  I am considering a modified version of any bounding box model.  Instead of the coordinates defining the box, it would just be the coordinates for the tip and end of the instrument.  So for instance, for a pencil, the tip would be the sharp lead writing part while the end would be the eraser.  For forceps, the tip would be the clamp of the forceps while the end would be the handle, where the forceps are attached.  I just do not know if this approach can work.  I wanted to get some confidence before labeling all the training data before going ahead with this approach.  
  > **username_0**: Hough transform would be great for lines (like these), but cannot determine orientation.  You're right though, it is indeed good for mobile. :)  
  > **username_3**: Is there a way to update the question to get more specific answers, and perhaps refine mine? As for the Hough transform, sorry if the explanation was vague (possible edit too). The transform detects lines only. The orientation takes a bit more work, but knowing two points on each line, and the orientation of the photo (e.g. EXIF metadata) are enough.  
  > **username_0**: I've updated the question to be more specific.  Thanks.  
  > **username_4**: I would say pose recognition is also very similar to OP's requirement. E.g. https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/42237.pdf  - although achieving results like the paper requires a lot of labelled data, it might be achieved for simpler objects via using a game engine renderer.  
  > **username_3**: @username_4 Your interesting comment could be a terrific alternative answer. How about posting an answer, perhaps elaborating a bit more?  
  
  ---
  
  