Skip to content

Commit adfca01

Browse files
Merge pull request #979 from roboflow/handle-wildcard-outputs-in-webrct
Handle wildcard outputs in webrct
2 parents cf7d4bb + 9a5b3f3 commit adfca01

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

inference/core/interfaces/stream_manager/manager_app/entities.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ class WebRTCTURNConfig(BaseModel):
100100
class InitialiseWebRTCPipelinePayload(InitialisePipelinePayload):
101101
webrtc_offer: WebRTCOffer
102102
webrtc_turn_config: Optional[WebRTCTURNConfig] = None
103-
stream_output: Optional[List[str]] = Field(default_factory=list)
104-
data_output: Optional[List[str]] = Field(default_factory=list)
103+
stream_output: Optional[List[Optional[str]]] = Field(default_factory=list)
104+
data_output: Optional[List[Optional[str]]] = Field(default_factory=list)
105105
webrtc_peer_timeout: float = 1
106106
webcam_fps: Optional[float] = None
107107

inference/core/interfaces/stream_manager/manager_app/inference_pipeline_manager.py

+32-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from types import FrameType
1212
from typing import Dict, Optional, Tuple
1313

14+
import cv2 as cv
1415
from pydantic import ValidationError
1516

1617
from inference.core import logger
@@ -275,11 +276,37 @@ def start_loop(loop: asyncio.AbstractEventLoop):
275276
def webrtc_sink(
276277
prediction: Dict[str, WorkflowImageData], video_frame: VideoFrame
277278
) -> None:
278-
if parsed_payload.stream_output[0] not in prediction:
279-
from_inference_queue.sync_put(video_frame.image)
280-
return
281-
if prediction[parsed_payload.stream_output[0]] is None:
282-
from_inference_queue.sync_put(video_frame.image)
279+
errors = []
280+
if not any(
281+
isinstance(v, WorkflowImageData) for v in prediction.values()
282+
):
283+
errors.append("Visualisation blocks were not executed")
284+
errors.append("or workflow was not configured to output visuals.")
285+
errors.append(
286+
"Please try to adjust the scene so models detect objects"
287+
)
288+
errors.append("or stop preview, update workflow and try again.")
289+
elif parsed_payload.stream_output[0] not in prediction:
290+
if not parsed_payload.stream_output[0]:
291+
errors.append("No stream output selected to show")
292+
else:
293+
errors.append(
294+
f"{parsed_payload.stream_output[0]} not available in results"
295+
)
296+
errors.append("Please stop, update outputs and try again")
297+
if errors:
298+
result_frame = video_frame.image.copy()
299+
for row, error in enumerate(errors):
300+
result_frame = cv.putText(
301+
result_frame,
302+
error,
303+
(10, 20 + 30 * row),
304+
cv.FONT_HERSHEY_SIMPLEX,
305+
0.7,
306+
(0, 255, 0),
307+
2,
308+
)
309+
from_inference_queue.sync_put(result_frame)
283310
return
284311
from_inference_queue.sync_put(
285312
prediction[parsed_payload.stream_output[0]].numpy_image

inference/core/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.35.0rc2"
1+
__version__ = "0.35.0"
22

33

44
if __name__ == "__main__":

0 commit comments

Comments
 (0)