Skip to content

Instantly share code, notes, and snippets.

View RodrigoCMoraes's full-sized avatar

RodrigoCMoraes RodrigoCMoraes

  • São Paulo, SP, Brazil
View GitHub Profile
@RodrigoCMoraes
RodrigoCMoraes / tokenize.py
Created June 6, 2018 17:18
Get a string and return a list with its tokens
from nltk.tokenize import word_tokenize
import nltk
nltk.download('punkt')
def tokenize(string, to_lower=True, is_alpha=False):
"""Get string and return a list with tokens.
Token is the most simple chain of characters without any type of separation.
Args:
@RodrigoCMoraes
RodrigoCMoraes / read_custom_keras_model.py
Last active December 1, 2018 18:49
Read keras model from architecture and weights file, json and h5 respectively
# https://gist.github.com/RodrigoCMoraes/d76890fb8149182e2522014f308660ae
import keras
def read_model(arch_file, weights_file, optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy']):
"""Read custom keras model from files
Args:
arch_file(str): json file with model architecture
weights_file(str): h5 file with weights of model
@RodrigoCMoraes
RodrigoCMoraes / live_webcam.py
Created July 18, 2018 15:47
Get frame from webcam and display it in real time
"""
Get frame from webcam and display it in real time
OpenCv version: 3.4.1
Installed with command: pip install opencv-python
Python version: 3.6.5 :: Anaconda, Inc.
"""
import cv2
"""
@RodrigoCMoraes
RodrigoCMoraes / file_downloader.py
Created October 14, 2018 13:17 — forked from nikhilkumarsingh/file_downloader.py
A file downloader with progress bar for terminal
from tqdm import tqdm
import requests
chunk_size = 1024
url = "http://www.nervenet.org/pdf/python3handson.pdf"
r = requests.get(url, stream = True)
total_size = int(r.headers['content-length'])
@RodrigoCMoraes
RodrigoCMoraes / plot_history_keras_training.py
Created December 12, 2018 00:56
This plot accuray and loss from history of training keras model
# batch_size = 1024
# num_epochs = 20
# history = model.fit(X_train, train_labels,
# batch_size=batch_size,
# epochs=num_epochs,
# validation_data=(X_val, val_labels))
# summarize history for accuracy
plt.plot(history.history['acc'])
plt.plot(history.history['val_acc'])
@RodrigoCMoraes
RodrigoCMoraes / cuda_9.0_cudnn_7.0.sh
Created December 18, 2018 13:10 — forked from ashokpant/cuda_9.0_cudnn_7.0.sh
Install CUDA Toolkit v9.0 and cuDNN v7.0 on Ubuntu 16.04
#!/bin/bash
# install CUDA Toolkit v9.0
# instructions from https://developer.nvidia.com/cuda-downloads (linux -> x86_64 -> Ubuntu -> 16.04 -> deb)
CUDA_REPO_PKG="cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64-deb"
wget https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/${CUDA_REPO_PKG}
sudo dpkg -i ${CUDA_REPO_PKG}
sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda-9-0
@RodrigoCMoraes
RodrigoCMoraes / jupyter_notebook_settings.py
Created December 19, 2018 13:11
Enlarge jupyter notebook and ignore warnings
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:90% !important; }</style>"))
import warnings
warnings.filterwarnings('ignore')
@RodrigoCMoraes
RodrigoCMoraes / pairwise_indexes.py
Last active December 19, 2018 13:41
Pairwise indexes from 1D array
def pairwise_indexes(array, mode='comb'):
"""
Get indexes pairwise from array
Params:
array(list or numpy.array): array with shape(N,) where N is array size
mode: comb=combinatations or perm=permutations
Returns:
pairs(numpy.array): array with pair elements
@RodrigoCMoraes
RodrigoCMoraes / delete_docker.sh
Last active February 18, 2019 15:07
Delete all images and containers in docker
#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
import cv2
import numpy as np
screen_width, screen_height = 1920, 1080
window_width, window_height = 1270, 720
path = "template.jpeg"
image = cv2.imread(path)
image_width, image_height = image.shape[:2]