Commit c6aa6053 authored by Bavanraj's avatar Bavanraj Committed by Manoj Kumar

Bavan dev

parent 2fbb6e9d
test1.jpg

131 KB

test2.jpg

131 KB

test3.jpg

136 KB

test4.jpg

64.3 KB

......@@ -9,15 +9,20 @@ import tensorflow.keras
from PIL import Image, ImageOps
import numpy as np
import os
PATH = os.path.dirname(__file__)
import string
class Translation:
def sign_predict():
PATH = os.path.dirname(__file__)
# def sign_predict():
# Disable scientific notation for clarity
np.set_printoptions(suppress=True)
# Load the model
model = tensorflow.keras.models.load_model(PATH + '/converted_keras/keras_model.h5')
#model = tensorflow.keras.models.load_model('C:/Users/user/Documents/A to Y 1000 dataset/keras_model.h5')
# Create the array of the right shape to feed into the keras model
# The 'length' or number of images you can put into the array is
......@@ -26,30 +31,46 @@ def sign_predict():
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
#data = np.ndarray(shape=(1, 480, 640, 3), dtype=np.float32)
# Replace this with the path to your image
image = Image.open('C:/Users/user/Documents/GitHub/2020_077/opencv_frame_0.png')
def sign_predict(self, loc):
# Replace this with the path to your image
# 'C:/Users/user/Documents/GitHub/2020_077/opencv_frame_0.png'
image = Image.open(loc)
# resize the image to a 224x224 with the same strategy as in TM2:
# resizing the image to be at least 224x224 and then cropping from the center
# resize the image to a 224x224 with the same strategy as in TM2:
# resizing the image to be at least 224x224 and then cropping from the center
size = (224, 224)
#size = (640, 480)
image = ImageOps.fit(image, size, Image.ANTIALIAS)
size = (224, 224)
#size = (640, 480)
image = ImageOps.fit(image, size, Image.ANTIALIAS)
# turn the image into a numpy array
image_array = np.asarray(image)
print(image_array)
# turn the image into a numpy array
image_array = np.asarray(image)
#print(image_array)
# display the resized image
image.show()
# display the resized image
#image.show()
# Normalize the image
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
# Normalize the image
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
# Load the image into the array
data[0] = normalized_image_array
# Load the image into the array
self.data[0] = normalized_image_array
# run the inference
prediction = model.predict(data)
print(prediction)
return
# run the inference
prediction = self.model.predict(self.data)
#print(prediction)
#print(prediction.shape)
#print(type(prediction))
#print(prediction[0, 2])
for alpha in range(26):
if prediction[0, alpha] >= 0.8:
#print(string.ascii_uppercase[alpha])
return string.ascii_uppercase[alpha]
#break
# if os.path.exists(loc):
# os.remove(loc)
# else:
# print("The file does not exist")
# return
from trans import Translation
import TextVoice
if __name__ == '__main__':
t1 = Translation()
Tex = TextVoice()
location1 = 'C:/Users/user/Documents/GitHub/2020_077/test1.jpg'
location2 = 'C:/Users/user/Documents/GitHub/2020_077/test2.jpg'
location3 = 'C:/Users/user/Documents/GitHub/2020_077/test3.jpg'
location4 = 'C:/Users/user/Documents/GitHub/2020_077/test4.jpg'
location5 = 'C:/Users/user/Documents/GitHub/2020_077/test55.jpg'
Tex.getInput()
#getInput('t1.sign_predict(location1)')
# t1.sign_predict(location2)
# t1.sign_predict(location3)
# t1.sign_predict(location4)
# t1.sign_predict(location5)
# t1.sign_predict(location2)
# t1.sign_predict(location3)
# t1.sign_predict(location4)
# t1.sign_predict(location5)
# t1.sign_predict(location1)
# t1.sign_predict(location4)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment