Skip to content

Instantly share code, notes, and snippets.

View datitran's full-sized avatar

Dat Tran datitran

View GitHub Profile
import falcon
class HelloResource:
def on_get(self, req, resp):
resp.status = falcon.HTTP_200
resp.body = 'Hello World!'
api = falcon.API()
api.add_route('/', HelloResource())
import os
import falcon
from keras.models import load_model
from .predict import PredictResource
api = application = falcon.API()
def load_trained_model():
global model
import base64
import json
import falcon
import numpy as np
from io import BytesIO
from PIL import Image, ImageOps
def convert_image(image):
img = Image.open(image).convert('L')
Framework # requests # failures Median response time Average response time Min response time Max response time Average Content Size Requests/s
Falcon 10055 0 26 66 19 2094 19 28.35
Flask 10871 0 26 60 19 1927 19 28.40
@datitran
datitran / object_detection_app.py
Created July 31, 2017 08:16
Object Recognition App with Video as Source
import os
import cv2
import time
import numpy as np
import tensorflow as tf
from utils import FPS
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
@datitran
datitran / README.md
Created March 21, 2017 15:24 — forked from Amit-PivotalLabs/README.md
Spark on Cloud Foundry

Spark on Cloud Foundry

This document describes one means of running a simple Apache Spark cluster on Cloud Foundry. It makes heavy use of Cloud Foundry's container networking features.

You can see an example running at http://spark-ui-proxy.184.73.108.92.xip.io.

Deploy BOSH-Lite on AWS

This cluster was deployed using BOSH-Lite on AWS. Note, this Director cannot be targetted with the new BOSH CLI (see cloudfoundry-attic/bosh-lite#424), but you can use the "old" Ruby CLI just fine. You can use the new CLI for local workflows like manifest interpolation, and then the "old" CLI for remote workflows like deploying and SSH.

@datitran
datitran / mnist_gpu_test_script.py
Created December 22, 2016 09:39
Test script for CUDA/cuDNN
import numpy as np
np.random.seed(1337)
from keras.datasets import mnist
from keras.utils import np_utils
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation
from keras.optimizers import RMSprop
NB_CLASSES = 10
grabFrame: function() {
var self = this;
this.canvasCtx.drawImage(this.video, 0, 0, this.canvas.width, this.canvas.height);
this.canvas.toBlob(function(imageData) {
var postImageReq = new XMLHttpRequest();
postImageReq.open("POST", "/prediction", true);
postImageReq.responseType = "json";
postImageReq.onload = function(event) {
@datitran
datitran / app.py
Created December 6, 2016 14:21
Detect faces function
def detect_faces(image):
faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
img = Image.open(StringIO(image))
img_cv2 = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2RGBA)
gray = cv2.cvtColor(img_cv2, cv2.COLOR_RGBA2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)