Skip to content

Instantly share code, notes, and snippets.

View MohanaRC's full-sized avatar

Mohana Roy Chowdhury MohanaRC

View GitHub Profile
@MohanaRC
MohanaRC / gender_detection.py
Last active November 9, 2016 10:15
Python wrapper for Detection of gender from camera using Lua
# @author : https://github.com/MohanaRC
# @description : Python wrapper for Detection of gender from camera using Lua
'''Uses lutorpy to call lua processes within a python function and finds the result of the gender code'''
import lutorpy
import numpy as np
import cv2
import time
import os
@MohanaRC
MohanaRC / object_classification.txt
Last active December 29, 2016 10:19
Pseudocode for object classification using Sparse Autoencoder and Softmax Classifier
import all the required packages
'''tagging_function : loads training images and allows the user to tag them into categories
input variables:
path_of_images : indicates the path of the input images
path_to_store_tagged_images : indicates the path where the tagged images are renamed and stored'''
define tagging_function(path_of_images, path_to_store_tagged_images):
get the names of all the images in path_of_images and store it in variable listing
import numpy as np
import tensorflow as tf
def tf_gradient_tape(x):
"""
Simple implementation to understand the functioning of gradient tape
Inputs:
x: Tensor value
Returns:
EagerTensor: Derivative of y with respect to input tensor x
"""
with tf.GradientTape() as t:
# Run the function for x=5
tmp_x = tf.constant(5.0)
dy_dx = tf_gradient_tape(tmp_x)
result = dy_dx.numpy()
def tf_gradient_tape2(x):
"""
Simple implementation to understand the functioning of gradient tape for chain rule
Inputs:
x: Tensor value
Returns:
EagerTensor: Derivative of z with respect to input tensor y
"""
with tf.GradientTape() as t:
# Run the function for x=5
tmp_x = tf.constant(3.0)
dz_dx = tf_gradient_tape2(tmp_x)
result = dz_dx.numpy()
def tf_gradient_tape2(x):
"""
Simple implementation to understand the functioning of gradient tape for chain rule
Inputs:
x: Tensor value
Returns:
EagerTensor: Derivative of z with respect to input tensor x
"""
with tf.GradientTape() as t:
def tf_gradient_tape_no_persistent(x):
"""
Simple implementation to understand the functioning of gradient tape for chain rule and return intermediate values without
setting persistent parameter
Inputs:
x: Tensor value
Returns:
EagerTensor: Derivative of y with respect to input tensor x and derivative of z with respect to input tensor x
"""
def tf_gradient_tape_persistent(x):
"""
Simple implementation to understand the functioning of gradient tape for chain rule with persistent set to True
Inputs:
x: Tensor value
Returns:
EagerTensor: Derivative of y with respect to input tensor x and derivate of z with respect to x
"""
with tf.GradientTape(persistent=True) as t: