Skip to content

Instantly share code, notes, and snippets.

View zakirangwala's full-sized avatar

Zaki Rangwala zakirangwala

View GitHub Profile
@zakirangwala
zakirangwala / detect.py
Created December 1, 2020 06:48
Detection Function - Mask Detection
def detect_fn(image):
detection_model = load_model()
image, shapes = detection_model.preprocess(image)
prediction_dict = detection_model.predict(image, shapes)
detections = detection_model.postprocess(prediction_dict, shapes)
return detections
@zakirangwala
zakirangwala / detect.py
Created December 1, 2020 06:57
Check Model - Mask Detection
def check(image):
image_np = cv2.imread(image)
input_tensor = tf.convert_to_tensor(
np.expand_dims(image_np, 0), dtype=tf.float32)
detections = detect_fn(input_tensor)
category_index = label_map_util.create_category_index_from_labelmap(
ANNOTATION_PATH+'/label_map.pbtxt')
num_detections = int(detections.pop('num_detections'))
@zakirangwala
zakirangwala / detect.py
Created December 1, 2020 07:17
Real-Time Prediction - Mask Detection
# Real Time Prediction -> Video Capture
def real_time_prediction():
category_index = label_map_util.create_category_index_from_labelmap(
ANNOTATION_PATH+'/label_map.pbtxt')
cap = cv2.VideoCapture(0)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
# Make detection
while True: