AUTODRI
[Getting Started Notebook] AUTODRI Challange
This is a Baseline Code to get you started with the challenge.
You can use this code to start understanding the data and create a baseline model for further imporvments.
Baseline for AUTODRI Challenge on AIcrowd¶
Author : Gauransh Kumar¶
Download Necessary Packages¶
In [1]:
!pip install numpy
!pip install pandas
!pip install scikit-learn
!pip install matplotlib tqdm
!pip install aicrowd-cli
%load_ext aicrowd.magic
In [2]:
%aicrowd login
Download data¶
The first step is to download the training data and the test data
In [3]:
# #Donwload the datasets
!rm -rf data
!mkdir data
%aicrowd ds dl -c autodri -o data
In [8]:
import shutil
# extracting validation zip
shutil.unpack_archive("./data/val.zip", "./data/")
# extracting train zip
shutil.unpack_archive("./data/train.zip", "./data/")
# extracting test zip
shutil.unpack_archive("./data/test.zip", "./data/")
In [9]:
## Now the data is available at the following locations:
TRAINING_IMAGES_FOLDER = "data/train/cameraFront"
TRAINING_LABELS_PATH = "data/train/train.csv"
TESTING_LABELS_PATH = "data/test/test.csv"
TESTING_IMAGES_FOLDER = "data/test/cameraFront"
# For this baseline, we will only be using the front camera angle of the car just for demonstration purpose. For actual one should try and see the best combination of all the angles
Import packages¶
In [10]:
import sys
import os
import tqdm
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPRegressor
from sklearn.metrics import mean_squared_error,mean_absolute_error
import matplotlib.pyplot as plt
%matplotlib inline
from PIL import Image
Load Data¶
We use PIL library to load our images. Here we are creating our array where our input features are the mean colours and output features are the rotations along the x axis.
In [11]:
training_labels_df = pd.read_csv(TRAINING_LABELS_PATH)
def pre_process_data_X(image):
"""
This file takes a loaded image and returns a particular
representation of the data point
NOTE: This current baseline implements a **very** silly approach
of representing every image by the mean RGB values for every image.
You are encourage to try to alternate representations of the data,
or figure out how to learn the best representation from the data ;)
"""
im_array = np.array(im)
mean_rgb = im_array.mean(axis=(0, 1))
return mean_rgb
ALL_DATA = []
for _idx, row in tqdm.tqdm(training_labels_df.iterrows(), total=training_labels_df.shape[0]):
filepath = os.path.join(
TRAINING_IMAGES_FOLDER,
row.filename
)
im = Image.open(filepath)
data_X = pre_process_data_X(im)
data_Y = [row.canSteering]
ALL_DATA.append((data_X, data_Y))
Exploratory Data Analysis¶
We now see the kind of images the dataset contains to get a better idea.
In [12]:
plt.figure(figsize=(20,20))
for i in range(16):
filename,xRot = training_labels_df.iloc[i]
filepath = os.path.join(
TRAINING_IMAGES_FOLDER,
filename
)
im = Image.open(filepath)
plt.subplot(4,4,i+1)
plt.axis('off')
plt.title("canSteering: %.3f"%(xRot))
plt.imshow(im)