Loading

CHESS POINTS

[Baseline] Chess Points

A getting started code for the Chess Points challenge.

ashivani

AIcrowd-Logo

Getting Started Code for Chess Points on AIcrowd

Author : Shubhamai

Download Necessary Packages 📚

In this baseline we are going to use FastAI as our main library to train out model and making & submitting predictions

In [ ]:
!pip install --upgrade fastai git+https://gitlab.aicrowd.com/yoogottamk/aicrowd-cli.git >/dev/null
%load_ext aicrowd.magic

Download Data

The first step is to download out train test data. We will be training a model on the train data and make predictions on test data. We submit our predictions.

In [ ]:
API_KEY = '' #Please enter your API Key [https://www.aicrowd.com/participants/me]
%aicrowd login --api-key $API_KEY
In [ ]:
%aicrowd dataset download --challenge chess-points -j 3
In [ ]:
!rm -rf data
!mkdir data

!unzip train.zip  -d data/ 
!unzip val.zip -d data/ 
!unzip test.zip  -d data/ 

!mv train.csv data/train.csv
!mv val.csv data/val.csv
!mv sample_submission.csv data/sample_submission.csv

Import packages

In [ ]:
import pandas as pd
from fastai.vision.all import *
import os

Load Data

  • We use pandas ๐Ÿผ library to load our data.
  • Pandas loads the data into dataframes and facilitates us to analyse the data.
  • Learn more about it here ๐Ÿค“
In [ ]:
train_df = pd.read_csv("data/train.csv")

Visualize the data 👀

In [ ]:
train_df
In [ ]:
train_df['ImageID'] = train_df['ImageID'].astype(str)+".jpg"
train_df
In [ ]:
dls = ImageDataLoaders.from_df(train_df, path="data/train", bs=8)
dls.show_batch()

TRAINING PHASE 🏋️

In [ ]:
learn = cnn_learner(dls, alexnet, metrics=F1Score())

Train the Model

In [ ]:
learn.fine_tune(1)

Testing Phase 😅

We are almost done. We trained and validated on the training data. Now its the time to predict on test set and make a submission.# Prediction on Evaluation Set

Predict Test Set

Predict on the test set and you are all set to make the submission!

In [ ]:
test_imgs_name = get_image_files("data/test")
test_dls = dls.test_dl(test_imgs_name)

label_to_class_mapping = {v: k for v, k in enumerate(dls.vocab)}
print(label_to_class_mapping)

test_img_ids = [re.sub(r"\D", "", str(img_name)) for img_name in test_imgs_name]
In [ ]:
test_dls.show_batch()
In [ ]:
_,_,results = learn.get_preds(dl = test_dls, with_decoded = True)

results = [label_to_class_mapping[i] for i in results.numpy()]

Save the prediction to csv

In [ ]:
submission = pd.DataFrame({"ImageID":test_img_ids, "label":results})
submission
In [ ]:
submission.to_csv("submission.csv", index=False)

🚧 Note :

  • Do take a look at the submission format.
  • The submission file should contain a header.
  • Follow all submission guidelines strictly to avoid inconvenience.

To download the generated csv in colab run the below command

In [ ]:
try:
    from google.colab import files
    files.download('submission.csv') 
except:
    print("Option Only avilable in Google Colab")

Well Done! 👍 We are all set to make a submission and see your name on leaderborad. Let navigate to challenge page and make one.


Comments

demarsylvain
Over 3 years ago

Hi @ashivani,

You used this line of code in order to load the dataset in the Colab environment: %aicrowd dataset download โ€“challenge chess-points -j 3

Is it possible to modify it a little in order to load only one file, for instance train.zip? Thank you in advance.

You must login before you can post a comment.

Execute