3

The title might be a bit convoluted.

I have an image recognition problem where I have to detect a direction. If I represent the direction as an angle it has a discontinuity at 0-360.

This is not exactly my problem, but similar. I want to tell the time from an image of an analog clock. If it is 11:59 and I predict 00:01 then the error is wrong (11:58) but more importantly in the wrong direction.

How do I represent the output in such a way that will work in training.

Edit: Not sure why this was tagged as duplicate, the question is not about measuring distance between points on a circle, the question is on how to perform backpropagation when the output is a continuous circular variable

Tnk
  • 31
  • 4
  • 3
    Take a look at previous threads in the [tag:circular-statistics] tag. – Stephan Kolassa Feb 12 '21 at 21:51
  • Use arithmetic 'mod' (modulo) 360.degrees (or 12 hours--and hundredths, instead of minutes.) Often used for integers, this works for continuous variables. In R: the code `372 %% 360` returns $12$ and `12.03 %% 12` returns $0.03.$ – BruceET Feb 12 '21 at 21:53
  • 2
    @Bruce That doesn't work, because `359 %% 360` returns `359`. It can be made to work with some care, essentially by taking the smaller of `x` modulo 360 and `360-x` modulo 360 where `x` is the difference between angles. – whuber Feb 12 '21 at 22:25
  • @Stephan Kolassa it seems that they are predicting classes, whereas I am trying to predict a continuous value on a circle. I thought of using 360, 180, 90 ... classes myself. I'm more worried about the fact that the output of my network is an arithmetic combination of the last layer, so the last layer myst be very different when predicting 359, compared to 1, it shouldn't be. That's why I was thinking maybe I can solve the problem by representing points on a circle that would be appropriate to the output of a CNN\ – Tnk Feb 12 '21 at 22:27
  • Also search for references to "cosine distance," which is a measure of distance between directions. – whuber Feb 12 '21 at 22:38
  • @Stephan Kolassa I was thinking of using sin and cos to encode the output, but I'm not sure how to combine that in Keras (or any other library) and perform backpropagation to train the network, and I haven't seen it anywhere so I assume it's not a good idea – Tnk Feb 12 '21 at 22:41
  • 1
    Per one of the comments in the duplicate, the simplest idea would be to map your angle to the unit circle, then use the standard Euclidean norm. Am I understanding you correctly that errors in one direction (counterclockwise) are worse than errors in the other direction (clockwise)? If you, you could map differences in angles to $[-\pi,\pi]$, then use a function defined on this interval for your error - but then the problematic discontinuity arises at $\pm\pi$, which is equally far away from zero in both a clockwise and counterclockwise direction. – Stephan Kolassa Feb 13 '21 at 09:05

0 Answers0