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 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 |
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 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')) |
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
# 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: |
OlderNewer