Skip to content

Instantly share code, notes, and snippets.

View nfsrules's full-sized avatar

nfsrules nfsrules

  • Paris region
View GitHub Profile
@nfsrules
nfsrules / functions.py
Last active April 19, 2018 12:27
Display activations functions
# Default Python's libraries
import os
import numpy as np
import pandas as pd
from tqdm import tqdm
import keras.backend as K
# Graphic libraries
@nfsrules
nfsrules / opencv_add.py
Created April 19, 2018 12:09
OpenCV bitwise add operation
# Convert RGB to BGR. (optional)
dst_map = cv2.cvtColor(dst_map, cv2.COLOR_RGB2BGR)
# Add feature map and original image
merged_img = cv2.add(dst_map, cropped_img)
@nfsrules
nfsrules / video_writing.py
Last active June 18, 2019 12:42
Video writing with OpenCV
# Create video writer
writer = cv2.VideoWriter("sample_output.avi",
cv2.VideoWriter_fourcc(*"MJPG"),
30,(1800,480))
for frame in tqdm(merged_maps):
writer.write(frame.astype('uint8'))
writer.release()
@nfsrules
nfsrules / image_merging.py
Last active April 19, 2018 13:00
Extract relevant activations from a feature map
# Get numpy array from matplotlib figure
target_map = get_figure(target_map, cmap='inferno').astype('uint8')
# Crop unnecessary regions from canvas
target_map = crop(target_map,9,63,33,232)
# Resize to original image size
target_map = cv2.resize(target_map,(1800,480), interpolation = cv2.INTER_CUBIC)
# Create a binary mask. You may want to change the binary threshold
@nfsrules
nfsrules / pre_processing.py
Last active April 19, 2018 12:05
Script to preprocess input image and get a feature map
def pre_process(img):
""" Prepare image to be feed to a Keras convolutive model.
img: 3-channel Numpy array image of size.
Returns a resized and smoothed 250x70 RGB image.
"""
# Crop relevant area from input image
img = crop(img,600,1080,0,1800)
# Resize to model's input size (250,70)
img = cv2.resize(img,(250,70), interpolation = cv2.INTER_LANCZOS4)#INTER_CUBIC)