forked from dsutanto/nuclio-handler
add-obb
This commit is contained in:
1 parent
28085cc9cb
commit
21479713e8
1 file changed
+22
-7
+22
-7
@@ -13,16 +13,15 @@ from openvino import Layout, Type
|
||||
|
||||
MODEL_XML = os.getenv("MODEL_XML", "/models/best.xml")
|
||||
MODEL_BIN = os.getenv("MODEL_BIN", "/models/best.bin")
|
||||
CLASSES_FILE = os.getenv("CLASSES_FILE", "/opt/nuclio/classes.json")
|
||||
|
||||
classes_file = os.getenv("CLASSES_FILE", "/opt/nuclio/classes.json")
|
||||
with open(classes_file, 'r') as f:
|
||||
classes_data = json.load(f)
|
||||
coconame = [cls['name'] for cls in sorted(classes_data, key=lambda x: x['id'])]
|
||||
# Will be initialized in init_context
|
||||
coconame = []
|
||||
|
||||
|
||||
class Yolov9OBB:
|
||||
def __init__(
|
||||
self, xml_model_path=MODEL_XML, bin_model_path=MODEL_BIN, conf=0.1, nms=0.4
|
||||
self, xml_model_path=MODEL_XML, bin_model_path=MODEL_BIN, conf=0.1, nms=0.4, class_names=None
|
||||
):
|
||||
core = ov.Core()
|
||||
if bin_model_path:
|
||||
@@ -52,7 +51,7 @@ class Yolov9OBB:
|
||||
self.colors = []
|
||||
|
||||
np.random.seed(42)
|
||||
for i in range(len(coconame)):
|
||||
for i in range(len(class_names)):
|
||||
color = tuple(np.random.randint(100, 256, size=3))
|
||||
self.colors.append(color)
|
||||
|
||||
@@ -177,8 +176,24 @@ class Yolov9OBB:
|
||||
|
||||
|
||||
def init_context(context):
|
||||
"""Nuclio init_context – called once per container.
|
||||
|
||||
Loads the IR model and compiles it for the CPU.
|
||||
"""
|
||||
global coconame
|
||||
context.logger.info("Init context OBB ----> 0%")
|
||||
model = Yolov9OBB(MODEL_XML, MODEL_BIN, conf=0.1, nms=0.4)
|
||||
|
||||
# Load class names
|
||||
try:
|
||||
with open(CLASSES_FILE, 'r') as f:
|
||||
classes_data = json.load(f)
|
||||
coconame = [cls['name'] for cls in sorted(classes_data, key=lambda x: x['id'])]
|
||||
context.logger.info(f"Loaded {len(coconame)} classes")
|
||||
except Exception as exc:
|
||||
context.logger.error(f"Failed to load classes from {CLASSES_FILE}: {exc}")
|
||||
coconame = []
|
||||
|
||||
model = Yolov9OBB(MODEL_XML, MODEL_BIN, conf=0.1, nms=0.4, class_names=coconame)
|
||||
context.user_data.model = model
|
||||
context.logger.info("Init context OBB ----> 100%")
|
||||
|
||||
|
||||
Reference in new issue
Block a user