Kaggle's Whale Competition

I think the issue is with the full data-set, I tested the code with a much smaller painfully validated data-set :sweat_smile: and the code worked but with the full set the error occurs after 1 epoch so there is something missing or mismatched in the full set

1 Like

Is this something we can easily do with the fast ai library? And if so, how?

Just read @amritv 's post about the data maybe not being valid. Thanks for the insight.

Hi folks

So I am doing this competition too - got sooo confused yesterday.

My Y value from the

x, y = next(iter(data.val_dl)) 

set returns a single dimension array(the same length as the batch size - 64) and I get randomly large numbers in this array. I just for the life of me figure out why the one hot encoding isn’t working…

data = ImageClassifierData.from_csv(
  PATH, 
  'train',
  label_csv,
  tfms=tfms_from_model(archiecture_chosen, sz, aug_tfms=transforms_side_on),
  test_name='test',
  val_idxs=val_idxs
);


print(len(val_idxs)) # validation set indexes
print(len(data.classes)) #individual classes there are

1970
4251

x,y = next(iter(data.trn_dl)) 

# x = First batch, 64 images, 3(RGB) x 244 x 244 per image


print(y)
# truth label indexes against each category - is what I am expecting.
# but it looks like I am getting the softmax i.e max(0, x) of each image in the batch(bs=64) returned. 

0
2409
1484
1632
3784
3175
2118
0
2443
638
1407
3134
1194
2525
0
977
1323
3942
2148
1048
1147
0
1392
2276
1904
3816
0
2796
2619
120
52
567
944
2305
3445
0
2017
1363
3861
2784
1208
1146
409
3275
3232
2720
2620
2348
2516
3614
2409
2511
3037
310
1545
3996
353
1280
3608
2193
2156
4197
551
3942
[torch.cuda.LongTensor of size 64 (GPU 0)]

list(zip(data.classes, y)) 
# zips the y(truth labels) with the images in the batch. 
# Showing that this is indeed one number per item in the batch.
# This looks so wrong :( where are my 1's and 0's

[(‘new_whale’, 0),
(‘w_0013924’, 2409),
(‘w_001ebbc’, 1484),
(‘w_002222a’, 1632),
(‘w_002b682’, 3784),
(‘w_002dc11’, 3175),
(‘w_0087fdd’, 2118),
(‘w_008c602’, 0),
(‘w_009dc00’, 2443),
(‘w_00b621b’, 638),
(‘w_00c4901’, 1407),
(‘w_00cb685’, 3134),
(‘w_00d8453’, 1194),
(‘w_00fbb4e’, 2525),
(‘w_0103030’, 0),
(‘w_010a1fa’, 977),
(‘w_011d4b5’, 1323),
(‘w_0122d85’, 3942),
(‘w_01319fa’, 2148),
(‘w_0134192’, 1048),
(‘w_013bbcf’, 1147),
(‘w_014250a’, 0),
(‘w_014a645’, 1392),
(‘w_0156f27’, 2276),
(‘w_015c991’, 1904),
(‘w_015e3cf’, 3816),
(‘w_01687a8’, 0),
(‘w_0175a35’, 2796),
(‘w_018bc64’, 2619),
(‘w_01a4234’, 120),
(‘w_01a51a6’, 52),
(‘w_01a99a5’, 567),
(‘w_01ab6dc’, 944),
(‘w_01b2250’, 2305),
(‘w_01c2cb0’, 3445),
(‘w_01cbcbf’, 0),
(‘w_01d6ca0’, 2017),
(‘w_01e1223’, 1363),
(‘w_01f211f’, 3861),
(‘w_01f8a43’, 2784),
(‘w_01f9086’, 1208),
(‘w_024358d’, 1146),
(‘w_0245a27’, 409),
(‘w_0265cb6’, 3275),
(‘w_026fdf8’, 3232),
(‘w_028ca0d’, 2720),
(‘w_029013f’, 2620),
(‘w_02a768d’, 2348),
(‘w_02b775b’, 2516),
(‘w_02bb4cf’, 3614),
(‘w_02c2248’, 2409),
(‘w_02c9470’, 2511),
(‘w_02cf46c’, 3037),
(‘w_02d5fad’, 310),
(‘w_02d7dc8’, 1545),
(‘w_02e5407’, 3996),
(‘w_02facde’, 353),
(‘w_02fce90’, 1280),
(‘w_030294d’, 3608),
(‘w_0308405’, 2193),
(‘w_0324b97’, 2156),
(‘w_032d44d’, 4197),
(‘w_0337aa5’, 551),
(‘w_034a3fd’, 3942)]


