Skip to content

Commit c1288f9

Browse files
authored
dgstream meta refactoring (#58)
* dgstreams examples refactoring (#1) * dgstreams examples refactoring (#2) * Unit tests update
1 parent a4ee223 commit c1288f9

9 files changed

+167
-256
lines changed

examples/dgstreams/dgstreams_demo.ipynb

+46-67
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
{
2626
"cell_type": "code",
27-
"execution_count": null,
27+
"execution_count": 13,
2828
"id": "0b76d324",
2929
"metadata": {},
3030
"outputs": [],
@@ -34,9 +34,7 @@
3434
"# URL of RTSP stream\n",
3535
"# URL of YouTube Video\n",
3636
"# path to video file (mp4 etc)\n",
37-
"video_source = (\n",
38-
" \"https://raw.githubusercontent.com/DeGirum/PySDKExamples/main/images/example_video.mp4\"\n",
39-
")"
37+
"video_source = \"https://raw.githubusercontent.com/DeGirum/PySDKExamples/main/images/example_video.mp4\""
4038
]
4139
},
4240
{
@@ -61,9 +59,7 @@
6159
"\n",
6260
"# create gizmos:\n",
6361
"source = VideoSourceGizmo(video_source) # video source gizmo\n",
64-
"display = VideoDisplayGizmo(\n",
65-
" \"press `x` or `q` to stop\", allow_drop=False\n",
66-
") # video display gizmo\n",
62+
"display = VideoDisplayGizmo(\"`q` to exit\", allow_drop=False) # video display gizmo\n",
6763
"\n",
6864
"# Create pipeline: connect display input to source output\n",
6965
"display.connect_to(source)\n",
@@ -95,14 +91,10 @@
9591
"source": [
9692
"from degirum_tools.streams import *\n",
9793
"\n",
98-
"c = Composition()\n",
99-
"\n",
10094
"# Create gizmos and pipeline as a single-liner:\n",
101-
"# we use __call__() operator of Composition class instead of add() method\n",
95+
"# we construct composition passing gizmo pipeline as a parameter\n",
10296
"# and we use `>>` operator of gizmo classes instead of connect_to() method\n",
103-
"c(VideoSourceGizmo(video_source)) >> c(VideoDisplayGizmo())\n",
104-
"\n",
105-
"c.start()"
97+
"Composition(VideoSourceGizmo(video_source) >> VideoDisplayGizmo()).start()"
10698
]
10799
},
108100
{
@@ -124,23 +116,16 @@
124116
"source": [
125117
"from degirum_tools.streams import *\n",
126118
"\n",
127-
"c = Composition()\n",
128-
"\n",
129119
"# create and add to composition all required gizmos\n",
130-
"source = c.add(VideoSourceGizmo(video_source)) # video source gizmo\n",
131-
"display = c.add(\n",
132-
" VideoDisplayGizmo([\"Original\", \"Resized\"])\n",
133-
") # two-input display gizmo: will show two windows\n",
134-
"resizer = c.add(ResizingGizmo(300, 200)) # resizing gizmo\n",
135-
"\n",
136-
"# Create pipeline: the image source is fed to a display and to the image resizing gizmo,\n",
137-
"# which is then fed to another display.\n",
138-
"\n",
139-
"display.connect_to(source, 0) # display input 0 is \"Original\"\n",
140-
"resizer.connect_to(source)\n",
141-
"display.connect_to(resizer, 1) # display input 1 is \"Resized\"\n",
142-
"\n",
143-
"c.start()"
120+
"source = VideoSourceGizmo(video_source) # video source gizmo\n",
121+
"display = VideoDisplayGizmo([\"Original\", \"Resized\"]) # two-input display gizmo\n",
122+
"resizer = ResizingGizmo(300, 200) # resizing gizmo\n",
123+
"\n",
124+
"# Create pipeline: the image source is connected to a display input 0. \n",
125+
"# Also it is connected to the image resizing gizmo which is then connected to display input 1.\n",
126+
"# Both pipelines are passed to the Composition object constructor.\n",
127+
"# Note, how `[]` operator is used to select the input of display gizmo to connect to.\n",
128+
"Composition(source >> display[0], source >> resizer >> display[1]).start()"
144129
]
145130
},
146131
{
@@ -162,16 +147,13 @@
162147
"source": [
163148
"from degirum_tools.streams import *\n",
164149
"\n",
165-
"c = Composition()\n",
166-
"\n",
167-
"source = c.add(VideoSourceGizmo(video_source))\n",
168-
"display = c.add(VideoDisplayGizmo())\n",
169-
"saver = c.add(VideoSaverGizmo(\"temp/mycapture.mp4\"))\n",
170-
"\n",
171-
"source >> display\n",
172-
"source >> saver\n",
150+
"# create gizmos\n",
151+
"source = VideoSourceGizmo(video_source)\n",
152+
"display = VideoDisplayGizmo()\n",
153+
"saver = VideoSaverGizmo(\"temp/mycapture.mp4\")\n",
173154
"\n",
174-
"c.start()"
155+
"# create pipeline and composition, then start it\n",
156+
"Composition(source >> display, source >> saver).start()"
175157
]
176158
},
177159
{
@@ -198,7 +180,7 @@
198180
},
199181
{
200182
"cell_type": "code",
201-
"execution_count": null,
183+
"execution_count": 18,
202184
"id": "193a0c25",
203185
"metadata": {},
204186
"outputs": [],
@@ -228,25 +210,20 @@
228210
"from degirum_tools.streams import *\n",
229211
"\n",
230212
"# load some object detection AI model\n",
231-
"model=dg.load_model(\n",
213+
"model = dg.load_model(\n",
232214
" model_name=model_name,\n",
233215
" inference_host_address=hw_location,\n",
234216
" zoo_url=model_zoo_url,\n",
235217
" token=degirum_tools.get_token(),\n",
236218
")\n",
237-
"c = Composition()\n",
238219
"\n",
239220
"# create gizmos\n",
240-
"source = c.add(VideoSourceGizmo(video_source)) # video source\n",
241-
"detection = c.add(AiSimpleGizmo(model)) # AI model\n",
242-
"display = c.add(\n",
243-
" VideoDisplayGizmo(\"Detection\", show_ai_overlay=True, show_fps=True)\n",
244-
") # display\n",
221+
"source = VideoSourceGizmo(video_source) # video source\n",
222+
"detection = AiSimpleGizmo(model) # AI model\n",
223+
"display = VideoDisplayGizmo(\"Detection\", show_ai_overlay=True, show_fps=True) # display\n",
245224
"\n",
246-
"# create pipeline\n",
247-
"source >> detection >> display\n",
248-
"\n",
249-
"c.start()"
225+
"# create pipeline and composition, then start it\n",
226+
"Composition(source >> detection >> display).start()"
250227
]
251228
},
252229
{
@@ -277,7 +254,7 @@
277254
},
278255
{
279256
"cell_type": "code",
280-
"execution_count": null,
257+
"execution_count": 20,
281258
"id": "2d31645f",
282259
"metadata": {},
283260
"outputs": [],
@@ -307,35 +284,37 @@
307284
"from degirum_tools.streams import *\n",
308285
"\n",
309286
"# load some object detection AI model\n",
310-
"model=dg.load_model(\n",
287+
"model = dg.load_model(\n",
311288
" model_name=model_name,\n",
312289
" inference_host_address=hw_location,\n",
313290
" zoo_url=model_zoo_url,\n",
314291
" token=degirum_tools.get_token(),\n",
315292
")\n",
316293
"\n",
317-
"c = Composition()\n",
318-
"\n",
319294
"# create gizmos\n",
320-
"source = c.add(VideoSourceGizmo(video_source)) # video source\n",
321-
"preprocessor = c.add(AiPreprocessGizmo(model))\n",
322-
"detection = c.add(AiSimpleGizmo(model))\n",
323-
"display = c.add(\n",
324-
" VideoDisplayGizmo(\"Objects\", show_ai_overlay=True, show_fps=True)\n",
325-
") # display\n",
326-
"\n",
327-
"# create pipeline\n",
328-
"source >> preprocessor >> detection >> display\n",
295+
"source = VideoSourceGizmo(video_source) # video source\n",
296+
"preprocessor = AiPreprocessGizmo(model) # AI model preprocessor\n",
297+
"detection = AiSimpleGizmo(model) # AI model\n",
298+
"display = VideoDisplayGizmo(\"Objects\", show_ai_overlay=True, show_fps=True) # display\n",
329299
"\n",
330-
"c.start()"
300+
"# create pipeline and composition, then start it\n",
301+
"Composition(source >> preprocessor >> detection >> display).start()"
331302
]
303+
},
304+
{
305+
"cell_type": "code",
306+
"execution_count": null,
307+
"id": "596abdcf",
308+
"metadata": {},
309+
"outputs": [],
310+
"source": []
332311
}
333312
],
334313
"metadata": {
335314
"kernelspec": {
336-
"display_name": "Python (supervision)",
315+
"display_name": "base",
337316
"language": "python",
338-
"name": "supervision"
317+
"name": "python3"
339318
},
340319
"language_info": {
341320
"codemirror_mode": {
@@ -347,7 +326,7 @@
347326
"name": "python",
348327
"nbconvert_exporter": "python",
349328
"pygments_lexer": "ipython3",
350-
"version": "3.9.18"
329+
"version": "3.9.16"
351330
}
352331
},
353332
"nbformat": 4,

0 commit comments

Comments
 (0)