Commit 52eb7220 authored by Manoj Kumar's avatar Manoj Kumar

code cleanup - dataq

parent b2136236
......@@ -18,11 +18,17 @@ app.config["DEBUG"] = True
def testApi():
return "<h1>The API is working</h1>"
##DATAQ
@app.route('/')
def home():
return render_template('homePage.html')
@app.route('/cam')
def openCam():
os.system('python dataq\detect.py')
## END DATAQ
# REVENG
@app.route('/tts')
......
import os
PATH = os.path.dirname(__file__)
FILEPATH = os.path.join(PATH,'detect.py')
exec(open(FILEPATH).read())
\ No newline at end of file
......@@ -8,6 +8,8 @@ from PIL import Image
from tensorflow import keras
sys.path.append('.')
from translation.modelUp import sign_predict
PATH = os.path.dirname(os.path.abspath(__file__))
if StrictVersion(tf.__version__) < StrictVersion('1.15.3'):
raise ImportError('Please upgrade your TensorFlow installation to v1.15.3 or later!')
......@@ -15,14 +17,13 @@ print(tf.__version__)
from object_detection.utils import label_map_util
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
MODEL_NAME = 'D:\manobran technologies\SLIIT 4th\cdap\\2020_077\dataq\inference_graph'
MODEL_NAME = PATH +'\inference_graph'
PATH_TO_FROZEN_GRAPH = MODEL_NAME + '\\frozen_inference_graph.pb'
PATH_TO_LABELS = os.path.join('D:\manobran technologies\SLIIT 4th\cdap\\2020_077\dataq\\training','labelmap.pbtxt')
PATH_TO_LABELS = os.path.join(PATH +'\\training','labelmap.pbtxt')
#load tensorflow model to memory
......
import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tensorflow as tf
import zipfile
import cv2
from distutils.version import StrictVersion
from collections import defaultdict
from io import StringIO
from PIL import Image
if StrictVersion(tf.__version__) < StrictVersion('1.15.3'):
raise ImportError('Please upgrade your TensorFlow installation to v1.15.3 or later!')
print(tf.__version__)
sys.path.append('..')
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
MODEL_NAME = 'D:\manobran technologies\SLIIT 4th\cdap\\2020_077\dataq\inference_graph'
PATH_TO_FROZEN_GRAPH = MODEL_NAME + '\\frozen_inference_graph.pb'
PATH_TO_LABELS = os.path.join('D:\manobran technologies\SLIIT 4th\cdap\\2020_077\dataq\\training','labelmap.pbtxt')
#load tensorflow model to memory
detection_graph = tf.Graph()
with detection_graph.as_default():
od_graph_def = tf.compat.v1.GraphDef()
with tf.compat.v2.io.gfile.GFile(PATH_TO_FROZEN_GRAPH, 'rb') as fid:
serialized_graph = fid.read()
od_graph_def.ParseFromString(serialized_graph)
tf.import_graph_def(od_graph_def, name='')
#map labels
category_index = label_map_util.create_category_index_from_labelmap(PATH_TO_LABELS, use_display_name=True)
def run_inference_for_single_image(image, graph):
if 'detection_masks' in tensor_dict:
# The following processing is only for single image
detection_boxes = tf.squeeze(tensor_dict['detection_boxes'], [0])
detection_masks = tf.squeeze(tensor_dict['detection_masks'], [0])
# Reframe is required to translate mask from box coordinates to image coordinates and fit the image size.
real_num_detection = tf.cast(tensor_dict['num_detections'][0], tf.int32)
detection_boxes = tf.slice(detection_boxes, [0, 0], [real_num_detection, -1])
detection_masks_reframed = utils_ops.reframe_box_masks_to_image_masks(detection_masks, detection_boxes, image.shape[0], image.shape[1])
detection_masks_reframed = tf.cast(tf.greater(detection_masks_reframed, 0.5), tf.uint8)
# Follow the convention by adding back the batch dimension
tensor_dict['detection_masks'] = tf.expand_dims(
detection_masks_reframed, 0)
image_tensor = tf.compat.v1.get_default_graph().get_tensor_by_name('image_tensor:0')
# Run inference
output_dict = sess.run(tensor_dict,
feed_dict={image_tensor: np.expand_dims(image, 0)})
# outputs are float32 numpy arrays
output_dict['num_detections'] = int(output_dict['num_detections'][0])
output_dict['detection_classes'] = output_dict[
'detection_classes'][0].astype(np.uint8)
output_dict['detection_boxes'] = output_dict['detection_boxes'][0]
output_dict['detection_scores'] = output_dict['detection_scores'][0]
if 'detection_masks' in output_dict:
output_dict['detection_masks'] = output_dict['detection_masks'][0]
return output_dict
#------------------------test section do not touch
#method
def runInferenceForMultipleImage(imageSet, graph):
with detection_graph.as_default():
with tf.Session() as session:
output_dicts= []
for index,image in enumerate(imageSet):
run_inference_for_single_image(image,graph)
output_dicts.append(image)
return output_dict
#Initialize Camera
camera = cv2.VideoCapture(0)
try:
with detection_graph.as_default():
with tf.compat.v1.Session() as sess:
# Get handles to input and output tensors
ops = tf.compat.v1.get_default_graph().get_operations()
all_tensor_names = {output.name for op in ops for output in op.outputs}
tensor_dict = {}
key_detections = [
'num_detections', 'detection_boxes', 'detection_scores',
'detection_classes', 'detection_masks'
]
for key in key_detections:
tensor_name = key + ':0'
if tensor_name in all_tensor_names:
tensor_dict[key] = tf.compat.v1.get_default_graph().get_tensor_by_name(
tensor_name)
while True:
ret, image_np = camera.read()
# Expand dimensions since the model expects images to have shape: [1, None, None, 3]
image_np_expanded = np.expand_dims(image_np, axis=0)
# Actual detection.
output_dict = runInferenceForMultipleImage(image_np, detection_graph)
# Visualization of the results of a detection.
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
output_dict['detection_boxes'],
output_dict['detection_classes'],
output_dict['detection_scores'],
category_index,
instance_masks=output_dict.get('detection_masks'),
use_normalized_coordinates=True,
line_thickness=8)
score = round(100*output_dict['detection_scores'][0])
#send the request to bavan here
###
# I will be sending a POST request to u. a hand picture
if score > 80:
print(image_np_expanded)
#waiting for the API on that component to be built
# end send request
cv2.imshow('Hand Detector. Press Q to close', cv2.resize(image_np, (800, 600)))
if cv2.waitKey(25) & 0xFF == ord('q'):
camera.release()
cv2.destroyAllWindows()
break
except Exception as e:
print(e)
camera.release()
# --------------------------end test section
\ No newline at end of file
import firebase_admin
from firebase_admin import credentials
from firebase_admin import storage
import datetime
import os
import requests , PIL.Image as pigm, io
# Fetch the service account key JSON file contents
PATH = os.path.dirname (os.path.abspath(__file__))
JSON = os.path.join(PATH,'creadentials.json')
cred = credentials.Certificate(JSON)
# Initialize the app with a service account, granting admin privileges
app = firebase_admin.initialize_app(cred, {
'storageBucket': 'storage-9eed9.appspot.com',
}, name='storage')
bucket = storage.bucket(app=app)
blob = bucket.blob("afternoon01.jpg")
url = blob.generate_signed_url(datetime.timedelta(seconds=300), method='GET')
response = requests.get(url)
image_bytes = io.BytesIO(response.content)
img =pigm.open(image_bytes)
img.show()
\ No newline at end of file
......@@ -26,11 +26,11 @@ def xml_to_csv(path):
def converter():
# for directory in ['train','test']:
# image_path = os.path.join(os.getcwd(), 'images/{}'.format(directory))
# xml_df = xml_to_csv(image_path)
# xml_df.to_csv('images/{}_labels.csv'.format(directory), index=None)
# print('Successfully converted xml to csv.')
for directory in ['train','test']:
image_path = os.path.join(os.getcwd(), 'images/{}'.format(directory))
xml_df = xml_to_csv(image_path)
xml_df.to_csv('images/{}_labels.csv'.format(directory), index=None)
print('Successfully converted xml to csv.')
print("xmltocsv")
#converter()
converter()
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