Cyclic Loss (distance between classes)

Hi there,

I am getting started with PyTorch, and I attempting to fine-tune a network to classify containing orientation data (pictures of pedestrians mainly). In particular, I clustered orientation into 24 bins, each of these belonging to a portion of 15º (from 0 to 360), and I have the true labels for all pedestrians to train the classifier. In particular, the last layer of my model is a FC layer with a 1x24 output.

By using a cross-entropy loss the obtained results are acceptable, but atm I am not taking into account the distance between classes: i.e. the bin number 0 (from 0-15º) is close to the bin number 1 (15-30º), but it is also close to the 23rd bin (345-360º).

My question is: is there any kind of implemented loss function that can take into account this cyclic feature and uses the distance between classes?


You could use modulo arithmetic to calculate distance between classes

c1 = (x - y)%23
c2 = (y-x)%23
min_dist = min(c1,c2)

Since you’re comparing orientations, you might be able to use cosine similarity directly without binning.

1 Like