-
Notifications
You must be signed in to change notification settings - Fork 0
Write YOLO Live and Offline filters #1
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
Open
FelonEkonom
wants to merge
9
commits into
master
Choose a base branch
from
implementation
base: master
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.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
97c8cb6
Write YOLO Live and Offline filters
FelonEkonom d9f4b10
Add demo for YOLO on computer camera
FelonEkonom 620f546
Prepare demos WiP
FelonEkonom 5020dd4
Improve examples
FelonEkonom 9cacb8b
Improve readme
FelonEkonom ed4e72a
Fix mix install
FelonEkonom eec0fec
Adjust to changes in raw video
FelonEkonom 8398c33
Fix setting log level
FelonEkonom e1f7f5a
Fix typo
FelonEkonom 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
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,35 +1,38 @@ | ||
| # Membrane Template Plugin | ||
| # Membrane YOLO Plugin | ||
|
|
||
| [](https://hex.pm/packages/membrane_template_plugin) | ||
| [](https://hexdocs.pm/membrane_template_plugin) | ||
| [](https://circleci.com/gh/membraneframework/membrane_template_plugin) | ||
| [](https://hex.pm/packages/membrane_yolo_plugin) | ||
| [](https://hexdocs.pm/membrane_yolo_plugin) | ||
| [](https://circleci.com/gh/membraneframework/membrane_yolo§ §_plugin) | ||
|
|
||
| This repository contains a template for new plugins. | ||
| Contains 2 Membrane Filters | ||
| - `Membrane.YOLO.LiveFilter` | ||
| - `Membrane.YOLO.OfflineFilter` | ||
| to run YOLO object detection on a video stream in live and offline scaneario. | ||
|
|
||
| Check out different branches for other flavors of this template. | ||
| Uses under the hood [yolo_elixir](https://github.com/poeticoding/yolo_elixir). | ||
|
|
||
| It's a part of the [Membrane Framework](https://membrane.stream). | ||
|
|
||
| ## Installation | ||
|
|
||
| The package can be installed by adding `membrane_template_plugin` to your list of dependencies in `mix.exs`: | ||
| The package can be installed by adding `membrane_yolo_plugin` to your list of dependencies in `mix.exs`: | ||
|
|
||
| ```elixir | ||
| def deps do | ||
| [ | ||
| {:membrane_template_plugin, "~> 0.1.0"} | ||
| {:membrane_yolo_plugin, "~> 0.1.0"} | ||
| ] | ||
| end | ||
| ``` | ||
|
|
||
| ## Usage | ||
| ## Examples | ||
|
|
||
| TODO | ||
| See `examples/yolo.livemd` or `examples/live_camera_capture.exs`, `examples/live_mp4_processing.exs` and `examples/offline_mp4_processing.exs` | ||
|
|
||
| ## Copyright and License | ||
|
|
||
| Copyright 2020, [Software Mansion](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=membrane_template_plugin) | ||
| Copyright 2025, [Software Mansion](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=membrane_yolo_plugin) | ||
|
|
||
| [](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=membrane_template_plugin) | ||
| [](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=membrane_yolo_plugin) | ||
|
|
||
| Licensed under the [Apache License, Version 2.0](LICENSE) |
Binary file not shown.
Binary file not shown.
|
Member
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. I think we should only keep examples in the livebook. It's basically duplicated in this and other .exs scripts, not great for maintenance |
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 |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| hardware_acceleration = | ||
| case :os.type() do | ||
| {:unix, :darwin} -> :coreml | ||
| {:unix, :linux} -> :cuda | ||
| end | ||
|
|
||
| Mix.install( | ||
| [ | ||
| {:membrane_yolo_plugin, | ||
| github: "membraneframework/membrane_yolo_plugin", branch: "implementation"}, | ||
| {:membrane_core, "~> 1.0"}, | ||
| {:membrane_camera_capture_plugin, "~> 0.7.3"}, | ||
| {:membrane_ffmpeg_swscale_plugin, "~> 0.16.3"}, | ||
| {:membrane_raw_video_format, | ||
| github: "membraneframework/membrane_raw_video_format", branch: "to_image", override: true}, | ||
| {:boombox, github: "membraneframework/boombox"}, | ||
| {:kino_yolo, github: "poeticoding/kino_yolo"}, | ||
| {:exla, "~> 0.10"} | ||
| ], | ||
| config: [ | ||
| ortex: [ | ||
| {Ortex.Native, [features: [hardware_acceleration]]} | ||
| ], | ||
| nx: [ | ||
| default_backend: EXLA.Backend | ||
| ] | ||
| ] | ||
| ) | ||
|
|
||
| Logger.configure(level: :info) | ||
|
|
||
| model_name = "yolox_l.onnx" | ||
| model_path = Path.join("examples/models", model_name) | ||
|
|
||
| if not File.exists?(model_path) do | ||
| model_url = | ||
| "https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/#{model_name}" | ||
|
|
||
| %{body: data} = Req.get!(model_url) | ||
| File.write!(model_path, data) | ||
| end | ||
|
|
||
| defmodule YOLOCameraCapturePipeline do | ||
| use Membrane.Pipeline | ||
|
|
||
| @impl true | ||
| def handle_init(_ctx, _opts) do | ||
| spec = | ||
| child(:camera_capture, Membrane.CameraCapture) | ||
| |> child(:swscale_converter, %Membrane.FFmpeg.SWScale.Converter{ | ||
| format: :RGB, | ||
| output_width: 640 | ||
| }) | ||
| |> child(:yolo_live_filter, %Membrane.YOLO.LiveFilter{ | ||
| yolo_model: | ||
| YOLO.load( | ||
| model_impl: YOLO.Models.YOLOX, | ||
| model_path: "examples/models/yolox_l.onnx", | ||
| classes_path: "examples/models/coco_classes.json", | ||
| eps: [unquote(hardware_acceleration)] | ||
| ), | ||
| draw_boxes: &KinoYOLO.Draw.draw_detected_objects/2 | ||
| }) | ||
| |> via_in(:input, options: [kind: :video]) | ||
| |> child(:boombox_sink, %Boombox.Bin{output: :player}) | ||
|
|
||
| {[spec: spec], %{}} | ||
| end | ||
| end | ||
|
|
||
| {:ok, _supervisor, pipeline} = Membrane.Pipeline.start_link(YOLOCameraCapturePipeline, []) | ||
| Process.monitor(pipeline) | ||
|
|
||
| receive do | ||
| {:DOWN, _ref, :process, _pid, _reason} -> :ok | ||
| end |
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 |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| hardware_acceleration = | ||
| case :os.type() do | ||
| {:unix, :darwin} -> :coreml | ||
| {:unix, :linux} -> :cuda | ||
| end | ||
|
|
||
| Mix.install( | ||
| [ | ||
| {:membrane_yolo_plugin, | ||
| github: "membraneframework/membrane_yolo_plugin", branch: "implementation"}, | ||
| {:membrane_core, "~> 1.0"}, | ||
| {:membrane_camera_capture_plugin, "~> 0.7.3"}, | ||
| {:membrane_ffmpeg_swscale_plugin, "~> 0.16.3"}, | ||
| {:membrane_raw_video_format, | ||
| github: "membraneframework/membrane_raw_video_format", branch: "to_image", override: true}, | ||
| {:boombox, github: "membraneframework/boombox"}, | ||
| {:kino_yolo, github: "poeticoding/kino_yolo"}, | ||
| {:exla, "~> 0.10"} | ||
| ], | ||
| config: [ | ||
| ortex: [ | ||
| {Ortex.Native, [features: [hardware_acceleration]]} | ||
| ], | ||
| nx: [ | ||
| default_backend: EXLA.Backend | ||
| ] | ||
| ] | ||
| ) | ||
|
|
||
| Logger.configure(level: :info) | ||
|
|
||
| model_name = "yolox_l.onnx" | ||
| model_path = Path.join("examples/models", model_name) | ||
|
|
||
| if not File.exists?(model_path) do | ||
| model_url = | ||
| "https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/#{model_name}" | ||
|
|
||
| %{body: data} = Req.get!(model_url) | ||
| File.write!(model_path, data) | ||
| end | ||
|
|
||
| defmodule YOLOMP4Pipeline do | ||
| use Membrane.Pipeline | ||
|
|
||
| @impl true | ||
| def handle_init(_ctx, _opts) do | ||
| spec = | ||
| child(:mp4_source, %Boombox.Bin{input: "examples/fixtures/street.mp4"}) | ||
| |> via_out(:output, options: [kind: :video]) | ||
| |> child(:transcoder, %Membrane.Transcoder{output_stream_format: Membrane.RawVideo}) | ||
| |> child(:swscale_converter, %Membrane.FFmpeg.SWScale.Converter{ | ||
| format: :RGB, | ||
| output_width: 640 | ||
| }) | ||
| |> child(:yolo_live_filter, %Membrane.YOLO.LiveFilter{ | ||
| yolo_model: | ||
| YOLO.load( | ||
| model_impl: YOLO.Models.YOLOX, | ||
| model_path: "examples/models/yolox_l.onnx", | ||
| classes_path: "examples/models/coco_classes.json", | ||
| eps: [unquote(hardware_acceleration)] | ||
| ), | ||
| draw_boxes: &KinoYOLO.Draw.draw_detected_objects/2 | ||
| }) | ||
| |> via_in(:input, options: [kind: :video]) | ||
| |> child(:boombox_sink, %Boombox.Bin{output: :player}) | ||
|
|
||
| {[spec: spec], %{}} | ||
| end | ||
|
|
||
| @impl true | ||
| def handle_child_notification(:processing_finished, :boombox_sink, ctx, state) do | ||
| {[terminate: :normal], state} | ||
| end | ||
| end | ||
|
|
||
| {:ok, supervisor, _pipeline} = Membrane.Pipeline.start_link(YOLOMP4Pipeline, []) | ||
| Process.monitor(supervisor) | ||
|
|
||
| receive do | ||
| {:DOWN, _ref, :process, _pid, _reason} -> :ok | ||
| end |
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 |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| [ | ||
| "person", | ||
| "bicycle", | ||
| "car", | ||
| "motorcycle", | ||
| "airplane", | ||
| "bus", | ||
| "train", | ||
| "truck", | ||
| "boat", | ||
| "traffic light", | ||
| "fire hydrant", | ||
| "stop sign", | ||
| "parking meter", | ||
| "bench", | ||
| "bird", | ||
| "cat", | ||
| "dog", | ||
| "horse", | ||
| "sheep", | ||
| "cow", | ||
| "elephant", | ||
| "bear", | ||
| "zebra", | ||
| "giraffe", | ||
| "backpack", | ||
| "umbrella", | ||
| "handbag", | ||
| "tie", | ||
| "suitcase", | ||
| "frisbee", | ||
| "skis", | ||
| "snowboard", | ||
| "sports ball", | ||
| "kite", | ||
| "baseball bat", | ||
| "baseball glove", | ||
| "skateboard", | ||
| "surfboard", | ||
| "tennis racket", | ||
| "bottle", | ||
| "wine glass", | ||
| "cup", | ||
| "fork", | ||
| "knife", | ||
| "spoon", | ||
| "bowl", | ||
| "banana", | ||
| "apple", | ||
| "sandwich", | ||
| "orange", | ||
| "broccoli", | ||
| "carrot", | ||
| "hot dog", | ||
| "pizza", | ||
| "donut", | ||
| "cake", | ||
| "chair", | ||
| "couch", | ||
| "potted plant", | ||
| "bed", | ||
| "dining table", | ||
| "toilet", | ||
| "tv", | ||
| "laptop", | ||
| "mouse", | ||
| "remote", | ||
| "keyboard", | ||
| "cell phone", | ||
| "microwave", | ||
| "oven", | ||
| "toaster", | ||
| "sink", | ||
| "refrigerator", | ||
| "book", | ||
| "clock", | ||
| "vase", | ||
| "scissors", | ||
| "teddy bear", | ||
| "hair drier", | ||
| "toothbrush" | ||
| ] |
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.
xd