Skip to content

Commit

Permalink
modeld: send_raw_pred under a flag (commaai#30298)
Browse files Browse the repository at this point in the history
* modeld: SEND_RAW_PRED under a flag

* not twice
  • Loading branch information
YassineYousfi authored Oct 20, 2023
1 parent 9e01f4a commit b7cc698
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions selfdrive/modeld/fill_model_msg.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import os
import capnp
import numpy as np
from typing import Dict
from cereal import log
from openpilot.selfdrive.modeld.constants import ModelConstants, Plan, Meta

SEND_RAW_PRED = os.getenv('SEND_RAW_PRED')

ConfidenceClass = log.ModelDataV2.ConfidenceClass

class PublishState:
Expand Down Expand Up @@ -163,6 +166,10 @@ def fill_model_msg(msg: capnp._DynamicStructBuilder, net_output_data: Dict[str,
else:
modelV2.confidence = ConfidenceClass.red

# raw prediction if enabled
if SEND_RAW_PRED:
modelV2.rawPredictions = net_output_data['raw_pred'].tobytes()

def fill_pose_msg(msg: capnp._DynamicStructBuilder, net_output_data: Dict[str, np.ndarray],
vipc_frame_id: int, vipc_dropped_frames: int, timestamp_eof: int, live_calib_seen: bool) -> None:
msg.valid = live_calib_seen & (vipc_dropped_frames < 1)
Expand Down
8 changes: 7 additions & 1 deletion selfdrive/modeld/modeld.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import sys
import os
import time
import pickle
import numpy as np
Expand All @@ -20,6 +21,8 @@
from openpilot.selfdrive.modeld.constants import ModelConstants
from openpilot.selfdrive.modeld.models.commonmodel_pyx import ModelFrame, CLContext

SEND_RAW_PRED = os.getenv('SEND_RAW_PRED')

MODEL_PATHS = {
ModelRunner.THNEED: Path(__file__).parent / 'models/supercombo.thneed',
ModelRunner.ONNX: Path(__file__).parent / 'models/supercombo.onnx'}
Expand Down Expand Up @@ -70,7 +73,10 @@ def __init__(self, context: CLContext):
self.model.addInput(k, v)

def slice_outputs(self, model_outputs: np.ndarray) -> Dict[str, np.ndarray]:
return {k: model_outputs[np.newaxis, v] for k,v in self.output_slices.items()}
parsed_model_outputs = {k: model_outputs[np.newaxis, v] for k,v in self.output_slices.items()}
if SEND_RAW_PRED:
parsed_model_outputs['raw_pred'] = model_outputs.copy()
return parsed_model_outputs

def run(self, buf: VisionBuf, wbuf: VisionBuf, transform: np.ndarray, transform_wide: np.ndarray,
inputs: Dict[str, np.ndarray], prepare_only: bool) -> Optional[Dict[str, np.ndarray]]:
Expand Down

0 comments on commit b7cc698

Please sign in to comment.