Lidar Car Detection
Solution for Lidar Car Detection
A detailed solution for submission 155659 submitted for challenge Lidar Car Detection
Starter Code for Lidar Car Detection
What we are going to Learn¶
- Learning about how lidar works
- Using scikit-learn for binary 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¶
Installing aicrowd-cli
In [4]:
!pip install aicrowd-cli
%load_ext aicrowd.magic
In [5]:
%aicrowd login
In [3]:
!rm -rf data
!mkdir data
%aicrowd ds dl -c lidar-car-detection -o data
Importing Libraries¶
In [6]:
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
import os
import matplotlib.pyplot as plt
import plotly.graph_objects as go
import random
Reading the dataset¶
In [7]:
# Reading the training dataset
train_data = np.load("/content/data/train.npz", allow_pickle=True)
train_data = train_data['train']
train_data.shape
Out[7]:
Visualizing the dataset¶
In this section, we will be visualizing a sample 3D lidar data
In [ ]:
# Getting a random 3D lidar sample data
INDEX = random.randint(0, train_data.shape[0])
# Getting the individual x,y and z points.
x = train_data[INDEX][0][:, 0].tolist()
y = train_data[INDEX][0][:, 1].tolist()
z = train_data[INDEX][0][:, 2].tolist()
# Label for the corrosponding sample ( no. of cars )
label = train_data[INDEX][1]
# Generating the 3D graph
fig = go.Figure(data=[go.Scatter3d(x=x, y=y, z=z,
mode='markers',
marker=dict(
size=1,
colorscale='Viridis',
opacity=0.8))])
print("No. of cars : ", label)
fig.show()
Can you try finding cars in this 3d data ?
Splitting the dataset¶
In [9]:
# Getting the 3d points and flattening the points into 1d array ( using only 100 training samples for faster teaining )
X = train_data[:, 0]
X = [i.flatten() for i in X]
# labels
y = train_data[:, 1]
In [10]:
# Splitting the dataset into training and testing
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2)
Training the model¶
In [11]:
model = RandomForestRegressor(verbose=True, n_jobs=-1)
In [12]:
model.fit(X_train, y_train)
Out[12]:
Validation¶
In [13]:
model.score(X_val, y_val)
Out[13]:
Generating the predictions¶
In [14]:
# Loading the test data
test_data = np.load("/content/data/test.npz", allow_pickle=True)
test_data = test_data['test']
test_data.shape
Out[14]:
In [15]:
# flattening the points into 1d array
X_test = X = [i.flatten() for i in test_data]
In [16]:
# Generating the predictions
predictions = model.predict(X_test)
predictions.shape
Out[16]:
In [17]:
submission = pd.DataFrame({"label":predictions})
submission
Out[17]:
In [18]:
# Saving the predictions
!rm -rf assets
!mkdir assets
submission.to_csv(os.path.join("assets", "submission.csv"))
Submitting our Predictions¶
Note : Please save the notebook before submitting it (Ctrl + S)
In [ ]:
In [ ]:
Content
Comments
You must login before you can post a comment.