Skip to content

Latest commit

 

History

History
218 lines (149 loc) · 9.99 KB

File metadata and controls

218 lines (149 loc) · 9.99 KB

This repository was based from the IBM pre-trained Audio Classifer. For the purpose of this project, we utilised this model to identify distress signals such as screams and sirens.

To set up the docker:

cd distress-identifier
docker build -t distress-identifier .

We tested the model with a screaming audio file (found in samples/screaming_output.wav) and obtained the following results:

Sound screenshot

The screaming audio file results can be achieved via the following:

$ docker run -it -p 5000:5000 distress-identifier
$ curl -F "audio=@samples/screaming_crowd.wav;type=audio/wav" -XPOST http://localhost:5000/model/predict

Please refer below for the full guide on how to get the distress identifier model working working


Build Status Website Status

IBM Developer Model Asset Exchange: Audio Classifier

This repository contains code to instantiate and deploy an audio classification model. This model recognizes a signed 16-bit PCM wav file as an input, generates embeddings, applies PCA transformation/quantization, uses the embeddings as an input to a multi-attention classifier and outputs top 5 class predictions and probabilities as output. The model currently supports 527 classes which are part of the Audioset Ontology. The classes and the label_ids can be found in class_labels_indices.csv. The model was trained on AudioSet as described in the paper 'Multi-level Attention Model for Weakly Supervised Audio Classification' by Yu et al.

The model has been tested across multiple audio classes, however it tends to perform best for Music / Speech categories. This is largely due to the bias towards these classes in the training dataset (90% of audio belong to either of these categories). Though the model is trained on data from Audioset which was extracted from YouTube videos, the model can be applied to a wide range of audio files outside the domain of music/speech. The test assets provided along with this model provide a broad range.

The model files are hosted on IBM Cloud Object Storage. The code in this repository deploys the model as a web service in a Docker container. This repository was developed as part of the IBM Developer Model Asset Exchange and the public API is powered by IBM Cloud.

Model Metadata

Domain Application Industry Framework Training Data Input Data Format
Audio Classification Multi Keras/TensorFlow Google AudioSet signed 16-bit PCM WAV audio file

References

Licenses

Component License Link
This repository Apache 2.0 LICENSE
Model Files Apache 2.0 AudioSet
Model Code MIT AudioSet Classification
Test Samples Various Samples README

Pre-requisites:

  • docker: The Docker command-line interface. Follow the installation instructions for your system.
  • The minimum recommended resources for this model is 8 GB Memory and 4 CPUs.

Deployment options

Deploy from Docker Hub

To run the docker image, which automatically starts the model serving API, run:

$ docker run -it -p 5000:5000 codait/max-audio-classifier

This will pull a pre-built image from Docker Hub (or use an existing image if already cached locally) and run it. If you'd rather checkout and build the model locally you can follow the run locally steps below.

Deploy on Red Hat OpenShift

You can deploy the model-serving microservice on Red Hat OpenShift by following the instructions for the OpenShift web console or the OpenShift Container Platform CLI in this tutorial, specifying codait/max-audio-classifier as the image name.

Deploy on Kubernetes

You can also deploy the model on Kubernetes using the latest docker image on Docker Hub.

On your Kubernetes cluster, run the following commands:

$ kubectl apply -f https://raw.githubusercontent.com/IBM/MAX-Audio-Classifier/master/max-audio-classifier.yaml

The model will be available internally at port 5000, but can also be accessed externally through the NodePort.

A more elaborate tutorial on how to deploy this MAX model to production on IBM Cloud can be found here

Run Locally

  1. Build the Model
  2. Deploy the Model
  3. Use the Model
  4. Development
  5. Cleanup

1. Build the Model

Clone this repository locally. In a terminal, run the following command:

$ git clone https://github.com/IBM/MAX-Audio-Classifier.git

Change directory into the repository base folder:

$ cd MAX-Audio-Classifier

To build the Docker image locally, run:

$ docker build -t max-audio-classifier .

All required model assets will be downloaded during the build process. Note that currently this Docker image is CPU only (we will add support for GPU images later).

2. Deploy the Model

To run the Docker image, which automatically starts the model serving API, run:

$ docker run -it -p 5000:5000 max-audio-classifier

3. Use the Model

The API server automatically generates an interactive Swagger documentation page. Go to http://localhost:5000 to load it. From there you can explore the API and also create test requests.

Note : The input is a 10 second signed 16-bit PCM wav audio file. Files longer than 10 seconds will be clipped so that only the first 10 seconds will be used by the model. Conversely, files shorter than 10 seconds will be repeated to create a clip 10 seconds in length.

Use the model/predict endpoint to load a signed 16-bit PCM wav audio file (you can use the fireworks.wav file located in the samples folder) and get predictions from the API.

Swagger Doc Screenshot

You can also test it on the command line, for example (with the thunder.wav file):

$ curl -F "audio=@samples/thunder.wav;type=audio/wav" -XPOST http://localhost:5000/model/predict

You should see a JSON response like that below:

{
    "status": "ok",
    "predictions": [
        {
            "label_id": "/m/06mb1",
            "label": "Rain",
            "probability": 0.7376469373703003
        },
        {
            "label_id": "/m/0ngt1",
            "label": "Thunder",
            "probability": 0.60517817735672
        },
        {
            "label_id": "/t/dd00038",
            "label": "Rain on surface",
            "probability": 0.5905200839042664
        },
        {
            "label_id": "/m/0jb2l",
            "label": "Thunderstorm",
            "probability": 0.5793699026107788
        },
        {
            "label_id": "/m/07yv9",
            "label": "Vehicle",
            "probability": 0.34878015518188477
        }
    ]
}

4. Development

To run the Flask API app in debug mode, edit config.py to set DEBUG = True under the application settings. You will then need to rebuild the Docker image (see step 1).

5. Cleanup

To stop the Docker container, type CTRL + C in your terminal.

Resources and Contributions

If you are interested in contributing to the Model Asset Exchange project or have any queries, please follow the instructions here.