3. Playing with Args
Learning Goal: Understand the role of the Args class.
Before you get started, it might not be a bad idea to check out the
fmdt.args module to read up on the Args class and it's
composition. Nevertheless, we are going to begin with a simple example.
In previous tutorials, we've been passing our arguments directly to
fmdt.detect like so:
Creating Args
However, we can explicitly create an Args object first, using either
fmdt.detect_args or fmdt.Args.new.
args = fmdt.detect_args(vid_in_path="demo.mp4", trk_path="trk.txt")
args = fmdt.Args.new(vid_in_path="demo.mp4", trk_path="trk.txt")
These two calls are semantically equivalent; the difference between
Args.new() and detect_args() is that Args.new includes extra options for
fmdt-log-parser & fmdt-visu, such as vid_out_path, that a call to
fmdt-detect does not use.
For example, the following code is valid:
whereas
is not.
Danger
TODO: The latest does not fail (while it should) because of the **args
parameter in the fmdt.detect_args function.
Calling fmdt-detect from an Args instance
We can actually use our new args to call fmdt-detect with the detect
function. Since the parameters are already stored in args, we don't have to
pass anything:
The benefits of this paradigm shift are subtle but important to reflect on. The main advantage is that this allows us to take a single core set of parameters and apply them across a list of videos.
Consider the case where we have a list of videeo filenames stored in vid_list:
We can then define a set of parameters:
And call fmdt-detect on all of the videos with args:
for v in vid_list:
args.detect_args.vid_in_path = v # Update the --vid-in-path parameter
args.detect() # Call fmdt-detect
Next Steps
Learn how to access the statistics stored in fmdt-detect's log files by
following along here.