Environment Classification
[Getting Started Notebook] Environment Classification
A Getting Started notebook for Environment Classification Puzzle of BlitzXI.
Starter Code for Environment Classification
In this challenge, you will have images of a self driving car moving through a town in different weather conditions. Your goal will be to classify the environment into 5 different classes ( using unsupervised methonds ), 1 means the weather is really good for a self driving car while 5 means the weather is very challenging for a self driving car.
What we are going to Learn¶
- Unsupvised Image Classification
Note : Create a copy of the notebook and use the copy for submission. Go to File > Save a Copy in Drive to create a new copy
Downloading Dataset¶
So we will first need to login to AIcrowd that will allow us to download the dataset after the API key is validated and saved.
!pip install aicrowd-cli
%load_ext aicrowd.magic
%aicrowd login
# Downloading the Dataset
!rm -rf data
!mkdir data
%aicrowd ds dl -c environment-classification -o data
# Unzipping and Organising the datasets
!unzip data/images.zip -d data/images > /dev/null
Importing Libraries¶
import pandas as pd
from sklearn.cluster import KMeans
import seaborn as sns
from glob import glob
from natsort import natsorted
import cv2
import os
import numpy as np
import random
from PIL import Image
Visualize the data 👀¶
images_folder = "data/images"
images_list = natsorted(glob(images_folder+"/*"))
img = Image.open(random.choice(images_list))
img
Loading the dataset¶
images_data = np.array([cv2.imread(image_path, 0).flatten() for image_path in images_list])
images_data.shape
Creating the model¶
Here, we will be using KMeans from sklearn model which is used in unsupervised data classification
# Number of classes
model = KMeans(n_clusters=5, n_jobs=-1)
model
Training the model¶
model.fit(images_data)
Generating the predictions¶
predictions = model.predict(images_data)
predictions.shape
df = pd.DataFrame({"ImageID":range(len(images_data)), "label":predictions})
df['ImageID'] = df["ImageID"].astype(int)
df = df.sort_values("ImageID").reset_index(drop=True)
df
Submitting Results 📄¶
!rm -rf assets
!mkdir assets
df.to_csv(os.path.join("assets", "submission.csv"), index=False)
Note : Please make sure that there should be filename submission.csv
in assets
folder before submitting it
Uploading the Results¶
!aicrowd notebook submit -c environment-classification -a assets --no-verify
Content
Comments
You must login before you can post a comment.