HandNet / tools /README.md
twerdster's picture
Document the CC BY 4.0 release and add a native preview dataset
8eb3e76 verified
|
Raw History Blame Contribute Delete
5.03 kB

HandNet utilities

Inspect a frame

inspect_sample.py is a new, standalone Python reader for the archival MAT files. It prints field shapes, dtypes, finite ranges, sensor positions and zero-based projected sensor pixels. It can export a calibrated point cloud. It does not download data or run a learned detector.

Install dependencies in your preferred Python environment:

python -m pip install numpy scipy

From a downloaded copy of this repository:

# Inspect the first Data*.mat member of a ZIP without extracting it.
python tools/inspect_sample.py archives/ValidationData.zip

# List available MAT members, then select an exact member or zero-based index.
python tools/inspect_sample.py archives/ValidationData.zip --list
python tools/inspect_sample.py archives/ValidationData.zip --index 12
python tools/inspect_sample.py archives/ValidationData.zip --member ValidationData/Data_0000000.mat

# Inspect an already extracted MAT file.
python tools/inspect_sample.py /path/to/Data_0000000.mat

# Export a sparse, segmented point cloud and all sensor annotations.
python tools/inspect_sample.py archives/ValidationData.zip --step 3 --pointcloud frame.npz

The example --member name is illustrative: use --list to obtain the archive's actual member path. --index selects a member in sorted filename order, not chronological order. For TrainData.rar, first use a RAR-capable extractor and inspect an extracted MAT file. The script deliberately does not invoke external archive executables or extract archive contents to disk.

Point-cloud output is a compressed NumPy archive with xyz_mm (N,3), sensor_xyz_mm (3,6), sensor_rotations (3,3,6), pixel_uv (N,2) and K (3,3). It retains camera axes (+X right, +Y down, +Z away). By default only nonzero depth within segmap is exported. Add --include-background to keep all nonzero depth. Point-cloud export creates the requested output file and refuses to overwrite an existing one.

The default calibration is ../calibration.json, resolved relative to the script. Use --calibration custom.json for another compatible calibration file containing a K matrix. This reader targets the MAT format distributed by HandNet, not arbitrary MAT v7.3/HDF5 datasets.

Reproduce the Explorer sample bundle

extract_space_samples.py builds the compact image/point-cloud bundle used by HandNet Explorer. It reads MAT members directly from five source ZIPs, without extracting the full archives. Install its additional image dependency:

python -m pip install numpy scipy pillow
python tools/extract_space_samples.py --archive-dir ./archives --output-dir ./explorer-data

Use a new, empty output directory. The source directory must contain TestData.zip, TestData_Perturbed.zip, ValidationData.zip, ValidationData_DerotGT.zip and TrainData_DerotGT.zip. The original RAR is not used in this small visualization selection.

The deterministic selection contains 96 frames: 24 original test, 24 perturbed test, 16 original validation, 16 ground-truth-normalized validation, and 16 ground-truth-normalized training frames. Within each archive, it chooses evenly spaced indices in sorted member order. Corresponding test/validation variants share selected member indices; source session/frame IDs are retained for inspection.

The output contains samples.json, sparse little-endian float32 XYZ clouds, and PNG images for depth, IR, source labels and all six sensor heatmaps. Point clouds keep every second pixel in each axis within the nonzero-depth hand mask. Depth and IR are contrast stretched for viewing; heatmaps use a fixed 0-to-1 grayscale scale. These are display derivatives, not replacement training archives. Each sample records its source archive, member and MAT SHA-256 hash. The generated manifest uses paths relative to an Explorer root with the bundle in data/; copy explorer-data/ to the app's data/ directory when reproducing the site.

Reproduce the Hub preview

After generating the Explorer bundle, optionally export its 96 display rows to the Hub-compatible Parquet preview:

python -m pip install datasets pyarrow pillow
python tools/build_parquet_preview.py --bundle-dir ./explorer-data --output ./preview/samples.parquet

The exporter embeds the depth, infrared and colorized-label PNGs, sensor poses and source identifiers; it also writes preview/samples.schema.json. It checks the 96-row count, Hugging Face schema metadata and an image-byte round trip. This preview does not contain every frame, the full point clouds or raw depth arrays. Use the original archives for training and quantitative image analysis.

Licenses

The new utilities and this tool documentation use the MIT license. Dataset arrays and their visualization derivatives use the repository's CC BY 4.0 license. Historical MATLAB code is linked in the dataset documentation and is not copied into these utilities.