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 / 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
@Mehdi-Amine
Mehdi-Amine / precision-recall-accuracy.py
Last active June 24, 2020 14:15
accuracy of a happy neural network hopefully
def precision(tp, fp):
return tp / (tp + fp)
print(f"Precision: {precision(tp, fp)}")
def recall(tp, fn):
return tp / (tp + fn)
print(f"Recall: {recall(tp, fn)}")
def accuracy(tp, fp, tn, fn):
return (tp + tn) / (tp + fp + tn + fn)
@Mehdi-Amine
Mehdi-Amine / recall.py
Created June 23, 2020 21:49
recall of a happy neural network
def recall(tp, fn):
return tp / (tp + fn)
print(f"Recall: {recall(tp, fn)}")
'''
Out:
Recall: 0.9677852348993289
'''