diff --git a/app/.gitattributes b/app/.gitattributes new file mode 100644 index 0000000..f0bdeab --- /dev/null +++ b/app/.gitattributes @@ -0,0 +1,2 @@ +*.onnx filter=lfs diff=lfs merge=lfs -text +*.jpg filter=lfs diff=lfs merge=lfs -text diff --git a/app/Containerfile b/app/Containerfile new file mode 100644 index 0000000..6f45bb7 --- /dev/null +++ b/app/Containerfile @@ -0,0 +1,12 @@ +FROM quay.io/nmasse-redhat/jetpack-multiarch:r36.4.0 + +ADD *.py *.jpg *.onnx /opt/app +WORKDIR /opt/app +RUN <= 0.25: + box = [ + outputs[0][i][0] - (0.5 * outputs[0][i][2]), outputs[0][i][1] - (0.5 * outputs[0][i][3]), + outputs[0][i][2], outputs[0][i][3]] + boxes.append(box) + scores.append(maxScore) + class_ids.append(maxClassIndex) + + detections = [] + result_boxes = cv2.dnn.NMSBoxes(boxes, scores, 0.25, 0.45, 0.5) + # Iterate through NMS results to draw bounding boxes and labels + for i in range(len(result_boxes)): + index = result_boxes[i] + box = boxes[index] + if scores[index] > MIN_CONF_THRESHOLD: + detection = { + 'class_id': class_ids[index], + 'class_name': CLASSES[class_ids[index]], + 'confidence': f"{scores[index]:.2f}", + 'box': [f"{c:.2f}" for c in box]} + detections.append(detection) + return detections + +if __name__ == "__main__": + # Logger + logging.basicConfig( + format='%(asctime)s %(levelname)-8s %(message)s', + level=logging.INFO, + datefmt='%Y-%m-%d %H:%M:%S' + ) + logger = logging.getLogger(__name__) + ort_sess = ort.InferenceSession(MODEL_PATH, providers=PROVIDERS) + nparr = np.fromfile(INPUT_IMAGE_PATH, np.uint8) + nparr = cv2.imdecode(nparr, cv2.IMREAD_COLOR) + preprocessed, scale, original_image = preprocess(nparr) + outputs = ort_sess.run(None, {'images': preprocessed}) + detections = postprocess(outputs[0]) + logger.info(f"Processed image {INPUT_IMAGE_PATH}") + logger.info(json.dumps(detections)) + logger.info(f"Now starting mass inference...") + start = time.time() + count = 0 + while True: + now = time.time() + if now - start > 1: + logger.info(f"Performed {count} inferences in {now-start:.2f}s") + start = time.time() + count = 0 + outputs = ort_sess.run(None, {'images': preprocessed}) + count+=1 + diff --git a/app/input.jpg b/app/input.jpg new file mode 100644 index 0000000..59eb32b --- /dev/null +++ b/app/input.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:737bac004419fa919c8ca2f17b73e7e51df11753d5acf866f5e8d92c2d5858bf +size 48350 diff --git a/app/model.onnx b/app/model.onnx new file mode 100644 index 0000000..4a89cd2 --- /dev/null +++ b/app/model.onnx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b324341eac87dd48c4d301afdc1d3aa7d58a8df86ec789b86d02f52bdf3ad192 +size 12238986 diff --git a/app/requirements.txt b/app/requirements.txt new file mode 100644 index 0000000..f9a892d --- /dev/null +++ b/app/requirements.txt @@ -0,0 +1,3 @@ +opencv-python-headless +numpy +onnxruntime