Skip to content

Commit 5733fe7

Browse files
authored
Polishing H5 support and simplifying saving/checking logic (#154)
* adds h5py to install guide instructions * adds ack for the `.h5` contribution * simplifies and moves inspect_h5 to utils.py * * adds make_h5_key function to generate h5 group names * brushes up existance logic and style * follow up * raise if .extract is called on BaseExtractor * adds doc for h5 * pin h5py version * replaced the exact function with the fn from the map * slightly improved doc * simplified saving/checking logic into generic functions * adds tests for h5 * moves all writes and loads to two functions * now h5 writing is done per feature key, not all keys at once * feature path construction now supports h5 as well as prev formats * puts back the default output feat keys * fixes bug for a test
1 parent 8bce9b3 commit 5733fe7

File tree

24 files changed

+168
-236
lines changed

24 files changed

+168
-236
lines changed

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ conda env create -f conda_env.yml
5151
conda activate video_features
5252

5353
# extract r(2+1)d features for the sample videos
54-
# (defaults to printing; use on_extraction=save_numpy or save_h5 to save to disk)
54+
# (defaults to printing; use on_extraction=save_numpy or save_h5 or save_pickle to save to disk)
5555
python main.py \
5656
feature_type=r21d \
5757
device="cuda:0" \
@@ -94,14 +94,7 @@ Output is defined by the `on_extraction` argument; by default it prints the feat
9494
Possible values of output are `['print', 'save_numpy', 'save_pickle', 'save_h5']`.
9595

9696
* **`save_numpy` / `save_pickle`**: Saves the features in the `output_path` folder with the same name as the input video file but with the `.npy` or `.pkl` extension.
97-
* **`save_h5`**: Saves features into a single HDF5 file per device in the `output_path` (e.g. `video_features_cuda0.h5` or `video_features_cpu.h5`). The features are stored as datasets inside the file, using the video filename as the group key.
98-
> **Tip for HDF5:** Since `save_h5` appends to the same file (e.g. `video_features_cuda0.h5`), we recommend using different `output_path` directories for different datasets (e.g. `./output/train` vs `./output/test`) to keep your data logically separate.
99-
### Inspecting H5 Files
100-
If you used `save_h5`, you can verify the contents of the generated file using the provided utility script. This will print the video names and feature shapes stored inside.
101-
102-
```bash
103-
python utils/inspect_h5.py ./output/r21d/video_features_cuda.h5
104-
```
97+
* **`save_h5`**: Saves features into a single HDF5 file per device in the `output_path` (e.g. `video_features_cuda0.h5`) with video path as keys (`/`/`\\` replaced by `_`). Structure: `file.h5 / video_key (group) / feature_name (rgb, flow, fps etc)`. Use `utils.py/inspect_h5()` to explore the content.
10598

10699

107100
## Used in
@@ -119,6 +112,7 @@ Please, let me know if you found this repo useful for your projects or papers.
119112
- [@ohjho](https://github.com/ohjho): added support of 37-layer R(2+1)d favors.
120113
- [@borijang](https://github.com/borijang): for solving bugs with file names, I3D checkpoint loading enhancement and code style improvements.
121114
- [@bjuncek](https://github.com/bjuncek): for helping with timm models and offline discussion.
115+
- [@VivekNarula7](https://github.com/VivekNarula7): for adding support for `.h5` output format.
122116

123117
## Citation
124118

conda_env.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ dependencies:
5959
- gstreamer-orc=0.4.34=hd590300_0
6060
- harfbuzz=6.0.0=h8e241bc_0
6161
- hdf5=1.14.0=nompi_hb72d44e_103
62-
- h5py
62+
- h5py=3.15.1
6363
- icu=70.1=h27087fc_0
6464
- idna=3.4=py311h06a4308_0
6565
- iniconfig=2.0.0=pyhd8ed1ab_0
@@ -248,4 +248,3 @@ dependencies:
248248
- huggingface-hub==0.20.2
249249
- safetensors==0.4.1
250250
- timm==0.9.12
251-

configs/clip.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extraction_total: null # extract a fix number of frames. It is mutually exclusiv
77

88
# Extraction Parameters
99
device: 'cuda:0' # device as in `torch`, can be 'cpu'
10-
on_extraction: 'print' # what to do once the features are extracted. Can be ['print', 'save_numpy', 'save_pickle']
10+
on_extraction: 'print' # what to do once the features are extracted. Can be ['print', 'save_numpy', 'save_pickle', 'save_h5']
1111
output_path: './output' # where to store results if saved
1212
tmp_path: './tmp' # folder to store the temporary files used for extraction (frames or aud files)
1313
keep_tmp_files: false # to keep temp files after feature extraction.

configs/i3d.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extraction_fps: null # For original video fps, leave as "null" (None)
88

99
# Extraction Parameters
1010
device: 'cuda:0' # device as in `torch`, can be 'cpu'
11-
on_extraction: 'print' # what to do once the features are extracted. Can be ['print', 'save_numpy', 'save_pickle']
11+
on_extraction: 'print' # what to do once the features are extracted. Can be ['print', 'save_numpy', 'save_pickle', 'save_h5']
1212
output_path: './output' # where to store results if saved
1313
tmp_path: './tmp' # folder to store the temporary files used for extraction (frames or aud files)
1414
keep_tmp_files: false # to keep temp files after feature extraction.

configs/r21d.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extraction_fps: null # For original video fps, leave unspecified "null" (None)
77

88
# Extraction Parameters
99
device: 'cuda:0' # device as in `torch`, can be 'cpu'
10-
on_extraction: 'print' # what to do once the features are extracted. Can be ['print', 'save_numpy', 'save_pickle']
10+
on_extraction: 'print' # what to do once the features are extracted. Can be ['print', 'save_numpy', 'save_pickle', 'save_h5']
1111
output_path: './output' # where to store results if saved
1212
tmp_path: './tmp' # folder to store the temporary files used for extraction (frames or aud files)
1313
keep_tmp_files: false # to keep temp files after feature extraction.

configs/raft.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ finetuned_on: 'sintel' # also 'kitti' is supported
99
# Extraction Parameters
1010
device: 'cuda:0' # device as in `torch`, can be 'cpu'
1111
batch_size: 1 # increase the extraction speed with batching
12-
on_extraction: 'print' # what to do once the features are extracted. Can be ['print', 'save_numpy', 'save_pickle']
12+
on_extraction: 'print' # what to do once the features are extracted. Can be ['print', 'save_numpy', 'save_pickle', 'save_h5']
1313
output_path: './output' # where to store results if saved
1414
tmp_path: './tmp' # folder to store the temporary files used for extraction (frames or aud files)
1515
keep_tmp_files: false # to keep temp files after feature extraction.

configs/resnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extraction_total: null # extract a fix number of frames. It is mutually exclusiv
77

88
# Extraction Parameters
99
device: 'cuda:0' # device as in `torch`, can be 'cpu'
10-
on_extraction: 'print' # what to do once the features are extracted. Can be ['print', 'save_numpy', 'save_pickle']
10+
on_extraction: 'print' # what to do once the features are extracted. Can be ['print', 'save_numpy', 'save_pickle', 'save_h5']
1111
output_path: './output' # where to store results if saved
1212
tmp_path: './tmp' # folder to store the temporary files used for extraction (frames or aud files)
1313
keep_tmp_files: false # to keep temp files after feature extraction.

configs/s3d.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ extraction_fps: 25 # 25 is my best guess. For original video fps, leave unspecif
66

77
# Extraction Parameters
88
device: 'cuda:0' # device as in `torch`, can be 'cpu'
9-
on_extraction: 'print' # what to do once the features are extracted. Can be ['print', 'save_numpy', 'save_pickle']
9+
on_extraction: 'print' # what to do once the features are extracted. Can be ['print', 'save_numpy', 'save_pickle', 'save_h5']
1010
output_path: './output' # where to store results if saved
1111
tmp_path: './tmp' # folder to store the temporary files used for extraction (frames or aud files)
1212
keep_tmp_files: false # to keep temp files after feature extraction.

configs/timm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extraction_total: null # extract a fix number of frames. It is mutually exclusiv
77

88
# Extraction Parameters
99
device: 'cuda:0' # device as in `torch`, can be 'cpu'
10-
on_extraction: 'print' # what to do once the features are extracted. Can be ['print', 'save_numpy', 'save_pickle']
10+
on_extraction: 'print' # what to do once the features are extracted. Can be ['print', 'save_numpy', 'save_pickle', 'save_h5']
1111
output_path: './output' # where to store results if saved
1212
tmp_path: './tmp' # folder to store the temporary files used for extraction (frames or aud files)
1313
keep_tmp_files: false # to keep temp files after feature extraction.

configs/vggish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ feature_type: 'vggish'
33

44
# Extraction Parameters
55
device: 'cuda:0' # device as in `torch`, can be 'cpu'
6-
on_extraction: 'print' # what to do once the features are extracted. Can be ['print', 'save_numpy', 'save_pickle']
6+
on_extraction: 'print' # what to do once the features are extracted. Can be ['print', 'save_numpy', 'save_pickle', 'save_h5']
77
output_path: './output' # where to store results if saved
88
tmp_path: './tmp' # folder to store the temporary files used for extraction (frames or aud files)
99
keep_tmp_files: false # to keep temp files after feature extraction.

0 commit comments

Comments
 (0)