MARS ROTATION
[Baseline] Mars Rotation Prediction
A getting started code for the Mars Rotation Prediction Challenge.
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
In [ ]:
data_folder = "data"
In [ ]:
train_df = pd.read_csv(os.path.join(data_folder, "train.csv"))
Visualize the data 👀¶
In [ ]:
train_df
In [ ]:
train_df['ImageID'] = train_df['ImageID'].astype(str)+".jpg"
train_df
TRAINING PHASE 🏋️¶
In [ ]:
dls = ImageDataLoaders.from_df(train_df, path=os.path.join(data_folder, "train"), bs=8, y_block=RegressionBlock)
dls.show_batch()
In [ ]:
learn = cnn_learner(dls, alexnet, metrics=mse)
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
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 [ ]:
test_dls.show_batch()
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})
submission
In [ ]:
submission.to_csv("submission.csv", index=False)
In [ ]:
!aicrowd submission create -c mars-rotation -f submission.csv
In [ ]:
Content
Comments
You must login before you can post a comment.
why is the ! and $ sign is used and why it has been highlighted?