Skip to content

Instantly share code, notes, and snippets.

View mmeendez8's full-sized avatar

Miguel Méndez mmeendez8

View GitHub Profile
@mmeendez8
mmeendez8 / db_session.py
Created November 27, 2018 11:41
Teradata access using python 3.5, pyodbc, pandas and fastload
import pyodbc
from subprocess import run, CalledProcessError
import os
from string import Template
import pandas as pd
''' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'''
''' DATABASE CONNECTION FILE (keep it simple) '''
''' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'''
@mmeendez8
mmeendez8 / cosine_similarity.py
Created October 4, 2018 15:48
Tensorflow function to compute cosine similarity between a column vector and the rows of a matrix.
import tensorflow as tf
import numpy as np
def cosine_similarity(matrix, vector):
''' Computes cosine similarity of a given vector with vector rows from matrix'''
# normalize input
norm_matrix = tf.nn.l2_normalize(matrix, 1)
norm_vector = tf.nn.l2_normalize(vector, 0)
@mmeendez8
mmeendez8 / cnn_image_model.py
Last active February 25, 2021 21:41
CNN using pretrained VGG16 model with a new classification layer. This script reads a csv with file paths and labels and fine-tunes (or retrains) the whole network based on new images and labels. Batch size and epochs can be also personalized
from keras.applications import VGG16
from keras.layers import Dropout, Flatten, Dense
from keras.applications.vgg16 import preprocess_input
from keras.preprocessing import image as kimage
from keras.models import Model
from keras.utils import to_categorical
import numpy as np
import pandas as pd
''' This file reads from a csv file the paths of the images and its corresponding labels (in my case
@mmeendez8
mmeendez8 / dynamic_nn.py
Created June 20, 2018 15:25
Tensorflow dynamic feed forward neural network creator
def init_weights(shape):
""" Weight initialization """
weights = tf.random_normal(shape, stddev=0.1)
return tf.Variable(weights)
def init_bias(shape):
"""Create a bias variable with appropriate initialization."""
initial = tf.constant(0.1, shape=shape)