Skip to content

Export bboxes dataset as VIA-tracks file #580

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
wants to merge 75 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
3b72492
Add files via upload
harsh-bhanushali-05 Mar 16, 2025
9ae5b89
Add support for exporting bboxes in VIA-tracks
harsh-bhanushali-05 Mar 16, 2025
d6ab206
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 16, 2025
5fbe43c
Bug fixes
harsh-bhanushali-05 Mar 16, 2025
be489d2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 16, 2025
7a74ce7
More big fixes
harsh-bhanushali-05 Mar 16, 2025
d51f08b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 16, 2025
0a31390
big fix
harsh-bhanushali-05 Mar 16, 2025
a00d6da
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 16, 2025
3ff9ab6
Pre commit changes
harsh-bhanushali-05 Mar 16, 2025
a93a1cc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 16, 2025
da2aa29
Pre-commit error changes
harsh-bhanushali-05 Mar 16, 2025
37dd94b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 16, 2025
5fe2fca
fix
harsh-bhanushali-05 Mar 16, 2025
fa3c97d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 16, 2025
45c7e16
fix.
harsh-bhanushali-05 Mar 16, 2025
e8a8965
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 16, 2025
aa9d4b5
Fixing code to resolve CI testcases
harsh-bhanushali-05 Mar 22, 2025
ac25ba4
Corrected the export format.
harsh-bhanushali-05 Mar 27, 2025
830e5ad
Updated testcases
harsh-bhanushali-05 Mar 27, 2025
eab3584
Updated the testcase
harsh-bhanushali-05 Apr 2, 2025
f5ebd0d
Replace logging with loguru
harsh-bhanushali-05 Apr 3, 2025
5d7a72d
Updated the logging
harsh-bhanushali-05 Apr 5, 2025
4801ec8
Rename file and small edits
sfmig May 8, 2025
227aab8
Export confidence optionally and pad with max digits plus one
sfmig May 8, 2025
637756e
Add preliminary tests
sfmig May 8, 2025
3d791b3
Parametrize tests
sfmig May 8, 2025
2a9d322
Add test_to_via_tracks_file_invalid_dataset
sfmig May 8, 2025
c62f3a4
Add invalid file test
sfmig May 8, 2025
5771d10
Add map to individual track ID and bboxes dataset validator
sfmig May 8, 2025
4da9037
Rename function to validate poses dataset
sfmig May 8, 2025
9e8620b
Add tests for mapping
sfmig May 8, 2025
bbbc413
Add mapping function. Factor out full csv writing
sfmig May 8, 2025
626c94f
Extend tests
sfmig May 8, 2025
03d5d5f
Remove renamed module
sfmig May 8, 2025
1a3bb6c
Get frame numbers from time coordinates (rather than from array shape)
sfmig May 12, 2025
9f8a65a
Move csv_writer call inside row writing function. Change max_digits t…
sfmig May 12, 2025
61afc3d
Use string literal for csv writer type annotation - see https://til.c…
sfmig May 12, 2025
e8405cc
Review fn signatures. Add image file suffix
sfmig May 12, 2025
f611eb4
Factor out common io utils and add explicit tests
sfmig May 12, 2025
65a5ffe
Change regex to non-greedy to fix sonarcloud issue (will check after …
sfmig May 12, 2025
bba4a07
Try to fix sonarcloud issue
sfmig May 12, 2025
547ef88
Replace regexp by str methods to make sonarcloud happy
sfmig May 12, 2025
492fd77
Add image_file_suffix to test
sfmig May 12, 2025
392e2ff
Add image size to test
sfmig May 12, 2025
f57411a
Test internal functions only for cases that are relevant
sfmig May 12, 2025
217bdd7
Define image filename template
sfmig May 12, 2025
8d2dba3
Reorganise and rename some functions. Add tests for get_image_filenam…
sfmig May 12, 2025
a62e9a1
Reorder tests
sfmig May 12, 2025
206ea60
Review docstrings and small edits. Factor out _get_track_id_from_indi…
sfmig May 13, 2025
db3e137
Expand test_to_via_tracks_file_valid_dataset
sfmig May 13, 2025
3ba25f6
Separate test of to_via_tracks_file when using different values of ex…
sfmig May 13, 2025
7b097f7
Separate image filename and confidence tests. Write confidence tests
sfmig May 13, 2025
038b012
Fix quotes for loadable in VIA (WIP, test fix pending)
sfmig May 13, 2025
db88119
Loadable in VIA
sfmig May 13, 2025
767c2cf
Replace with json approach
sfmig May 13, 2025
1524a22
Fix json serialisation issue
sfmig May 13, 2025
8db30ea
Add preliminary test for double quotes
sfmig May 13, 2025
842bbbc
Fix frame_ being interpreted as a cross-reference by sphinx
sfmig May 14, 2025
21d11f8
Small edits to test
sfmig May 14, 2025
c4c1fa2
Allow user to set padding for frame number
sfmig May 14, 2025
d83d7b9
Rename variables. Add helper function for tests
sfmig May 14, 2025
b2c645a
Add region id and count id
sfmig May 14, 2025
8e18070
Check two lines literally
sfmig May 14, 2025
b652dd3
Combine image filename argus to _write_single_row into one
sfmig May 14, 2025
0a43e1c
Add test to check datasets are recoverable
sfmig May 14, 2025
35396e0
Add tests for region and count ID
sfmig May 14, 2025
a628c67
Change default extract_track_id_from_individuals to True
sfmig May 14, 2025
4d74049
Small edits
sfmig May 14, 2025
3eb9c75
Fixes for API reference
sfmig May 14, 2025
0ad84b2
Consistency in naming the file
sfmig May 14, 2025
4f66088
Add reference
sfmig May 14, 2025
76a0eee
Update guide
sfmig May 14, 2025
61c5ecd
Add reference
sfmig May 14, 2025
3c2dbc7
Update guide
sfmig May 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions docs/source/user_guide/input_output.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,23 @@ save_poses.to_dlc_file(ds, "/path/to/file.csv", split_individuals=True)
(target-saving-bboxes-tracks)=
## Saving bounding box tracks

We currently do not provide explicit methods to export a movement bounding boxes dataset in a specific format. However, you can easily save the bounding box tracks to a .csv file using the standard Python library `csv`.
We currently support exporting a [movement bboxes datasets](target-poses-and-bboxes-dataset) as a [VIA tracks .csv file](via:docs/face_track_annotation.html), so that you can visualise and correct your bounding box tracks with the [VGG Image Annotator (VIA-2) software](via:via.html).

Here is an example of how you can save a bounding boxes dataset to a .csv file:
To export your bounding boxes dataset `ds`, you will need to import the {mod}`movement.io.save_bboxes` module:

```python
from movement.io import save_bboxes
```

Then you can save it as a VIA tracks .csv file:
```python
save_bboxes.to_via_tracks_file(ds, "/path/to/output/file.csv")
```

By default the {func}`movement.io.save_bboxes.to_via_tracks_file` function will try to extract the track IDs from the individuals' names, but you can also select to extract them from the sorted list of individuals with `extract_track_id_from_individuals=True`.


Alternatively, you can save the bounding box tracks to a .csv file with a custom header using the standard Python library `csv`. Below is an example of how you can do this:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we have the built-in support for saving to VIA, I wonder if it's worth putting this "alternative" custom csv option under a dropdown, in the spirit of reducing the page length

```python
# define name for output csv file
filepath = "tracking_output.csv"
Expand All @@ -279,7 +292,7 @@ with open(filepath, mode="w", newline="") as file:
writer.writerow([frame, individual, x, y, width, height, confidence])

```
Alternatively, we can convert the `movement` bounding boxes dataset to a pandas DataFrame with the {meth}`xarray.DataArray.to_dataframe` method, wrangle the dataframe as required, and then apply the {meth}`pandas.DataFrame.to_csv` method to save the data as a .csv file.
Or if you prefer to work with `pandas`, you can convert the `movement` bounding boxes dataset to a `pandas` DataFrame with the {meth}`xarray.DataArray.to_dataframe` method, wrangle the dataframe as required, and then apply the {meth}`pandas.DataFrame.to_csv` method to save the data as a .csv file.


(target-sample-data)=
Expand Down
4 changes: 2 additions & 2 deletions movement/io/load_bboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ def from_file(
) -> xr.Dataset:
"""Create a ``movement`` bounding boxes dataset from a supported file.

At the moment, we only support VIA-tracks .csv files.
At the moment, we only support VIA tracks .csv files.

Parameters
----------
file_path : pathlib.Path or str
Path to the file containing the tracked bounding boxes. Currently
only VIA-tracks .csv files are supported.
only VIA tracks .csv files are supported.
source_software : "VIA-tracks".
The source software of the file. Currently only files from the
VIA 2.0.12 annotator [1]_ ("VIA-tracks") are supported.
Expand Down
Loading
Loading