[Baseline] Mars Rotation Prediction

A getting started code for the Mars Rotation Prediction Challenge.

By Shubhamaicrowd


Getting Started Code for Mars Rotation Challenge on AIcrowd

Author : Shubhamai

Download Necessary Packages 📚

In [ ]:
!pip install --upgrade fastai
In [ ]:
!pip install -U aicrowd-cli

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 from [https://www.aicrowd.com/participants/me]
!aicrowd login --api-key $API_KEY
In [ ]:
!aicrowd dataset download --challenge mars-rotation
In [ ]:
!rm -rf data
!mkdir data

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

!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 *
from fastai.data.core 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 [ ]:
data_folder = "data"
In [ ]:
train_df = pd.read_csv(os.path.join(data_folder, "train.csv"))

Visualize the data 👀

In [ ]:
In [ ]:
train_df['ImageID'] = train_df['ImageID'].astype(str)+".jpg"


In [ ]:
dls = ImageDataLoaders.from_df(train_df, path=os.path.join(data_folder, "train"), bs=8, y_block=RegressionBlock)
In [ ]:
learn = cnn_learner(dls, alexnet, metrics=mse)

Train the Model

In [ ]:

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

Load Test Set

Load the test data on which final submission is to be made.

In [ ]:
test_imgs_name = get_image_files(os.path.join(data_folder, "test"))
test_dls = dls.test_dl(test_imgs_name)

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

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

Save the prediction to csv

🚧 Note :

  • Do take a look at the submission format.
  • The submission file should contain a header.
  • Follow all submission guidelines strictly to avoid inconvenience.
In [ ]:
submission = pd.DataFrame({"ImageID":test_img_ids, "label":results})
In [ ]:
submission.to_csv("submission.csv", index=False)
In [ ]:
!aicrowd submission create -c mars-rotation -f submission.csv
In [ ]:

↕️  Read More

Liked by  


You must login before you can post a comment.