Skip to content

Instantly share code, notes, and snippets.

View NISH1001's full-sized avatar
💭
Staring into the abyss...

Nish NISH1001

💭
Staring into the abyss...
View GitHub Profile
@NISH1001
NISH1001 / splitter.py
Created November 24, 2018 14:45
Create train-test directories
#!/usr/bin/env python3
import glob
from collections import defaultdict
import shutil
import os
def create_dir(dirname):
if not os.path.isdir(dirname):
os.mkdir(dirname)
@NISH1001
NISH1001 / colorized_voronoi.py
Created December 7, 2018 01:22 — forked from pv/colorized_voronoi.py
Colorized Voronoi diagram with Scipy, in 2D, including infinite regions
import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import Voronoi
def voronoi_finite_polygons_2d(vor, radius=None):
"""
Reconstruct infinite voronoi regions in a 2D diagram to finite
regions.
Parameters
@NISH1001
NISH1001 / voronoi.py
Created December 8, 2018 04:01
Compute voronoi diagram for given list of points
# coords => List of tuple => [(x1, y1), ....(xn, yn)]
def voronoi(coords, width=800, height=800, use_max=False):
coord_matrix = np.array(coords)
X, Y = zip(*coords)
if use_max:
w, h = max(X) + 2, max(Y) + 2
else:
w, h = width, height
print("Computing voronoi diagram of size :: {}, {}".format(w, h))
@NISH1001
NISH1001 / noise-reduction.md
Created December 10, 2018 05:59
Remove noise from audio track

First Create Noise Profile

This is done using ffmpeg:

ffmpeg -i source.mp3 -vn -ss 00:00:18 -t 00:00:20 noisesample.wav

Create Noise Profile for Sox

sox noisesample.wav -n noiseprof noise_profile_file
@NISH1001
NISH1001 / audio-replacer.sh
Created December 11, 2018 14:34
replace audio in video
ffmpeg -i source_video -i source_audio -c:v copy -map 0:v:0 -map 1:a:0 output_video
@NISH1001
NISH1001 / git-shit.md
Last active December 16, 2019 08:41
Rebase and Merge

Suppose there are 2 branches: master and feature

Squash Commits in Feature

  • git checkout feature
  • git rebase feature -i

This will open editor in interactive mode. DIfferent options like pick and squash are available

Rebase Feature into master without squash

First use rebase command standing in the feature branch.

@NISH1001
NISH1001 / keras-activation-visualization-cnn.md
Created January 12, 2019 14:42
visualize activation at different layers in CNN in Keras

First get list of all the layers (after activation).

from keras.models import Model
layer_outputs = [layer.output for layer in model.layers]

Predict image and get corresponding activation in each layer

activation_model = Model(inputs=model.input, outputs=layer_outputs)
@NISH1001
NISH1001 / imagenet1000_clsid_to_human.txt
Created January 13, 2019 09:23 — forked from yrevar/imagenet1000_clsidx_to_labels.txt
text: imagenet 1000 class id to human readable labels (Fox, E., & Guestrin, C. (n.d.). Coursera Machine Learning Specialization.)
{0: 'tench, Tinca tinca',
1: 'goldfish, Carassius auratus',
2: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias',
3: 'tiger shark, Galeocerdo cuvieri',
4: 'hammerhead, hammerhead shark',
5: 'electric ray, crampfish, numbfish, torpedo',
6: 'stingray',
7: 'cock',
8: 'hen',
9: 'ostrich, Struthio camelus',
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from rasa_nlu.featurizers import Featurizer
import tensorflow_hub as hub
import tensorflow as tf
class UniversalSentenceEncoderFeaturizer(Featurizer):
"""Appends a universal sentence encoding to the message's text_features."""
# URL of the TensorFlow Hub Module