Skip to content

Instantly share code, notes, and snippets.

@erogol
erogol / loader.py
Created March 8, 2017 13:59
multiprocess data loader template for keras or any other
# Modified 2016-06-30 by Josiah Olson to add python3 support
# 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)
from __future__ import absolute_import
from __future__ import print_function
import numpy as np
from keras.models import Sequential, Model
from keras.layers import Dense, Dropout, Lambda, merge, BatchNormalization, Activation, Input, Merge
from keras import backend as K
def euclidean_distance(vects):
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@erogol
erogol / face_landmark_detection_by_8bit.ipynb
Created June 23, 2016 14:29
8bit.ai Face Landmark Detection tutorial
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@erogol
erogol / Notebook2WP.html
Created June 21, 2016 10:29
Add Iptyhon Notebook to Wordpress
<script type="text/javascript">// <![CDATA[
function resizeIframe(ifrm) { ifrm.style.height = ifrm.contentWindow.document.body.scrollHeight + 'px'; // Setting the width here, or setting overflowX to "hidden" as above both // work for this page. It may be that one turns out to be better. ifrm.style.width = ifrm.contentWindow.document.body.scrollWidth + 'px'; }
// ]]></script>
<script type="text/javascript">// <![CDATA[
function onLoad() { var ifrm = document.getElementById('ipython_notebook_frame'); setTimeout(resizeIframe, 0, ifrm); }
// ]]></script>
<div class="cell border-box-sizing text_cell rendered">
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
@erogol
erogol / timeout_example.py
Created June 15, 2016 14:33
How to define a timeout to custom functions
import errno
import os
import signal
import time
class TimeoutError(Exception):
pass
class timeout:
def __init__(self, seconds=1, error_message='Timeout'):
@erogol
erogol / DeepResidualNetMxNet.py
Created March 4, 2016 11:51
DeepResidualNet model defined by mxnet
# coding: utf-8
# # DressRank traning
# In[ ]:
import mxnet as mx
from mxnet.utils import *
import logging
#include<opencv2/opencv.hpp>
#include<opencv2/imgproc.hpp>
#include<opencv2/imgcodecs/imgcodecs.hpp>
#include<opencv2/videoio.hpp>
#include<iostream>
#include<vector>
int main(int argc, char *argv[])
{
cv::Mat frame;
@erogol
erogol / CaffeBatchPrediction.cpp
Created July 13, 2015 12:54
Caffe c++ batch based prediction
#include "caffeclassifier.h"
CaffeClassifier::CaffeClassifier(const string& model_file,
const string& trained_file,
const string& mean_file,
const string& label_file,
const bool use_GPU,
const int batch_size) {
if (use_GPU)
Caffe::set_mode(Caffe::GPU);