<jupyter_start><jupyter_text>***Check the Version of Tensor Flow***<jupyter_code>import tensorflow as tf
print(tf.__version__)<jupyter_output>1.13.1<jupyter_text>**Upload the zip file of the images and unizip it following the command**<jupyter_code>!unzip Archive.zip<jupyter_output><empty_output><jupyter_text>**Import Librariers**<jupyter_code>import tensorflow as tf
import tflearn
from tflearn.layers.conv import conv_2d,max_pool_2d
from tflearn.layers.core import input_data,dropout,fully_connected
from tflearn.layers.estimator import regression
import numpy as np
import cv2
from sklearn.utils import shuffle<jupyter_output>WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.<jupyter_text>**Load Images and put it in a vector**<jupyter_code>loadedImages = []

#Load Images From Fist
for i in range(0, 1000):
    image = cv2.imread('fist/fist_' + str(i) + '.png')
    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    loadedImages.append(gray_image.reshape(89, 100, 1))
    
#Load Images from Palm
for i in range(0, 1000):
    image = cv2.imread('palm/palm_' + str(i) + '.png')
    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    loadedImages.append(gray_image.reshape(89, 100, 1))
    
#Load Images from Swing
for i in range(0, 1000):
    image = cv2.imread('swing/swing_' + str(i) + '.png')
    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    loadedImages.append(gray_image.reshape(89, 100, 1))

#Load Images From Peace
for i in range(0, 1000):
    image = cv2.imread('peace/peace_' + str(i) + '.png')
    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    loadedImages.append(gray_image.reshape(89, 100, 1))
    

#Load Images From None
for i in range(0, 1000):
    image = cv2.imread('NONE/NONE_' + str(i) + '.png')
    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    loadedImages.append(gray_image.reshape(89, 100, 1))<jupyter_output><empty_output><jupyter_text>**Create the output vector with four values**<jupyter_code># Create OutputVector

outputVectors = []
for i in range(0, 1000):
    outputVectors.append([1, 0, 0,0,0])

for i in range(0, 1000):
    outputVectors.append([0, 1, 0,0,0])

for i in range(0, 1000):
    outputVectors.append([0, 0, 1,0,0])
    
for i in range(0, 1000):
    outputVectors.append([0, 0, 0,1,0])

for i in range(0, 1000):
    outputVectors.append([0, 0, 0,0,1])<jupyter_output><empty_output><jupyter_text>**Load the test Images**<jupyter_code>testImages = []

#Load Images for Fist
for i in range(0, 100):
    image = cv2.imread('fist_test/fist_' + str(i) + '.png')
    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    testImages.append(gray_image.reshape(89, 100, 1))
    
#Load Images for Palm
for i in range(0, 100):
    image = cv2.imread('palm_test/palm_' + str(i) + '.png')
    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    testImages.append(gray_image.reshape(89, 100, 1))
    
#Load Images for Swing
for i in range(0, 100):
    image = cv2.imread('swing_test/swing_' + str(i) + '.png')
    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    testImages.append(gray_image.reshape(89, 100, 1))

#Load Images for Peace
for i in range(0, 100):
    image = cv2.imread('peace_test/peace_' + str(i) + '.png')
    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    testImages.append(gray_image.reshape(89, 100, 1))
    
#Load Images for None
for i in range(0, 100):
    image = cv2.imread('NONETEST/NONE_' + str(i) + '.png')
    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    testImages.append(gray_image.reshape(89, 100, 1))


#Labes for the test vector

testLabels = []

for i in range(0, 100):
    testLabels.append([1, 0, 0,0,0])
    
for i in range(0, 100):
    testLabels.append([0, 1, 0,0,0])

for i in range(0, 100):
    testLabels.append([0, 0, 1,0,0])
    
for i in range(0, 100):
    testLabels.append([0, 0, 0,1,0])
    
for i in range(0, 100):
    testLabels.append([0, 0, 0,0,1])<jupyter_output><empty_output><jupyter_text>stride is the number of units the filter shifts each time.<jupyter_code># Define the CNN Model
tf.reset_default_graph()
convnet=input_data(shape=[None,89,100,1],name='input')
#32 Filters, 2 Stride, Activation is relu
convnet=conv_2d(convnet,32,2,activation='relu')
convnet=max_pool_2d(convnet,2)

convnet=conv_2d(convnet,64,2,activation='relu')
convnet=max_pool_2d(convnet,2)

convnet=conv_2d(convnet,128,2,activation='relu')
convnet=max_pool_2d(convnet,2)

convnet=conv_2d(convnet,256,2,activation='relu')
convnet=max_pool_2d(convnet,2)

convnet=conv_2d(convnet,256,2,activation='relu')
convnet=max_pool_2d(convnet,2)

convnet=conv_2d(convnet,128,2,activation='relu')
convnet=max_pool_2d(convnet,2)

convnet=conv_2d(convnet,64,2,activation='relu')
convnet=max_pool_2d(convnet,2)

convnet=fully_connected(convnet,1000,activation='relu')
convnet=dropout(convnet,0.75)

convnet=fully_connected(convnet,5,activation='softmax')

convnet=regression(convnet,optimizer='adam',learning_rate=0.001,loss='categorical_crossentropy',name='regression')

model=tflearn.DNN(convnet,tensorboard_verbose=0)<jupyter_output>WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tflearn/initializations.py:119: UniformUnitScaling.__init__ (from tensorflow.python.ops.init_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.initializers.variance_scaling instead with distribution=uniform to get equivalent behavior.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tflearn/layers/core.py:239: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.
Instructions for updating:
Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tflearn/objectives.py:66: calling reduce_sum_v1 (from tensorflow.python.ops.math_ops) with keep_dims is deprecated and will be removed in a future version.
Instructions for updating:
keep_dims is deprecated, use keepdims instead
WARNING:tensorflow:From /usr/local/lib[...]<jupyter_text>**Train the data**<jupyter_code># Shuffle Training Data
loadedImages, outputVectors = shuffle(loadedImages, outputVectors, random_state=0)

# Train model
model.fit(loadedImages, outputVectors, n_epoch=50,
           validation_set = (testImages, testLabels),
           snapshot_step=100, show_metric=True, run_id='convnet_coursera')

model.save("TrainedModel/GestureRecogModel.tfl")<jupyter_output>Training Step: 3949  | total loss: [1m[32m0.00000[0m[0m | time: 2.855s
| Adam | epoch: 050 | loss: 0.00000 - acc: 1.0000 -- iter: 4992/5000
Training Step: 3950  | total loss: [1m[32m0.00000[0m[0m | time: 3.881s
| Adam | epoch: 050 | loss: 0.00000 - acc: 1.0000 | val_loss: 0.55160 - val_acc: 0.9660 -- iter: 5000/5000
--
INFO:tensorflow:/content/TrainedModel/GestureRecogModel.tfl is not in all_model_checkpoint_paths. Manually adding it.
{'fraction_non_alphanumeric': 0.13341698034295274, 'fraction_numerical': 0.060644081974069425, 'mean_word_length': 5.539653600729261, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '315865', 'license': 'MIT', 'n_tokens_mistral': 2975, 'n_tokens_neox': 2696, 'n_words': 567, 'path': 'trainer.ipynb', 'repo_name': 'ramk94/GestureRecognition', 'size': '7173'}