No description
  • Jupyter Notebook 100%
Find a file
@SakulFlee | Lukas Weber f24154617e
Requirements simplification
2026-04-15 17:19:36 +02:00
.cache New attempt 2026-04-11 13:40:50 +02:00
.ipython/profile_default New attempt 2026-04-11 13:40:50 +02:00
.local/share/jupyter/runtime New attempt 2026-04-11 13:40:50 +02:00
cache New attempt 2026-04-11 13:40:50 +02:00
data Further toying around with algorithms 2026-04-10 16:54:04 +02:00
.dockerignore Trying to get this to work 2026-04-04 00:15:23 +02:00
.gitattributes LFS cache 2026-04-07 23:12:07 +02:00
01_train_som_OLD_corrupt.ipynb New attempt 2026-04-11 13:40:50 +02:00
02_analyze.ipynb Trying to get this to work 2026-04-04 00:15:23 +02:00
03_train_som_60feat.ipynb 3rd attempt with a MFCC 2026-04-15 17:18:56 +02:00
04_train_som_julia.ipynb 4th attempt with Julia 2026-04-15 17:19:10 +02:00
docker-compose.yml Further toying around with algorithms 2026-04-10 16:54:04 +02:00
Dockerfile Trying to get this to work 2026-04-04 00:15:23 +02:00
project.ipynb Various changes to orginal project 2026-04-15 17:19:26 +02:00
README.md Trying to get this to work 2026-04-04 00:15:23 +02:00
requirements.txt Requirements simplification 2026-04-15 17:19:36 +02:00
SOM.ipynb 5th attempt with a simpler approach 2026-04-15 17:19:16 +02:00
utils.py New attempt 2026-04-11 13:40:50 +02:00

Pig Vocalization Analysis with Self-Organizing Maps (SOM)

This project analyzes pig vocalizations using a Self-Organizing Map (SOM) to identify meaningful clusters in the audio data. The system can classify different types of pig sounds (e.g., happy, sad, hungry, in pain) and estimate the age of the animal based on vocal characteristics.

Project Structure

SOM/
├── requirements.txt          # Python dependencies
├── utils.py                 # Audio processing utilities
├── 01_train_som.ipynb       # Training notebook for SOM model
├── 01_train_som_updated.ipynb # Updated training notebook using real data
├── 02_analyze.ipynb         # Analysis notebook for new samples
├── 02_analyze_updated.ipynb # Updated analysis notebook using real data
├── data/                    # Audio files and metadata
│   ├── _index.csv           # Metadata for audio files
│   └── *.wav                # Audio recordings
├── models/                  # Trained SOM models
├── reports/                 # Analysis reports
└── visualizations/          # Generated plots and charts

Setup

  1. Install the required dependencies:
pip install -r requirements.txt
  1. Place your audio files in the data/ directory
  2. Ensure the _index.csv file is present with metadata

Usage

Training Phase

  1. Run 01_train_som_updated.ipynb to train the SOM model on your audio data
  2. The notebook will:
    • Load audio files from the data/ directory
    • Process and segment vocalizations
    • Extract features using FFT and MFCC
    • Train the SOM model
    • Generate visualizations
    • Save the trained model

Analysis Phase

  1. Run 02_analyze_updated.ipynb to analyze new audio samples
  2. The notebook will:
    • Load the trained SOM model
    • Process new audio files
    • Map samples to SOM clusters
    • Generate reports and visualizations
    • Export cluster likelihoods

Features

  • Audio Processing: Automatically detects and segments vocalizations from silence
  • Feature Extraction: Uses FFT and MFCC for audio characterization
  • Clustering: Self-Organizing Map for unsupervised clustering
  • Age Estimation: Estimates animal age based on dominant frequency
  • Visualization: Multiple plots showing cluster distributions
  • Reporting: Detailed text and CSV reports

Data Format

The _index.csv file contains metadata for each recording with columns:

  • filename: Name of the audio file
  • species: Type of animal
  • sex: Gender of the animal
  • age: Age category
  • sound_type: Type of vocalization
  • Additional metadata fields

Output Files

After running the analysis, you'll find:

  • models/trained_som.pkl: Trained SOM model
  • data/som_index.csv: Cluster index with labels
  • reports/mapping_results.csv: Direct mapping of samples to clusters
  • reports/cluster_likelihood_report.csv: Probabilities for each cluster
  • reports/cluster_summary_report.csv: Summary statistics
  • reports/analysis_report.txt: Comprehensive text report
  • visualizations/*.png: Charts and plots

Customization

You can customize the analysis by modifying:

  • SOM grid size (X and Y dimensions)
  • Feature extraction parameters
  • Cluster labeling heuristics
  • Audio processing thresholds

Notes

  • The system works with various audio formats (WAV, MP3, FLAC, etc.)
  • Sampling rate is standardized to 22050 Hz
  • The age estimation is based on frequency analysis (higher pitch = younger animal)
  • Cluster labels are preliminary and should be validated by domain experts

Docker Setup

To avoid installation issues and ensure compatibility, you can run this project using Docker:

  1. Prerequisites: Install Docker and Docker Compose

  2. Build and run the container:

    docker-compose up --build
    
  3. Access Jupyter Lab: Open your browser and navigate to http://localhost:8888

  4. Working with the notebooks: The notebooks will be accessible through the Jupyter interface at http://localhost:8888

The Docker setup includes all necessary dependencies and creates a consistent environment that avoids the installation issues experienced with pandas and other packages.

To run commands in the container directly:

# Access the container
docker-compose exec som-analysis bash

# Run a specific notebook
docker-compose exec som-analysis python -m ipykernel notebook 01_train_som_updated.ipynb