Skip to content

Instantly share code, notes, and snippets.

View tldrafael's full-sized avatar

Rafael Toledo tldrafael

View GitHub Profile
@tldrafael
tldrafael / pretrainedmodels_webcam.py
Last active July 11, 2019 20:35
Run Keras ResNet50 in Webcam
import cv2
import numpy as np
from keras.applications import ResNet50
from keras.applications import imagenet_utils
from keras.preprocessing.image import img_to_array
model = ResNet50(weights='imagenet')
camera = cv2.VideoCapture(0)
# If possible control the FPS to constrain the labels appearances
@tldrafael
tldrafael / install_nvidia_drivers_and_docker_azure.sh
Last active March 18, 2019 16:48
Automatically install Nvidia drivers and Nvidia runtime docker in Azure
# Install nvidia-drivers
add-apt-repository -y ppa:graphics-drivers/ppa && \
apt-get update && \
apt-get install -y nvidia-415 && \
# Install the latest docker-ce
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - && \
apt-key fingerprint 0EBFCD88 && \
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" && \
apt-get update && \
apt-get install -y docker-ce && \
# get mp3 stdout output, pipe it to sox to remove beginning and end silence, and force specific rate sample and monochannel
gtts-cli "Hello World" | sox -t mp3 - -r 8000 -c 1 out.wav silence 1 0.1 1% reverse silence 1 0.1 1% reverse
@tldrafael
tldrafael / awk_useful_commands
Last active October 5, 2018 20:37
Awk tricks
## summary.csv and input_postconnect.csv are dummy files of example.
# Filter examples
## print entire row
awk -F';' '{ if( ($3=="") && (($5~"human")||($5~"machine"))) { print } }' summary.csv
awk -F';' '{ if( ($3~"human") && ($5!~"human") && ($5!="")) { print } }' summary.csv
## print specific column $1
awk -F';' '{ if( ($3~"human") && ($5!~"human") && ($5!="")) { print $1 } }' summary.csv
#
# Generic example
#
from flask import Flask, json, request, Response
import helpers
app = Flask(__name__)
@app.route('/predict', methods = ['POST'])
def api_predict():