Skip to content

Instantly share code, notes, and snippets.

View mythrex's full-sized avatar
🎯
Focusing

Shivam Kaushik mythrex

🎯
Focusing
View GitHub Profile
@mythrex
mythrex / cnn_visualisation.py
Created June 17, 2020 03:40
Plot kernel Visualisations and activvations
#custom function to conduct occlusion experiments
def occlusion(model, image, label, occ_size = 50, occ_stride = 50, occ_pixel = 0.5):
#get the width and height of the image
width, height = image.shape[-2], image.shape[-1]
#setting the output image width and height
output_height = int(np.ceil((height-occ_size)/occ_stride))
output_width = int(np.ceil((width-occ_size)/occ_stride))
@mythrex
mythrex / plot bounding box.py
Last active June 13, 2020 10:34
Plot bounding boxes on the image. Requires anchors which is a list of (bounding box, score, labels)
def make_bounding_box(img, anchors, colors, thickness=2):
'''
img -> (np.array) image array
anchors -> (list) list of anchor(bounding_box, score, label)
colors -> (list) list of colors for each label
thickness -> (int) thickness of font and bounding box
'''
img1 = np.array(img).copy()
bbs = list(map(lambda x: x[0], anchors))
scores = list(map(lambda x: x[1], anchors))
@mythrex
mythrex / non_max supression.py
Created June 13, 2020 10:30
Non Max Suppression
def get_iou(bb1, bb2):
assert bb1[0] < bb1[2]
assert bb1[1] < bb1[3]
assert bb2[0] < bb2[2]
assert bb2[1] < bb2[3]
# determine the coordinates of the intersection rectangle
x_left = max(bb1[0], bb2[0])
y_top = max(bb1[1], bb2[1])
x_right = min(bb1[2], bb2[2])
@mythrex
mythrex / get_iou.py
Created June 13, 2020 07:46
Gets Iou given two bounding boxes
def get_iou(bb1, bb2):
assert bb1[0] < bb1[2]
assert bb1[1] < bb1[3]
assert bb2[0] < bb2[2]
assert bb2[1] < bb2[3]
# determine the coordinates of the intersection rectangle
x_left = max(bb1[0], bb2[0])
y_top = max(bb1[1], bb2[1])
x_right = min(bb1[2], bb2[2])
@mythrex
mythrex / kaggle-dataset-download.sh
Created June 8, 2020 14:08
Download dataset to kaggle on colab
#/bin/bash
pip install kaggle
mkdir ~/.kaggle
cp kaggle.json ~/.kaggle/
chmod 600 ~/.kaggle/kaggle.json
kaggle datasets download -d iarunava/cell-images-for-detecting-malaria
@mythrex
mythrex / Global Contast Normalisation
Last active May 27, 2020 18:05
In this we normalise the contrast
def gcn(x, lambda_, s, epsilon=1e-8):
'''
Returns contrasted normalized img with added mean.
lambda_: constant added to variance
s: new std deviation of img
mu: img mean
'''
img = x.copy()
mu = img.mean()
img = img - mu
@mythrex
mythrex / concat
Created May 11, 2020 20:07
ffmpeg concat
ffmpeg -f concat -i files.txt -c copy output.mp4
@mythrex
mythrex / merge.sh
Created May 10, 2020 14:03
Merge two files
!#/bin/bash
mkvmerge -o outfile.mkv Scene0.mp4 \+ Scene1.mp4
@mythrex
mythrex / Merge Videos
Created May 10, 2020 13:20
Merge videos with ffmpeg
ffmpeg -i concat:"input1.mp4|input2.mp4" output.mp4
#!/bin/bash
gsettings set org.gnome.shell.extensions.dash-to-dock extend-height false
gsettings set org.gnome.shell.extensions.dash-to-dock dock-position BOTTOM
gsettings set org.gnome.shell.extensions.dash-to-dock transparency-mode FIXED
gsettings set org.gnome.shell.extensions.dash-to-dock dash-max-icon-size 64
gsettings set org.gnome.shell.extensions.dash-to-dock unity-backlit-items true