Any advice would be great.

1 Like

You can just use opencv to convert the grayscale images to rgb using the below function.
img_rgb = cv2.cvtColor(gray,cv2.COLOR_GRAY2RGB)

3 Likes

thanks! i ll check it out!!

Hi all, just a couple of quick questions, as I have been fiddling around with this competition as well.

  1. I will need to transform the grayscale images into RGB, and have been trying to do so according to https://stackoverflow.com/a/21709613. Unfortunately, it has not been working. Would anyone have any advice?
  2. Do you recommend doing grayscale -> RGB process before I resize the photos?

Did you find a solution to your problem already? I have the same issue.

Same issue with latest fastai.

Its the labels there’s an issue with the label matching data if am not mistaken. I have had to put a hold on my AI learning for now. So switched off and moved away from this.

Checkout the Kaggle page notebooks and see how they break the data down. That helped me a lot before I stopped this.

I have the same problem with the Whale competition when trying to call .fit() on the learner. Apparently there is no solution on these forums yet.

I think we can figure this out :slight_smile:

Can someone please share the first 2 - 3 rows from the input csv file? You can do head -n 3 file_name.csv in terminal to get this.

Also, could someone please read this into a dataframe and check the type of the label column? You can get this by doing type(df.loc[0, 'label_column_name'])

I did a little bit of investigating and I believe that the problem occurs when the number of classes in the validation set is greater than the number of classes in the training set.

3 Likes

Probably because of validation set not representing the whole class set. Moreover, since many of the classes have only a single sample in the dataset, when random validation split is done, few such samples go to validation set. Thereby, the training set also does not represent the corresponding classes. So, many of the classes stay only in validation set or training set.

1 Like

I think @Subhanandh and @francis are onto something. When I set val_idxs = 0, I am able to call learn.fit() with no error now.

1 Like

So does that mean in this case you’re training without a validation set?

If the problem is that there are too many classes with just one image (so training and validation sets contain different classes), couldn’t we do data augmentation, then use augmented data to create a validation set? Trying to figure it out now, but I’m still a pretty slow coder :slight_smile:

Does anyone have a update to this? I think it’s surprising that everyone on the fast.ai side of things is having issues; however nothing seems to be mentioned on the Kaggle forums.

You can see this topic

I spotted this thread linked over from the Kaggle competition and as a big fan of FastAI (recently spent many nights working through Part 2!) I thought I’d share my notebook which I got working. I didn’t actually hit the problems mentioned above, but hopefully someone will be able to see what I’ve done differently: https://github.com/jamesr2323/deep_learning/blob/master/experiments/whales_baseline.ipynb

Also before posting the notebook I updated FastAI to the latest commit on Github and hit an issue initialising the test set, which I’ve submitted a PR for https://github.com/fastai/fastai/pull/515 .If you have the same issue you can use that change as a temporary work-around.

4 Likes

Thanks @jamesrees for sharing your notebook, your data import worked for me and helped me avoid the below error when I tried lean.fit

RuntimeError: cuda runtime error (59) : device-side assert triggered

By creating a reference dictionary and replacing the given whale ids with integers I no longer encountered the assert error. So I guess as mentioned above there is an issue with dealing with the original labels given.

If I load the original label file [train.csv] straight into a pandas dataframe I get the below column types:

Image:    object
Id:       oject

Creating a reference dictionary and replacing the original whale Ids with integer labels allows my learn.fit to run without errors

Image:    object
Id:       int64

If anyone is getting the above error, try replacing the whale Id labels with Integer lables as per @jamesrees notebook here:

https://github.com/jamesr2323/deep_learning/blob/master/experiments/whales_baseline.ipynb

1 Like

I’ve just started working on the whale competition. I’m pretty new to this, but it looks like the grayscale images in the dataset are 3 channel images where R==G==B. I think this is why @jamesrees notebook works with resnet34 without needing to convert image channels.

Following some of the ideas in a Kaggle kernel on data processing for this competition (https://www.kaggle.com/lextoumbourou/humpback-whale-id-data-and-aug-exploration), I like the idea of creating 3 channel grayscale versions of all the color images as part of data augmentation.

It looks like torchvision has a function to do exactly this - see Grayscale and to_grayscale in https://pytorch.org/docs/master/torchvision/transforms.html

Is there a way to incorporate this in aug_tfms on tfms_from_model? Or would some other pipeline need to be developed?