This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import tensorflow as tf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run the function for x=5 | |
tmp_x = tf.constant(5.0) | |
dy_dx = tf_gradient_tape(tmp_x) | |
result = dy_dx.numpy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run the function for x=5 | |
tmp_x = tf.constant(3.0) | |
dz_dx = tf_gradient_tape2(tmp_x) | |
result = dz_dx.numpy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
OlderNewer