Project Page β’ arXiv
Overview of implicit, garbage class, and discriminator methods for few-shot open-set action recognition
Combined results for SAFSAR in 5-way 1-shot and 5-shot settings:
| Dataset | OS-Method | FS ACC 1-shot | FS ACC 5-shot | OS ACC 1-shot | OS ACC 5-shot | AUROC 1-shot | AUROC 5-shot |
|---|---|---|---|---|---|---|---|
| Diving48 | Softmax | 63.49 | 74.12 | 64.16 | 65.36 | 68.48 | 71.49 |
| Diving48 | EOS | 64.43 | 72.80 | 62.91 | 64.94 | 68.64 | 74.60 |
| Diving48 | GC | 65.01 | 76.32 | 64.89 | 69.36 | 70.18 | 75.82 |
| Diving48 | FR-Disc | 68.83 | 78.58 | 66.22 | 70.29 | 71.28 | 76.55 |
| SSv2 | Softmax | 62.11 | 74.08 | 62.29 | 69.61 | 70.39 | 77.05 |
| SSv2 | EOS | 62.97 | 73.84 | 65.08 | 69.90 | 71.56 | 79.60 |
| SSv2 | GC | 62.47 | 76.24 | 64.06 | 70.89 | 69.20 | 77.62 |
| SSv2 | FR-Disc | 63.37 | 77.88 | 66.56 | 73.52 | 72.18 | 81.56 |
| NTURGBD | Softmax | 88.31 | 91.58 | 79.90 | 81.45 | 87.76 | 91.44 |
| NTURGBD | EOS | 87.63 | 91.86 | 80.10 | 82.18 | 88.17 | 91.89 |
| NTURGBD | GC | 89.07 | 92.40 | 81.78 | 81.51 | 89.30 | 89.37 |
| NTURGBD | FR-Disc | 89.97 | 95.54 | 82.95 | 86.53 | 89.78 | 94.31 |
| HMDB51 | Softmax* | 65.29 | 79.68 | 64.44 | 72.40 | 70.76 | 81.79 |
| HMDB51 | EOS* | 69.19 | 80.18 | 66.23 | 72.48 | 74.60 | 81.45 |
| HMDB51 | GC | 62.85 | 76.74 | 60.19 | 64.30 | 68.99 | 76.45 |
| HMDB51 | FR-Disc | 72.38 | 85.17 | 68.87 | 76.99 | 77.48 | 87.94 |
| UCF101 | Softmax* | 95.04 | 98.32 | 80.59 | 91.25 | 94.55 | 98.03 |
| UCF101 | EOS* | 94.84 | 98.78 | 81.30 | 89.32 | 95.18 | 98.31 |
| UCF101 | GC | 79.98 | 86.33 | 59.88 | 57.49 | 75.15 | 81.91 |
| UCF101 | FR-Disc | 95.72 | 99.28 | 86.82 | 91.52 | 95.19 | 98.89 |
* Methods marked with an asterisk were trained for 1K iterations to prevent overfitting on that dataset.
This work has been submitted for review at the ICPR 2026 conference.
This repository contains the implementation of few-shot learning methods adapted for open-set action recognition. The codebase supports various approaches to handle unknown classes during few-shot video classification tasks.
FR-Disc checkpoints (SAFSAR, STRM) and the FSOS-AR benchmark splits are available on the Hugging Face Hub, collected here:
HSP-IIT/fsos-ar-benchmark collection
- Dataset splits:
HSP-IIT/fsos-ar-benchmark(load_dataset("HSP-IIT/fsos-ar-benchmark", "<config>")) - Model checkpoints: 8 SAFSAR + 3 STRM repos, one per dataset/shot (see the collection above)
The repository implements few-shot action recognition models:
- SAFSAR - Self-Attention Few-Shot Action Recognition
- STRM - Spatiotemporal Relational Matching
- SSv2 - Something-Something V2
- HMDB51 - Human Motion Database
- UCF101 - UCF Action Recognition Dataset
- NTURGBD120 - NTU RGB+D 120 Action Recognition
- Diving48 - Fine-grained Diving Dataset
Four different approaches for handling open-set scenarios:
- softmax - Standard softmax baseline (implicit method)
- eos - Entropic Open-Set loss
- discriminator - Binary discriminator approach
- gc - Garbage Class method
- Conda or Miniconda
- Python 3.10 or above
- CUDA-compatible GPU (recommended for training)
- Clone the repository:
git clone <repository-url>
cd fsosar- Create and activate the conda environment:
conda env create -f environment.yaml
conda activate fsosarThe environment includes:
- PyTorch with CUDA support
- Transformers (Hugging Face)
- CLIP (OpenAI)
- scikit-learn
- wandb (Weights & Biases)
- OpenCV, matplotlib, einops
- imageio
This repository does not redistribute the benchmark datasets. Download each dataset from its
official source (Diving48, SSv2, HMDB51, UCF101, NTURGBD120), then use the helper scripts in
data/ to extract per-video frames into a <dataset>/images/<class>/<video_id>/ layout:
data/prepare_diving48.py/data/extract_images_from_videos.py- extract equidistant frames from raw videos into the expected folder structuredata/ssv2_move_videos_inside_class_folders.py- reorganize SSv2 videos into per-class foldersdata/create_train_test_diving_ntu.py- build train/test split files for Diving48/NTURGBD120
The scripts contain example paths at the top (if __name__ == '__main__':) that must be edited to
point at your local dataset location before running them. The resulting images/ folder is what
configs/<Dataset>.json -> path (combined with FSOSAR_DATASETS_PATH, see below) must point to.
Few-shot train/test/val class splits are already provided under splits/.
utils.load_configs resolves dataset and log locations automatically on the author's own machines.
On any other machine (a fresh clone, CI, or your own workstation) it falls back to these environment
variables, so set them before training:
export FSOSAR_DATASETS_PATH=/path/to/datasets # parent dir containing e.g. Diving48/images (default: cwd)
export FSOSAR_LOG_PATH=/path/to/logs # where logs/checkpoints are written (default: cwd)
export FSOSAR_CONFIG=server # "server" (real training) or "local" (author's debug/eval config); default: server
export FSOSAR_HOST=my-machine # free-form tag used in checkpoint/log naming (default: hostname)For training a single model configuration:
python train.py --model SAFSAR --data Diving48 --os_loss discriminatorArguments:
--model: Choose fromSAFSAR,STRM--data: Choose fromSSv2,HMDB51,UCF101,NTURGBD120,Diving48--os_loss: Choose fromsoftmax,eos,discriminator,gc
For SLURM-based clusters, use the provided script in the jobs/ directory:
cd jobs
sbatch train_single_slurm.shEdit the script to customize:
- Job name, partition, and resource allocation
- Model, dataset, and open-set loss parameters
- Time limits and GPU requirements
For running multiple experiments in parallel:
cd jobs
./submit_batch_slurm.shCustomization options:
# Default usage (uses configurations in the script)
./submit_batch_slurm.sh
# Custom models and datasets
./submit_batch_slurm.sh --models SAFSAR,STRM --datasets UCF101,HMDB51 --os-losses softmax,gc
# Custom resource allocation
./submit_batch_slurm.sh --partition gpuv --gpus 4 --cpus 16 --memory 32G --time 48:00:00
# View help
./submit_batch_slurm.sh --helpAvailable options:
--models MODEL1,MODEL2,...- Comma-separated list of models--datasets DATA1,DATA2,...- Comma-separated list of datasets--os-losses LOSS1,LOSS2,...- Comma-separated list of open-set losses--partition PARTITION- SLURM partition (default: gpu)--time TIME- Time limit (default: 24:00:00)--cpus CPUS- CPUs per task (default: 20)--gpus GPUS- Number of GPUs (default: 4)--memory MEMORY- Memory allocation (default: 64G)
The batch submission script will:
- Validate all input parameters
- Display all job combinations that will be submitted
- Ask for confirmation before submission
- Submit jobs to SLURM with proper resource allocation
- Provide job IDs and monitoring commands
Useful SLURM commands:
squeue -u $USER # Check your job queue
squeue -j <job_id> # Check specific job status
scancel <job_id> # Cancel a job
scancel -u $USER # Cancel all your jobs
scontrol show job <job_id> # Show detailed job infofsosar/
βββ LICENSE # BSD 3-Clause License
βββ LICENSE_DEPENDENCIES.md # Comprehensive license report for all dependencies
βββ README.md # This file
βββ environment.yaml # Conda environment specification
βββ methods.png # Methods diagram
βββ configs/ # Configuration files for models and datasets
β βββ SAFSAR.json
β βββ STRM.json
β βββ SSv2.json
β βββ HMDB51.json
β βββ UCF101.json
β βββ Diving48.json
β βββ NTURGBD120.json
β βββ local_config.json # Author's local debug/eval config (FSOSAR_CONFIG=local)
β βββ server_config.json # Training config used by default (FSOSAR_CONFIG=server)
βββ models/ # Model implementations
β βββ __init__.py
β βββ safsar.py
β βββ strm.py
βββ jobs/ # SLURM job scripts
β βββ train_single_slurm.sh # Single job submission
β βββ train_batch_slurm.sh # Batch worker script
β βββ submit_batch_slurm.sh # Batch submission manager
β βββ download_checkpoints.sh # Download pretrained checkpoints
βββ splits/ # Dataset split files
β βββ diving/
β βββ hmdb_ARN/
β βββ ucf_ARN/
β βββ ssv2_OTAM/
β βββ kinetics_CMN/
β βββ nturgbd/
βββ data/ # Data preparation scripts
β βββ prepare_diving48.py
β βββ extract_images_from_videos.py
β βββ create_train_test_diving_ntu.py
β βββ get_classes_splits_classes_for_paper.py
β βββ visualize_confusion_matrix.py
β βββ visualize_confidence_histograms.py
β βββ visualize_features.py
βββ data_analysis/ # Analysis and visualization outputs (created at runtime)
β βββ confusion_matrices/
β βββ histograms/
β βββ saved_features/
β βββ confidence_scores/
βββ checkpoints/ # Saved model checkpoints (created at runtime)
β βββ SAFSAR/
β βββ strm/
βββ train.py # Main training script
βββ videoloader.py # Dataset loading utilities
βββ utils.py # Helper functions
βββ log_filter.py # Log filtering utility
Model and dataset configurations are stored in the configs/ directory as JSON files. Each configuration file contains:
- Model architecture parameters
- Training hyperparameters (learning rate, batch size, etc.)
- Dataset-specific settings
- Evaluation parameters
- Open-set loss specific configurations
To modify training behavior, edit the corresponding configuration files or override parameters in the training script.
The repository supports Weights & Biases (wandb) for experiment tracking:
- Training/validation metrics
- Confusion matrices
- Confidence score histograms
- Feature visualizations
- OSCR curves and AUPR scores
Checkpoints are automatically saved to:
logs/<shot>_<model>_<os_loss>_<dataset>_<timestamp>/
Several visualization scripts are provided in the data/ directory:
data/visualize_confusion_matrix.py- Generate confusion matricesdata/visualize_confidence_histograms.py- Analyze prediction confidencedata/visualize_features.py- t-SNE/UMAP feature space visualization
Results are saved to the data_analysis/ directory.
If you use this code for your research, please cite our paper (citation will be added after acceptance).
This project is licensed under the BSD 3-Clause License.
Copyright (c) 2025, Istituto Italiano di Tecnologia
See LICENSE for the full license text.
All dependencies use permissive licenses compatible with BSD 3-Clause. For detailed information about third-party licenses, see LICENSE_DEPENDENCIES.md.
This work builds upon several open-source implementations:
- CLIP by OpenAI
- Hugging Face Transformers
- PyTorch
For questions or issues, please open an issue in the repository or contact the authors.
Status: Under review at ICPR 2026