Skip to content

Instantly share code, notes, and snippets.

View gyglim's full-sized avatar

Michael Gygli gyglim

View GitHub Profile
@Namburger
Namburger / tflite_cv_objdetect.py
Last active March 29, 2024 11:31
An example with opencv/tflite object detection combo
import os
import argparse
import cv2
import numpy as np
import sys
import time
import importlib.util
from tflite_runtime.interpreter import Interpreter
from tflite_runtime.interpreter import load_delegate
@bookjan
bookjan / face-detection.py
Last active January 18, 2022 08:02
Using python opencv to detect face and send the frames to FFmpeg to create HLS(HTTP Live Streaming)
import numpy as np
import cv2
import sys
cap = cv2.VideoCapture(0)
face_cascade = cv2.CascadeClassifier('<PATH_TO_CASCADES_FOLDER>/haarcascade_frontalface_default.xml')
while(True):
# Capture frame-by-frame
@zeryx
zeryx / tensorflow_preload.py
Last active September 7, 2017 20:06
performance improvements with tensorflow & algorithmia
# This code example describes how to pre-load a tensorflow graph file
# into an Algorithmia container and load the graph into memory.
# This approach allows us to preserve the graph in system memory between API calls,
# Improving overall performance.
# We also document how to evict the tensorflow GPU memory context between API requests by
# moving it to a separate thread, and how to define the amount of GPU memory an algorithm uses.
# These GPU tweaks significantly improve performance on Algorithmia's infrastructure
import Algorithmia
@kingjr
kingjr / hinge_vs_loss.py
Last active August 25, 2020 01:47
Illustrate how SVM and Logistic Regression are very similar except that SVM strictly relies on a subset of the data.
# Author: Jean-Remi King <jeanremi.king@gmail.com>
"""
Illustrate how a hinge loss and a log loss functions
typically used in SVM and Logistic Regression
respectively focus on a variable number of samples.
For simplification purposes, we won't consider the
regularization or penalty (C) factors.
"""
import numpy as np
import matplotlib.animation as animation
# Context manager to generate batches in the background via a process pool
# Usage:
#
# def batch(seed):
# .... # generate minibatch
# return minibatch
#
# with BatchGenCM(batch) as bg:
# minibatch = next(bg)
# .... # do something with minibatch
@ebenolson
ebenolson / draw_net.py
Created March 27, 2015 23:01
Functions to draw Lasagne networks with graphviz, like Caffe's draw_net.py
"""
Functions to create network diagrams from a list of Layers.
Examples:
Draw a minimal diagram to a pdf file:
layers = lasagne.layers.get_all_layers(output_layer)
draw_to_file(layers, 'network.pdf', output_shape=False)
Draw a verbose diagram in an IPython notebook: