Audio Classification
PyTorch
LiteRT
LiteRT
kernel-insect-cnn
insect
bioacoustics
experimental
local-inference
Instructions to use ganesh333/kernel-insect-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use ganesh333/kernel-insect-classifier with LiteRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Download predict.py from ganesh333/kernel-insect-classifier: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/ganesh333/kernel-insect-classifier/resolve/main/predict.py
- Command line
-
hf download hf://ganesh333/kernel-insect-classifier/predict.py
-
curl -L -o predict.py https://huggingface.co/ganesh333/kernel-insect-classifier/resolve/main/predict.py
1.27 kB
| import argparse, json, sys | |
| from pathlib import Path | |
| from src.inference import predict_wav | |
| ROOT=Path(__file__).resolve().parent | |
| def resolve(p): | |
| """Use the path as given if it exists, else relative to this project folder (so the script works from any cwd).""" | |
| p=Path(p) | |
| return p if p.exists() or p.is_absolute() else ROOT/p | |
| p=argparse.ArgumentParser(description='Run the local experimental Kernel insect classifier') | |
| p.add_argument('wav'); p.add_argument('--model-dir',default='.') | |
| p.add_argument('--device',default='cpu') | |
| a=p.parse_args() | |
| wav=Path(a.wav); model_dir=resolve(a.model_dir) | |
| if not wav.is_file(): sys.exit(f"Audio file not found: {wav.resolve()}\nPass the path to a real recording (.wav, or .flac/.ogg/.mp3 with soundfile installed), e.g. python predict.py C:/path/to/clip.wav --model-dir full_model") | |
| if not (model_dir/'model.h5').is_file(): sys.exit(f"No model.h5 in {model_dir}. Use --model-dir . (baseline), full_model or finetuned_cnn.") | |
| try: | |
| print(json.dumps(predict_wav(wav,model_dir,a.device),indent=2)) | |
| except (ValueError,RuntimeError) as e: | |
| # soundfile raises LibsndfileError (a RuntimeError) for unreadable files. | |
| sys.exit(f"Could not read {wav} as audio ({e}). Convert it first, e.g. ffmpeg -i input.mp3 -ac 1 output.wav") | |