@Louis-Cheng-Liu
@numbqq
@Electr1
import numpy as np
import os
import argparse
import sys
from ksnn.api import KSNN
from ksnn.types import *
import cv2 as cv
cam_index = 0
names = {
0: 'person', 1: 'bicycle', 2: 'car', 3: 'motorcycle', 4: 'airplane', 5: 'bus', 6: 'train', 7: 'truck',
8: 'boat', 9: 'traffic light', 10: 'fire hydrant', 11: 'stop sign', 12: 'parking meter', 13: 'bench',
14: 'bird', 15: 'cat', 16: 'dog', 17: 'horse', 18: 'sheep', 19: 'cow', 20: 'elephant', 21: 'bear',
22: 'zebra', 23: 'giraffe', 24: 'backpack', 25: 'umbrella', 26: 'handbag', 27: 'tie', 28: 'suitcase',
29: 'frisbee', 30: 'skis', 31: 'snowboard', 32: 'sports ball', 33: 'kite', 34: 'baseball bat',
35: 'baseball glove', 36: 'skateboard', 37: 'surfboard', 38: 'tennis racket', 39: 'bottle',
40: 'wine glass', 41: 'cup', 42: 'fork', 43: 'knife', 44: 'spoon', 45: 'bowl', 46: 'banana',
47: 'apple', 48: 'sandwich', 49: 'orange', 50: 'broccoli', 51: 'carrot', 52: 'hot dog', 53: 'pizza',
54: 'donut', 55: 'cake', 56: 'chair', 57: 'couch', 58: 'potted plant', 59: 'bed', 60: 'dining table',
61: 'toilet', 62: 'tv', 63: 'laptop', 64: 'mouse', 65: 'remote', 66: 'keyboard', 67: 'cell phone',
68: 'microwave', 69: 'oven', 70: 'toaster', 71: 'sink', 72: 'refrigerator', 73: 'book', 74: 'clock',
75: 'vase', 76: 'scissors', 77: 'teddy bear', 78: 'hair drier', 79: 'toothbrush'
}
def draw_bounding_box(frame, box, class_index, confidence):
pass
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--library", help="Path to C static library file")
parser.add_argument("--model", help="Path to nbg file")
parser.add_argument("--level", help="Information printer level: 0/1/2")
args = parser.parse_args()
if args.model:
if os.path.exists(args.model) == False:
sys.exit('Model \'{}\' not exist'.format(args.model))
model = args.model
else:
sys.exit("NBG file not found !!! Please use format: --model")
if args.library:
if os.path.exists(args.library) == False:
sys.exit('C static library \'{}\' not exist'.format(args.library))
library = args.library
else:
sys.exit("C static library not found !!! Please use format: --library")
if args.level == '1' or args.level == '2':
level = int(args.level)
else:
level = 0
resnet50 = KSNN('VIM3')
print(' |--- KSNN Version: {} +---| '.format(resnet50.get_nn_version()))
print('Start init neural network ...')
resnet50.nn_init(library=library, model=model, level=level)
print('Done.')
cap = cv.VideoCapture(cam_index)
assert cap.isOpened()
color = (0, 255, 0)
while True:
ret, frame = cap.read()
if not ret:
break
frame = cv.resize(frame, (640, 480))
outputs = resnet50.nn_inference(frame, platform='ONNX', reorder='2 1 0', output_format=output_format.OUT_FORMAT_FLOAT32)
outputs = outputs[0]
predictions = np.array(outputs).reshape(8400, 144)
boxes = predictions[:, :64]
confidences = predictions[:, 64:]
confidences = 1 / (1 + np.exp(-confidences))
predicted_classes = np.argmax(confidences, axis=1)
predicted_class_names = [names[class_index] for class_index in predicted_classes]
cv.imshow('Camera Stream', frame)
if cv.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv.destroyAllWindows()
im unable to understand why there are 64 elements for box location…
if the model is giving out confidences for 80 classes there should be 80 boxes…
and also the model output is like
[[actual output list of 1209600 elements]]
though that works out to be 144x8400
but please tell me why there are 64 elements for boxes
it would be great if you could help out with postprocessing of the output…