My 0.5871 LB Solution (and some lessons learnt)

Hi guys,

With competition almost over and no further attempts here’s an overview of my solution. The source is open-source and available at GitHub - antorsae/fish: Identify fish challenge

STEP 1. Take each video and create new videos cropped to 384x384 centered in the zone of interest (where the fish action is happening) and rotating them so all fish / ruler is horizontal, so they end up like this:



This part is implemented here: fish/ at master · antorsae/fish · GitHub

STEP 2 Take all videos created in step 1) and build frame by frame predictions of length, fish species including a new species_no_fish when there’s no fish.

Here’s an example of the generated predictions for the training data:

row_id,video_id,frame,length,species_fourspot,species_grey sole,species_other,species_plaice,species_summer,species_windowpane,species_winter,species_no_fish

this is implemented using again resnet-152 with transfer learning and classifying the 7 species + a new one (no fish) and regressing the length (only propagating gradients when it’s an actual fish). Oversampling is used for balancing classes. Implementation @ fish/ at master · antorsae/fish · GitHub

STEP 3 Initially I wanted to take the output of 2) and build a RNN to predict the fish sequence. I made some attempts to make it work: by trying to use a CTC function predicting the frame where the fish changes, or generating proxy signals (square wave with mod 2 of the fish number and use binary cross entropy loss, or a chainsaw wave using MSE loss) but none worked. I believe with more work the CTC approach would have worked.

So with just 1 day left I explored the frame-by-frame predictions fish/playground-sequence-prediction-thresholding.ipynb at master · antorsae/fish · GitHub and settled on some basic thresholding to generate the fish sequences: fish/ at master · antorsae/fish · GitHub

Not bad but way worse I think than what a decent RNN-based approach would have provided.


Since the most important metric was sequence accuracy, I should have focused on an end-to-end RNN (or 3d CNN) sequence prediction taking the frame-by-frame CNN features and not just the frame-by-frame probabilities for 8 classes.

Any comments or suggestions would be greatly appreciated. I really enjoyed this competition! :slight_smile:

1 Like

Cropping the region of interest is really nice approach.
As far as I understand the code in, you trained the model against xy coordinate and boat id.
How did you create these labels?
I can imagine that xy coordinate can be computed somehow from x1, y1, x2, y2 in training.csv. Is it the way you did?
Did you also train a model to get boat id?

I first build training_transform.csv with just looking at the centroid of head/tail for each video. I look at all frames and in retrospect I should have experimented looking at the first 2, but anyway that generates a file with the x,y centroid for each video as well as boat_id which is a clustering id - see classifies the boat into a finite set of boat_id (classification task) as well as regressing the x,y of the centroid for that particular video. Instead of taking the raw x,y, I regress the difference of x,y (dx,dy) for the video and the centroid for that boat_id. I weighted the loss so that the classification should be more important and if you look at the variance of dx,dy for each cluster they are smaller that if you where to regress x,y directly, in other words if you classify boat_id correctly (very easy) even if you do a bad job on dx,dy it wouldn’t be so bad.

I tried to regress x,y and the angle directly but when I saw there was just 5 boat scenarios I tried the above and worked on the first attempt (almost :slight_smile: )

1 Like

Thank you for answering. So you used xy centroids to cluster boat types. Very interesting!
But does the model work also for test data? When you crop test images, did they capture fish like training images?
I wonder if it can work well for test images that can contain new types of boat.

Yes, xy centroids and ruler angle (measured by proxy of arctan2(head,tail)). Yes, the model works for test data (I manually verified all 667 test videos visually and yes they capture the fish ROI properly).

Re: new types of boat… not as it is. you would have to train the with ground truth for new types of boats or regress x,y centroids and angle ruler angle directly (code is almost ready to do it, I implementation an orientation-invariant angle loss in which is not used but you can see what it does).