Skip to content

Instantly share code, notes, and snippets.

View Mehdi-Amine's full-sized avatar
💭
Having fun with Neural Networks

Mehdi Mehdi-Amine

💭
Having fun with Neural Networks
View GitHub Profile
@Mehdi-Amine
Mehdi-Amine / two_moons.py
Last active November 8, 2023 08:24
generating and visualizing a dataset using Scikit-learn and the make_moons() function
# 1- Generating a dataset.
from sklearn.datasets import make_moons
# X are the generated instances, an array of shape (500,2).
# y are the labels of X, with values of either 0 or 1.
X, y = make_moons(n_samples=500, noise=0.3, random_state=42)
# 2- Visualizing the dataset.
from matplotlib import pyplot as plt
@Mehdi-Amine
Mehdi-Amine / perceptron-class.py
Last active June 26, 2023 08:46
perceptron class
class Perceptron:
def __init__(self, input_size):
np.random.seed(42)
self.sizes = [input_size, 1]
self.bias = np.random.randn(1, 1)
self.weights = np.random.randn(1, input_size)
# used for plotting convergence
self.parameters_as_they_change = [np.concatenate((self.bias[0], self.weights.squeeze()), axis=0)]
print("Generated Perceptron:")
@Mehdi-Amine
Mehdi-Amine / inference-vid.py
Created November 5, 2021 16:23
pytorch-auto-drive inference on videos
!python visualize_lane.py --image-path=IMAGE_PATH
--save-path=SAVE_PATH
--method=baseline
--backbone=erfnet
--dataset=tusimple
--continue-from=erfnet_baseline_tusimple_20210424.pt
--height=360
--width=640
@Mehdi-Amine
Mehdi-Amine / inference.py
Created November 5, 2021 16:17
pytorch-auto-drive inference
from visualize_lane import *
!python visualize_lane.py --image-path=IMAGE_PATH
--save-path=SAVE_PATH
--method=baseline
--backbone=erfnet
--dataset=culane
--continue-from=erfnet_baseline_culane_20210204.pt
--height=288
--width=800
@Mehdi-Amine
Mehdi-Amine / dependencies.py
Created November 5, 2021 16:13
pytorch-auto-drive colab dependencies
!pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html
!pip install mmcv
!pip install ujson
!pip install filetype
@Mehdi-Amine
Mehdi-Amine / clone-pad.py
Created November 5, 2021 16:05
Cloning the git repository to set up colab nb environment
from google.colab import drive
drive.mount('/content/gdrive')
%cd gdrive/MyDrive/auto-drive/pytorch-auto-drive/
!git clone https://github.com/voldemortX/pytorch-auto-drive.git
@Mehdi-Amine
Mehdi-Amine / hough-transform.py
Created November 5, 2021 15:30
Hough lines from the cropped image
lines = cv2.HoughLinesP(cropped_image, 2, np.pi/180, 100, np.array([]), minLineLength=40, maxLineGap=5)
@Mehdi-Amine
Mehdi-Amine / roi.py
Created November 5, 2021 15:04
cropping the region of interest
def region_of_interest(image):
height = image.shape[0]
width = image.shape[1]
polygons = np.array([[(10,height), (width,height), (width,1100), (630, 670), (10, 1070)]])
mask = np.zeros_like(image)
cv2.fillPoly(mask, polygons, 255)
masked_image = cv2.bitwise_and(image, mask)
return masked_image
@Mehdi-Amine
Mehdi-Amine / canny.py
Created November 5, 2021 14:58
canny edge detection
def canny(image):
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
blur = cv2.GaussianBlur(gray, (5, 5), 0)
canny = cv2.Canny(blur, 10, 30)
return canny
@Mehdi-Amine
Mehdi-Amine / normal-scale.py
Created June 24, 2020 14:37
method to return the false negatives and false positives to their normal scale for inspection
def inverse_scale_for(fp_cases, fn_cases):
# Converting to Numpy to be compatible with Sklearn
fp_cases = x_test[fp_indx].numpy()
fn_cases = x_test[fn_indx].numpy()
# Inverse transformation for the columns that were scaled: tea temp + internet speed
fp_cases_inv = std_scaler.inverse_transform(fp_cases[:,:2])
fn_cases_inv = std_scaler.inverse_transform(fn_cases[:,:2])
# Concatenating the now normally scaled columns with the book column