{"id":27945133,"url":"https://github.com/collabora/gst-python-ml","last_synced_at":"2025-05-07T12:55:59.734Z","repository":{"id":270538349,"uuid":"899061367","full_name":"collabora/gst-python-ml","owner":"collabora","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-05T15:42:48.000Z","size":101754,"stargazers_count":9,"open_issues_count":4,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-07T12:55:46.730Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/collabora.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-05T14:52:03.000Z","updated_at":"2025-05-05T15:42:52.000Z","dependencies_parsed_at":"2025-01-01T05:40:47.916Z","dependency_job_id":null,"html_url":"https://github.com/collabora/gst-python-ml","commit_stats":null,"previous_names":["collabora/gst-python-analytics","collabora/gst-python-ml"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/collabora%2Fgst-python-ml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/collabora%2Fgst-python-ml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/collabora%2Fgst-python-ml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/collabora%2Fgst-python-ml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/collabora","download_url":"https://codeload.github.com/collabora/gst-python-ml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252882786,"owners_count":21819155,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-07T12:55:58.873Z","updated_at":"2025-05-07T12:55:59.725Z","avatar_url":"https://github.com/collabora.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GStreamer Python ML\n\nThis project provides a pure Python ML framework for upstream GStreamer, supporting a broad range of ML vision and language features. \n\nSupported functionality includes:\n\n1. object detection\n1. tracking\n1. video captioning\n1. translation\n1. transcription\n1. speech to text\n1. text to speech\n1. text to image\n1. LLMs\n1. serializing model metadata to Kafka server\n\nML toolkits are supported via the `MLEngine` abstraction - we have nominal support for\nTensorFlow, LiteRT and OpenVINO, but all testing thus far has been done with PyTorch.\n\nThese elements will work with your distribution's GStreamer packages. They have been tested on Ubuntu 24 with GStreamer 1.24.\n\n## Python Version\n\nAll elements have been tested with Python 3.12, the installed version of Python on Ubuntu 24\n\n## Install\n\nThere are two installation options described below: installing on your host machine,\nor installing with a Docker container:\n\n### Host Install (Ubuntu 24)\n\n#### Install packages\n\n```\nsudo apt update \u0026\u0026 sudo apt -y upgrade\nsudo apt install -y python3-pip  python3-venv \\\n    gstreamer1.0-plugins-base gstreamer1.0-plugins-base-apps \\\n    gstreamer1.0-plugins-good gstreamer1.0-plugins-bad \\\n    gir1.2-gst-plugins-bad-1.0 python3-gst-1.0 gstreamer1.0-python3-plugin-loader \\\n    libcairo2 libcairo2-dev git\n```\n\n#### Install venv\n\n`python3 -m venv --system-site-packages ~/venv`\n\n\n#### Clone repo (host)\n\n`git clone https://github.com/collabora/gst-python-ml.git`\n\n#### Update .bashrc\n\n```\nexport VIRTUAL_ENV=$HOME/venv\nexport PATH=$VIRTUAL_ENV/bin:$PATH\nexport GST_PLUGIN_PATH=$HOME/src/gst-python-ml/plugins\n```\n\nand then\n\n`source ~/.bashrc`\n\n#### Activate venv and install basic pip packages\n\n```\nsource $VIRTUAL_ENV/bin/activate\npip install --upgrade pip\n```\n\n#### Install pip requirements\n\n```\ncd ~/src/gst-python-ml\npip install -r requirements.txt\n```\n\n### Docker Install\n\n#### Build Docker Container\n\nImportant Note:\n\nThis Dockerfile maps a local `gst-python-ml` repository to the container,\nand expects this repository to be located in `~/src` i.e.  `~/src/gst-python-ml`.\n\n\n#### Enable Docker GPU Support on Host\n\nTo use the host GPU in a docker container, you will need to install the nvidia container toolkit. If running on CPU, these steps can be skipped.\n\n\nAdd nvidia repository (Ubuntu)\n\n```\ncurl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \\\n  \u0026\u0026 curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \\\n    sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \\\n    sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list\n```\n\nThen\n\n```\nsudo apt update\nsudo apt install -y nvidia-container-toolkit\nsudo systemctl restart docker\n```\n\n#### Build Ubuntu 24.04 Container\n`docker build -f ./Dockerfile -t ubuntu24:latest .`\n\n#### Run Docker Container\n\na) If running on CPU, just remove `--gpus all` from command below\nb) This command assumes you have set up a Kafka network as described below\n\n`docker run -v ~/src/gst-python-ml/:/root/gst-python-ml -it --rm --gpus all --name ubuntu24 ubuntu24:latest /bin/bash`\n\nIn the container shell, run\n\n`pip install -r requirements.txt`\n\nto install base requirements, and then\n\n`cd gst-python-ml` to run the pipelines below. After installing requirements,\nit is recommended to open another terminal on host and run\n\n`docker ps` to get the container id, and then run\n\n`docker commit $CONTAINER_ID` to commit the changes, where `$CONTAINER_ID`\nis the id for your docker instance.\n\n#### Docker Cleanup\n\nIf you want to purge existing docker containers and images:\n\n```\ndocker container prune -f\ndocker image prune -a -f\n```\n\n## IMPORTANT NOTE\n\nTo use the language elements included in this project, the `nvidia-cuda-toolkit`\nubuntu package must be installed, and additional pip requirements must be installed from\n`requirements/language_requrements.txt`\n\n## Post Install\n\nRun `gst-inspect-1.0 python` to see all of the pyml elements listed.\n\n# Building PyPI Package\n\n## Setup\n1. Generate token on PyPI and add to `.pypirc` :\n\n```\n[pypi]\n  username = __token__\n  password = FOOBAR\n```\n\n2. `pip install setuptools wheel twine`\n\n## Build\n\n`python -m build`\n\n## Upload\n\n`twine upload dist/*`\n\n\n## Using GStreamer Python ML Elements\n\n## Pipelines\n\nBelow are some sample pipelines for the various elements in this project.\n\n### kafkasink\n\n#### Setting up kafka network\n\n`docker network create kafka-network`\n\nand list networks\n\n`docker network ls`\n\n#### docker launch\n\nTo launch a docker instance with the kafka network, add ` --network kafka-network  `\nto the docker launch command above.\n\n#### Set up kafka and zookeeper\n\nNote: setup below assumes you are running your pipeline in a docker container. \nIf running pipeline from host, then the port changes from `9092` to `29092`,\nand the broker changes from `kafka` to `localhost`.\n\n```\ndocker stop kafka zookeeper\ndocker rm kafka zookeeper\ndocker run -d --name zookeeper --network kafka-network -e ZOOKEEPER_CLIENT_PORT=2181 confluentinc/cp-zookeeper:latest\ndocker run -d --name kafka --network kafka-network \\\n  -e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 \\\n  -e KAFKA_ADVERTISED_LISTENERS=INSIDE://kafka:9092,OUTSIDE://localhost:29092 \\\n  -e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT \\\n  -e KAFKA_LISTENERS=INSIDE://0.0.0.0:9092,OUTSIDE://0.0.0.0:29092 \\\n  -e KAFKA_INTER_BROKER_LISTENER_NAME=INSIDE \\\n  -e KAFKA_BROKER_ID=1 \\\n  -e KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 \\\n  -p 9092:9092 \\\n  -p 29092:29092 \\\n  confluentinc/cp-kafka:latest\n```\n\n#### Create test topic\n```\ndocker exec kafka kafka-topics --create --topic test-kafkasink-topic --bootstrap-server kafka:9092 --partitions 1 --replication-factor 1\n```\n\n#### list topics\n\n`docker exec -it kafka kafka-topics --list --bootstrap-server kafka:9092`\n\n\n#### delete topic\n\n`docker exec -it kafka kafka-topics --delete --topic test-topic --bootstrap-server kafka:9092`\n\n\n#### consume topic\n\n`docker exec -it kafka kafka-console-consumer --bootstrap-server kafka:9092 --topic test-kafkasink-topic --from-beginning`\n\n\n### non ML\n\n`GST_DEBUG=4 gst-launch-1.0 videotestsrc ! video/x-raw,width=1280,height=720 ! pyml_overlay meta-path=data/sample_metadata.json tracking=true ! videoconvert ! autovideosink`\n\nNote: make sure to set the following in `.bashrc` file :\n\n`export GST_PLUGIN_PATH=/home/$USER/src/gst-python-ml/plugins:$GST_PLUGIN_PATH`\n\n\n### streammux/streamdemux pipeline\n\n```\n GST_DEBUG=4 gst-launch-1.0   videotestsrc pattern=ball ! video/x-raw, width=320, height=240 ! queue ! pyml_streammux name=mux   videotestsrc pattern=smpte ! video/x-raw, width=320, height=240 ! queue ! mux.sink_1   videotestsrc pattern=smpte ! video/x-raw, width=320, height=240 ! queue ! mux.sink_2   mux.src ! queue ! pyml_streamdemux name=demux   demux.src_0 ! queue ! glimagesink  demux.src_1 ! queue ! glimagesink   demux.src_2 ! queue  ! glimagesink\n```\n\n\n### Bird's Eye View\n\n`GST_DEBUG=4 gst-launch-1.0 filesrc location=data/soccer_single_camera.mp4 ! decodebin ! videoconvert ! pyml_birdseye ! videoconvert ! autovideosink`\n\n`GST_DEBUG=4 gst-launch-1.0 filesrc location=data/soccer_single_camera.mp4 ! decodebin ! videorate ! video/x-raw,framerate=30/1 ! videoconvert ! pyml_birdseye ! videoconvert ! openh264enc ! h264parse ! matroskamux ! filesink location=output.mkv`\n\n### Classification\n\n```\nGST_DEBUG=4 gst-launch-1.0  filesrc location=data/people.mp4 ! decodebin ! videoconvert ! videoscale ! video/x-raw,width=640,height=480 ! pyml_classifier model-name=resnet18 device=cuda !  videoconvert !  autovideosink\n```\n\n\n### Object Detection\n\n#### TorchVision\n\n`pyml_objectdetector` supports all TorchVision  object detection models.\nSimply choose a suitable model name and set it on the `model-name` property.\nA few possible model names:\n\n```\nfasterrcnn_resnet50_fpn\nssdlite320_mobilenet_v3_large\n```\n\n##### fasterrcnn\n\n`GST_DEBUG=4 gst-launch-1.0  filesrc location=data/people.mp4 ! decodebin ! videoconvert ! videoscale ! video/x-raw,width=640,height=480 ! pyml_objectdetector model-name=fasterrcnn_resnet50_fpn device=cuda batch-size=4 ! videoconvert ! pyml_overlay ! videoconvert ! autovideosink`\n\n##### fasterrcnn/kafka\n\na) run pipeline from host\n\n```\nGST_DEBUG=4 gst-launch-1.0  filesrc location=data/people.mp4 ! decodebin ! videoconvert ! videoscale ! video/x-raw,width=640,height=480 ! pyml_objectdetector model-name=fasterrcnn_resnet50_fpn device=cuda batch-size=4 ! pyml_kafkasink schema-file=data/pyml_object_detector.json broker=localhost:29092 topic=test-kafkasink-topic\n```\n\nb) run pipeline from docker\n\n```\nGST_DEBUG=4 gst-launch-1.0  filesrc location=data/people.mp4 ! decodebin ! videoconvert ! videoscale ! video/x-raw,width=640,height=480 ! pyml_objectdetector model-name=fasterrcnn_resnet50_fpn device=cuda batch-size=4 ! pyml_kafkasink schema-file=data/pyml_object_detector.json broker=kafka:9092 topic=test-kafkasink-topic\n```\n\n\n#### maskrcnn\n\n```\nGST_DEBUG=4 gst-launch-1.0   filesrc location=data/people.mp4 ! decodebin ! videoconvert ! videoscale ! pyml_maskrcnn device=cuda batch-size=4 model-name=maskrcnn_resnet50_fpn ! videoconvert ! pyml_overlay ! videoconvert ! autovideosink\n```\n\n#### yolo with tracking\n\n```\nGST_DEBUG=4 gst-launch-1.0   filesrc location=data/soccer_tracking.mp4 ! decodebin !  videoconvertscale ! video/x-raw,width=640,height=480 ! pyml_yolo model-name=yolo11m device=cuda:0 track=True ! pyml_overlay  ! videoconvert ! autovideosink\n```\n\n```\nGST_DEBUG=4 gst-launch-1.0   filesrc location=data/soccer_tracking.mp4 ! decodebin ! videoconvertscale ! video/x-raw,width=640,height=480,format=RGB ! pyml_streammux name=mux   filesrc location=data/soccer_tracking.mp4 ! decodebin ! videoconvertscale ! video/x-raw,width=640,height=480,format=RGB ! mux.   mux. ! pyml_yolo model-name=yolo11m device=cuda:0 track=True ! pyml_streamdemux name=demux   demux. ! queue ! videoconvert ! pyml_overlay ! videoconvert ! autovideosink sync=false   demux. ! queue ! videoconvert ! pyml_overlay ! videoconvert !  autovideosink sync=false\n\n```\n\n\n### Transcription\n\n#### transcription with initial prompt set\n\n```\nGST_DEBUG=4 gst-launch-1.0 filesrc location=data/air_traffic_korean_with_english.wav ! decodebin ! audioconvert ! pyml_whispertranscribe device=cuda language=ko initial_prompt = \"Air Traffic Control은, radar systems를,  weather conditions에, flight paths를, communication은, unexpected weather conditions가, continuous training을, dedication과, professionalism\" ! fakesink\n```\n\n#### translation to English\n\n```\nGST_DEBUG=4 gst-launch-1.0 filesrc location=data/air_traffic_korean_with_english.wav ! decodebin ! audioconvert ! pyml_whispertranscribe device=cuda language=ko translate=yes ! fakesink\n```\n\n#### coquitts\n\n```\nGST_DEBUG=4 gst-launch-1.0 filesrc location=data/air_traffic_korean_with_english.wav ! decodebin ! audioconvert ! pyml_whispertranscribe device=cuda language=ko translate=yes ! pyml_coquitts device=cuda ! audioconvert ! wavenc ! filesink location=output_audio.wav\n```\n\n#### whisperspeechtts\n\n```\nGST_DEBUG=4 gst-launch-1.0 filesrc location=data/air_traffic_korean_with_english.wav ! decodebin ! audioconvert ! pyml_whispertranscribe device=cuda language=ko translate=yes ! pyml_whisperspeechtts device=cuda ! audioconvert ! wavenc ! filesink location=output_audio.wav\n```\n\n#### mariantranslate\n\n```\nGST_DEBUG=4 gst-launch-1.0 filesrc location=data/air_traffic_korean_with_english.wav ! decodebin ! audioconvert ! pyml_whispertranscribe device=cuda language=ko translate=yes ! pyml_mariantranslate device=cuda src=en target=fr ! fakesink\n```\n\nSupported src/target languages:\n\nhttps://huggingface.co/models?sort=trending\u0026search=Helsinki\n\n\n#### whisperlive\n\n`GST_DEBUG=4 gst-launch-1.0 filesrc location=data/air_traffic_korean_with_english.wav ! decodebin ! audioconvert ! pyml_whisperlive device=cuda language=ko translate=yes llm-model-name=\"microsoft/phi-2\" ! audioconvert ! wavenc ! filesink location=output_audio.wav`\n\n### LLM\n\n1. generate HuggingFace token\n\n2. `huggingface-cli login`\n    and pass in token\n\n3. LLM pipeline (in this case, we use phi-2)\n\n`GST_DEBUG=4 gst-launch-1.0 filesrc location=data/prompt_for_llm.txt !  pyml_llm device=cuda model-name=\"microsoft/phi-2\" ! fakesink`\n\n### stablediffusion\n\n`GST_DEBUG=4 gst-launch-1.0 filesrc location=data/prompt_for_stable_diffusion.txt ! pyml_stablediffusion device=cuda ! pngenc ! filesink location=output_image.png`\n\n#### Caption\n\n#### caption + yolo\n\n`GST_DEBUG=4 gst-launch-1.0   filesrc location=data/soccer_tracking.mp4 ! decodebin ! videoconvertscale ! video/x-raw,width=640,height=480 ! pyml_yolo model-name=yolo11m device=cuda:0 track=True ! pyml_caption device=cuda:0 ! textoverlay !  pyml_overlay ! videoconvert !  autovideosink`\n\n\n#### caption with prompt\n\n`GST_DEBUG=4 gst-launch-1.0   filesrc location=data/soccer_tracking.mp4 ! decodebin ! videoconvertscale !  video/x-raw,width=640,height=480 !  pyml_caption device=cuda:0 prompt=\"What is the name of the game being played?\" downsampled_width=320 downsampled_height=240 ! textoverlay !  videoconvert !  autovideosink`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcollabora%2Fgst-python-ml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcollabora%2Fgst-python-ml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcollabora%2Fgst-python-ml/lists"}