Feature/raven export wrapper - #125
Open
shaing10 wants to merge 16 commits into
Open
Conversation
Introduces core components for exporting soundbay models to Raven Intelligence: - RavenExportModel: Wraps trained models with preprocessing pipeline - PreprocessingPipeline: Embeds resampling and preprocessing from args.yaml - PeakNormalizeModule/UnitNormalizeModule: Export-compatible normalization - _get_model_class: Lazy model loading to avoid transformers dependency The wrapper accepts raw audio input and outputs class probabilities, matching Raven Intelligence expected interface. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Adds functions to export wrapped models to Raven Intelligence format: - export_to_onnx: Export to ONNX format (limited by STFT support) - export_to_torchscript: Export to TorchScript (recommended) - create_raven_model_package: One-command export from soundbay checkpoint Creates complete .ravenmodel package including: - JSON configuration file (.ravenmodel) - Exported model (model.pt or model.onnx) - Labels file (labels.txt) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Adds support for packaging pre-existing TorchScript models: - create_raven_model_package_from_torchscript: Package external .pt models with custom labels, sample rate, and duration settings Adds CLI interface for command-line usage: python -m soundbay.raven_export checkpoint.pth --output-dir /path --name MyModel 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Relocate from soundbay/ to scripts/ for better organization - Add comprehensive usage examples in module docstring: - CLI usage for exporting soundbay checkpoints - Python API for checkpoint export - Python API for packaging existing TorchScript models - Document output structure and supported architectures - Add notes on TorchScript vs ONNX and DJL compatibility 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Code review fixes: - Remove duplicated ResNet182D/Squeezenet2D class definitions - Import model classes directly from soundbay.models (requires transformers) - Add checkpoint file existence check in from_checkpoint() - Remove redundant conditional for input_dims - Move shutil import to top of file - Add --format CLI option for export format selection 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add all CLI options to usage example (--format, --no-softmax) - Add REQUIREMENTS section noting transformers dependency - Clarify input tensor shapes for both export methods 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- PeakNormalizeModule: use global min/max (not per-dimension) - UnitNormalizeModule: use global mean/std (not per-dimension) - Add documentation explaining why nn.Module re-implementations are needed - Reference original implementations in soundbay/data.py This ensures exported models produce identical results to training. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add explicit error for MinFreqFiltering and SlidingWindowNormalize (these use numpy/random operations incompatible with TorchScript) - Document supported vs unsupported preprocessors in module docstring - Add inline comments referencing original implementations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
PeakNormalizeModule and UnitNormalizeModule now use per-sample normalization with keepdim=True, ensuring correct broadcasting for any batch size during Raven Intelligence inference. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Shows step-by-step progress during model export: - Step 1/4: Loading checkpoint and model creation - Step 2/4: TorchScript tracing - Step 3/4: Labels file creation - Step 4/4: Raven config generation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Raven Intelligence applies sigmoid independently to each model output. Models exported with softmax baked in get double-transformed, compressing scores into a narrow unusable range. This adds a compensate-for-sigmoid option that outputs inverse-sigmoid(softmax(logits)), so Ravens sigmoid recovers exact softmax probabilities (scores sum to 1.0). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
PeakNormalizeModule and UnitNormalizeModule previously used per-sample normalization (reducing all dims except batch). The originals in soundbay/data.py use global min/max/mean/std across all dims. Simplified to match exactly. Also added validation for MinFreqFiltering to error if min_freq != 0 (only no-op case is supported for TorchScript export). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The original soundbay PeakNormalize/UnitNormalize use global min/max/mean/std because they run per-sample inside __getitem__ (no batch dim). When Raven sends batch_size>1, we must reduce all dims EXCEPT batch to match the original's per-sample semantics. Added comments explaining the reasoning to prevent future regressions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
mosheman5
reviewed
Apr 29, 2026
mosheman5
left a comment
Collaborator
There was a problem hiding this comment.
looks good
do we still new --compensate-for-sigmoid in the default/recommended command?
Collaborator
Author
Current Raven Intelligence releases allow disabling sigmoid post-processing, so plain softmax output is now the correct default. Demotes --compensate-for-sigmoid to legacy status (workaround for older Raven versions without this option). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
mosheman5
approved these changes
May 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
scripts/raven_export.py— exports soundbay checkpoints (ResNet182D, Squeezenet2D) to Raven Intelligence.ravenmodelpackages with preprocessing baked innn.Modules for TorchScript compatibility--compensate-for-sigmoidflag (recommended): Raven applies sigmoid to model outputs internally, so this option outputsinverse_sigmoid(softmax(logits))— Raven's sigmoid then recovers exact softmax probabilities that sum to 1.0Usage
Recommended (until Raven publishes a new version with more DOFs in their post-processing logic): compensate for Raven's sigmoid post-processing
python scripts/raven_export.py /path/to/checkpoint/best.pth \ --output-dir ~/Raven\ Workbench/Raven\ Intelligence/Models/ \ --name My_Detector \ --compensate-for-sigmoidRaw logits (no activation, Raven applies sigmoid):
python scripts/raven_export.py /path/to/checkpoint/best.pth \ --name My_Detector --no-softmaxWhy some modules are re-implemented
TorchScript export requires all operations to be
nn.Moduleinstances or pure torch ops. Several soundbay preprocessors can't be traced as-is:PeakNormalize__call__, notnn.Module— TorchScript can't trace itnn.Modulewrapper with identical logic (verified: 0.0 diff)UnitNormalizenn.ModuleLibrosaPcenlibrosa.core.pcen(NumPy/SciPy) — can't run in TorchScripttorch.jit.scriptfor the IIR loop. Matches librosa's filter coefficients andlfilter_ziinitialization exactlyMinFreqFilteringnumpy.floornn.Identity(validated: onlymin_freq=0configs are supported; errors on non-zero)Test plan