Skip to main content

spectrogram layers

Project description

SPELA - spectrogram layers

Rewrote kapre using tensorflow.keras
credits go to Keunwoo Choi for writing kapre

My main goal for rewriting it with tensorflow.keras is to use it with TensorFlow Lite
since Keunwoo Choi used core keras and I had problems converting the model to
tensorflow lite.

Implementing audio features inside the keras layers allows the preprocessing
computations to be done on the GPU as highlighted in their paper

Checkout this Speaker Recognition project to see the usage of Spela.

Installation

The package uses tensorflow but is not listed as requirement, please install it.

pip install spela

or

git clone https://github.com/kongkip/spela.git
cd spela
python setup.py install

Usage

spectrogram

import tensorflow as tf
from spela.spectrogram import Spectrogram

# a one channel audio with 16000 sample rate
input_shape = (1, 16000)

x = get_data()
y = get_data()


model = tf.keras.Sequential()
model.add(Spectrogram(n_dft=512, n_hop=256, input_shape=(input_shape),
                      return_decibel_spectrogram=True, power_spectrogram=2.0,
                      trainable_kernel=False, name='static_stft'))

model.compile(optimizer=tf.keras.optimizers.Adam(lr=0.001), loss=tf.keras.losses.categorical_crossentropy
              , metrics=["acc"])

print(model.summary())

model.fit(x,y)

Mel Spectrogram

import tensorflow as tf
from spela.melspectrogram import Melspectrogram

# a one channel audio with 16000 sample rate
input_shape = (1, 16000)

x = get_data()
y = get_data()

model = tf.keras.Sequential()
model.add(Melspectrogram(sr=SR, n_mels=128,
          n_dft=512, n_hop=256, input_shape=input_shape,
          return_decibel_melgram=True,
          trainable_kernel=False, name='melgram'))

model.compile(optimizer=tf.keras.optimizers.Adam(lr=0.001), loss=tf.keras.losses.categorical_crossentropy
              , metrics=["acc"])

print(model.summary())

model.fit(x,y)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spela-0.0.5.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spela-0.0.5-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file spela-0.0.5.tar.gz.

File metadata

  • Download URL: spela-0.0.5.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200622 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for spela-0.0.5.tar.gz
Algorithm Hash digest
SHA256 a31d37d28a2f3a179227e0d9feb0a888fdbfd272cb85d2a72e719094a76926bc
MD5 c123abfd3717b0042c6cc1d17f1747e0
BLAKE2b-256 aa1c5235e4ccfe604dd5463ec03ba05002377943d16ba6edc817c4b9e369e044

See more details on using hashes here.

File details

Details for the file spela-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: spela-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1.post20200622 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for spela-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2fd6f5c917c25e2919e3b3e68ef38d0b9aa921671f2b1f404b9968b85f7d8fe5
MD5 e7291cf1ac7048c225eee55a06f81246
BLAKE2b-256 470b28a87f121e06fe85c2b5782f4d14cd309e3540bd06f7554ba9b40611d3df

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page