Fbeta score on iWildCam kaggle dataset

(Alhamede Abdelgadir) #1

Hi

I have been trying to practice using the fastai library on the kaggle dataset for iWildCam. Since the metric they used was the F1 score I wanted to try it too using the fastai ‘fbeta’ function. However I faced the error below

RuntimeError: The size of tensor a (14) must match the size of tensor b (64) at non-singleton dimension 1

Below are some code snippets of how I prepared the databunch

data = (ImageList.from_df(train_lbl, path/‘train_images’)
.split_subsets(train_size=0.03, valid_size=0.005) # select percentage of training and validation datasets
.label_from_df(cols=‘category_id’)
.transform(size=64)
.databunch(bs=64))

The learner is as below

f_score = partial(fbeta, thresh=0.2)
learn = create_cnn(data, models.resnet34, model_dir=’/kaggle/working’, metrics=[error_rate, accuracy, f_score])

Not sure if this will also help but I extracted the labels in the following way

train_df = pd.read_csv(path/‘train.csv’)
train_lbl = train_df[[‘file_name’, ‘category_id’]]

0 Likes

(Alhamede Abdelgadir) #2

Solved it, I used ‘Fbeta()’ instead of fbeta as given below

learn = create_cnn(data, models.densenet121, model_dir='/kaggle/working', metrics=[error_rate, accuracy, FBeta(beta=1)])
0 Likes