-
Notifications
You must be signed in to change notification settings - Fork 99
multimodal: Data sync between vision and ts #1930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
sathyendranv
wants to merge
2
commits into
main
Choose a base branch
from
feature/svellais/data_sync
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,15 @@ | |
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
|
|
||
| import socket | ||
|
|
||
| import cv2 | ||
| import pandas as pd | ||
| import paho.mqtt.client as mqtt | ||
| import time | ||
| import base64 | ||
| import subprocess | ||
| import requests | ||
| import json | ||
| import os | ||
| import glob | ||
|
|
@@ -269,17 +272,85 @@ def check_and_load_simulation_files(target_fps): | |
| return | ||
|
|
||
| continuous_ingestion = os.getenv("CONTINUOUS_SIMULATOR_INGESTION", "true").lower() == "true" | ||
|
|
||
| streamed_once = False | ||
| while True: | ||
| for i, filename in enumerate(available_files, 1): | ||
| logger.info(f" {i}. {filename}") | ||
| stream_video_and_csv(filename, target_fps=target_fps) | ||
| if not streamed_once: | ||
| for i, filename in enumerate(available_files, 1): | ||
| logger.info(f" {i}. {filename}") | ||
| stream_video_and_csv(filename, target_fps=target_fps) | ||
| if not continuous_ingestion: | ||
| streamed_once = True | ||
| if not continuous_ingestion: | ||
| logger.info("Continuous ingestion disabled. Exiting...") | ||
| break | ||
| logger.info("Streaming completed once as CONTINUOUS_SIMULATOR_INGESTION is set to false. Sleeping indefinitely.") | ||
| time.sleep(60) # Sleep indefinitely after one complete streaming | ||
|
|
||
| def is_port_accessible(Host: str, Port: int): | ||
| """ | ||
| Check if a port is accessible on a given host. | ||
|
|
||
| :param host: The hostname or IP address to check. | ||
| :param port: The port number to check. | ||
| :param timeout: The timeout in seconds for the connection attempt. | ||
| :return: True if the port is accessible, False otherwise. | ||
| """ | ||
|
|
||
| logger.info("Waiting for %s accessible...", Host) | ||
| while True: | ||
| try: | ||
| # Create a socket object | ||
| with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: | ||
| # Set the timeout for the connection attempt | ||
| sock.settimeout(5) | ||
| # Attempt to connect to the host and port | ||
| sock.connect((Host, Port)) | ||
| logger.info("%s is accessible...", Host) | ||
| return True | ||
| except (socket.timeout, socket.error): | ||
| pass | ||
| time.sleep(1) | ||
|
|
||
| def start_dlsps_pipeline_server(Host: str, Port: int): | ||
| """ | ||
| Start the DLStreamPipelineServer using a subprocess call to the dlstreamer-pipeline-server binary. | ||
| """ | ||
| logger.info("Starting DLStreamPipelineServer...") | ||
| try: | ||
| # Create the pipeline via HTTP request | ||
| payload = { | ||
| "source": { | ||
| "uri": "rtsp://mediamtx:8554/live.stream", | ||
| "type": "uri", | ||
| }, | ||
| "destination": { | ||
| "metadata": { | ||
| "type": "mqtt", | ||
| "topic": "vision_weld_defect_classification", | ||
| }, | ||
| "frame": [ | ||
| { | ||
| "type": "webrtc", | ||
| "peer-id": "samplestream", | ||
| } | ||
| ], | ||
| }, | ||
| "parameters": { | ||
| "classification-properties": { | ||
| "model": "/home/pipeline-server/resources/models/weld-defect-classification-f16-DeiT/deployment/Classification/model/model.xml", | ||
| "device": "CPU", | ||
| } | ||
| }, | ||
| } | ||
| response = requests.post( | ||
| f"http://{Host}:{Port}/pipelines/user_defined_pipelines/weld_defect_classification", | ||
| json=payload, | ||
| timeout=10, | ||
| ) | ||
| response.raise_for_status() | ||
| logger.info("DLStreamPipelineServer started successfully.") | ||
| return response | ||
| except Exception as e: | ||
| logger.error("Failed to start DLStreamPipelineServer: %s", e) | ||
| return None | ||
|
|
||
| if __name__ == "__main__": | ||
| # Uncomment the line below to see available files | ||
|
|
@@ -293,6 +364,19 @@ def check_and_load_simulation_files(target_fps): | |
| # Default behavior - process all available files | ||
| client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2) | ||
| client.connect(MQTT_BROKER) | ||
|
|
||
| ts_host = os.getenv("TS_MS_SERVER", "ia-time-series-analytics-microservice") | ||
| ts_port = int(os.getenv("TS_MS_PORT", "9092")) | ||
|
|
||
| dlsps_host = os.getenv("DLSPS_MS_SERVER", "dlstreamer-pipeline-server") | ||
| dlsps_port = int(os.getenv("DLSPS_MS_PORT", "8080")) | ||
|
|
||
| is_port_accessible(ts_host, ts_port) | ||
| time.sleep(10) | ||
| # is_port_accessible(dlsps_host, dlsps_port) | ||
|
|
||
|
|
||
|
|
||
| target_fps = int(os.getenv("SIMULATION_TARGET_FPS", "10")) | ||
| ffmpeg_cmd = [ | ||
| "ffmpeg", | ||
|
|
@@ -310,6 +394,12 @@ def check_and_load_simulation_files(target_fps): | |
| ] | ||
|
|
||
| ffmpeg_proc = subprocess.Popen(ffmpeg_cmd, stdin=subprocess.PIPE) | ||
|
|
||
| # dlsps_proc = start_dlsps_pipeline_server(dlsps_host, dlsps_port) | ||
|
|
||
| # if dlsps_proc is None: | ||
| # logger.error("DLStreamPipelineServer failed to start. Exiting.") | ||
| # exit(1) | ||
|
Comment on lines
+398
to
+402
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this commented code and the function def, also line 376? |
||
| check_and_load_simulation_files(target_fps) | ||
|
|
||
| if 'ffmpeg_proc' in locals(): | ||
|
|
||
3 changes: 2 additions & 1 deletion
3
...cturing-ai-suite/industrial-edge-insights-multimodal/weld-data-simulator/requirements.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| opencv-python==4.12.0.88 | ||
| paho-mqtt==2.1.0 | ||
| pandas==2.3.2 | ||
| pandas==2.3.2 | ||
| requests==2.32.4 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this, you may have added primarily for debug purpose this.