Lidar Car Detection
[Getting Started Notebook] Lidar Car Detection
A Getting Started notebook for Car Detection using Lidar Puzzle of BlitzXI.
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 [ ]:
!pip install aicrowd-cli
%load_ext aicrowd.magic
In [ ]:
%aicrowd login
In [ ]:
!rm -rf data
!mkdir data
%aicrowd ds dl -c lidar-car-detection -o data
Importing Libraries¶
In [ ]:
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 [ ]:
# Reading the training dataset
train_data = np.load("/content/data/train.npz", allow_pickle=True)
train_data = train_data['train']
train_data.shape
Out[ ]:
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 [ ]:
# Getting the 3d points and flattening the points into 1d array ( using only 100 training samples for faster teaining )
X = train_data[:100, 0]
X = [i.flatten() for i in X]
# labels
y = train_data[:100, 1]
In [ ]:
# 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 [ ]:
model = RandomForestRegressor(verbose=True, n_jobs=-1)
In [ ]:
model.fit(X_train, y_train)
Out[ ]:
Validation¶
In [ ]:
model.score(X_val, y_val)
Out[ ]:
Generating the predictions¶
In [ ]:
# Loading the test data
test_data = np.load("/content/data/test.npz", allow_pickle=True)
test_data = test_data['test']
test_data.shape
Out[ ]:
In [ ]:
# flattening the points into 1d array
X_test = X = [i.flatten() for i in test_data]
In [ ]:
# Generating the predictions
predictions = model.predict(X_test)
predictions.shape
Out[ ]:
In [ ]:
submission = pd.DataFrame({"label":predictions})
submission
Out[ ]:
In [ ]:
# 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 [ ]:
!aicrowd notebook submit -c lidar-car-detection -a assets --no-verify
In [ ]:
Content
Comments
You must login before you can post a comment.
Just a small mistake, we are using scikit-learn for regression
Comment deleted by eric_parisot.