Skip to content

Instantly share code, notes, and snippets.

View tldrafael's full-sized avatar

Rafael Toledo tldrafael

View GitHub Profile
#
# Generic example
#
from flask import Flask, json, request, Response
import helpers
app = Flask(__name__)
@app.route('/predict', methods = ['POST'])
def api_predict():
@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
# 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 / 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 && \
@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
# Code snippet to train lightgbm models quickly, using the number of iterations based on CV
import lightgbm as lgb
lgb_dftrain = lgb.Dataset(features_train, target_train)
params = {'boosting_type': 'gbdt',
'objective': 'binary',
'enable_bundle': True,
'max_conflict_rate': 0,
'max_depth': 20,
@tldrafael
tldrafael / plot.py
Created October 20, 2019 18:34
Plotting subplots snippet
import matplotlib.pyplot as plt
fig, axs = plt.subplots(4, figsize=(12, 12))
for i in range(4):
axs[i].imshow(sample_masks[:, :, i])
axs[i].axis('off')
@tldrafael
tldrafael / annotation_image_tools.txt
Created October 26, 2019 21:05
Annotation Tools for Image Dectation - Open Source
# Easy to go tools
- http://www.robots.ox.ac.uk/~vgg/software/via/via-1.0.6.html
- https://github.com/virajmavani/semi-auto-image-annotation-tool
- https://labelbox.com/ -> Free until 2500 images per year.
# More references
- https://github.com/jsbroks/awesome-dataset-tools
- https://www.datasetlist.com/tools/
@tldrafael
tldrafael / using_parseargs.py
Last active October 30, 2019 15:53
Snippet to use parseargs
import argparse
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-e', type=str, help='Environment variable', required=True, dest='var1',
choices=['staging', 'production'])
parser.add_argument('--hypertuning', help='Run hypertuning process', action='store_true', dest='var2')
return parser.parse_args()
@tldrafael
tldrafael / pdb_autocomplete.py
Created October 31, 2019 12:43
Pdb autocomple
import rlcompleter
import pdb
pdb.Pdb.complete = rlcompleter.Completer(locals()).complete
pdb.set_trace()
# Oneline to insert into code
import rlcompleter; import pdb; pdb.Pdb.complete = rlcompleter.Completer(locals()).complete; pdb.set_trace()