Skip to content

Instantly share code, notes, and snippets.

View vgoklani's full-sized avatar

Vishal Goklani vgoklani

View GitHub Profile
@pieceofsummer
pieceofsummer / parser.py
Created September 16, 2017 23:26
Google Wifi diagnostic report parser
#!/usr/bin/python
import os, sys, gzip
from StringIO import StringIO
from datetime import datetime
def readByte(f):
return ord(f.read(1))
def readInt(f):
l = 0
cimport cython
import numpy as np
cimport numpy as np
from sklearn.metrics import f1_score
@cython.boundscheck(False)
@cython.wraparound(False)
def f1_opt(np.ndarray[long, ndim=1] label, np.ndarray[double, ndim=1] preds):
@timehaven
timehaven / akmtdfgen.py
Last active August 24, 2023 17:14
kmtdfgen: Keras multithreaded dataframe generator
"""akmtdfgen: A Keras multithreaded dataframe generator.
Works with Python 2.7 and Keras 2.x.
For Python 3.x, need to fiddle with the threadsafe generator code.
Test the generator_from_df() functions by running this file:
python akmtdfgen.py
@Tushar-N
Tushar-N / pad_packed_demo.py
Last active December 27, 2022 06:35
How to use pad_packed_sequence in pytorch<1.1.0
import torch
import torch.nn as nn
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
seqs = ['gigantic_string','tiny_str','medium_str']
# make <pad> idx 0
vocab = ['<pad>'] + sorted(set(''.join(seqs)))
# make model
@swyoon
swyoon / np_to_tfrecords.py
Last active November 29, 2022 06:39
From numpy ndarray to tfrecords
import numpy as np
import tensorflow as tf
__author__ = "Sangwoong Yoon"
def np_to_tfrecords(X, Y, file_path_prefix, verbose=True):
"""
Converts a Numpy array (or two Numpy arrays) into a tfrecord file.
For supervised learning, feed training inputs to X and training labels to Y.
For unsupervised learning, only feed training inputs to X, and feed None to Y.
from graphviz import Digraph
import torch
from torch.autograd import Variable, Function
def iter_graph(root, callback):
queue = [root]
seen = set()
while queue:
fn = queue.pop()
if fn in seen:
@spro
spro / pytorch-simple-rnn.py
Last active April 25, 2022 10:50
PyTorch RNN training example
import torch
import torch.nn as nn
from torch.nn import functional as F
from torch.autograd import Variable
from torch import optim
import numpy as np
import math, random
# Generating a noisy multi-sin wave
import torch
import torchvision
import torch.nn as nn
import torch.nn.functional as F
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
import numpy as np
import torch.optim as optim
from torch.autograd import Variable

Install dlib and face_recognition on a Raspberry Pi

Instructions tested with a Raspberry Pi 2 with an 8GB memory card. Probably also works fine on a Raspberry Pi 3.

Steps

Download the latest Raspbian Jessie Light image. Earlier versions of Raspbian won't work.

Write it to a memory card using Etcher, put the memory card in the RPi and boot it up.

@Dref360
Dref360 / TFQueueKeras.py
Last active March 16, 2020 02:24
An example of using keras with tf queues, this handle BatchNorm
import operator
import threading
from functools import reduce
import keras
import keras.backend as K
from keras.engine import Model
import numpy as np
import tensorflow as tf
import time