Skip to content

Latest commit

 

History

History
76 lines (60 loc) · 2.39 KB

README.md

File metadata and controls

76 lines (60 loc) · 2.39 KB

Tensorflow Extra

TensorFlow GPU & TPU compatible operations: MelSpectrogram, TimeFreqMask, CutMix, MixUp, ZScore, and more

Installation

For Stable version

!pip install tensorflow-extra

or For updated version

!pip install git+https://github.com/awsaf49/tensorflow_extra

Usage

To check use case of this library, checkout BirdCLEF23: Pretraining is All you Need notebook. It uses this library along with Multi Stage Transfer Learning for Bird Call Identification task.

Layers

MelSpectrogram

Converts audio data to mel-spectrogram in GPU/TPU.

import tensorflow_extra as tfe
audio2spec = tfe.layers.MelSpectrogram()
spec = audio2spec(audio)

Time Frequency Masking

Can also control number of stripes.

time_freq_mask = tfe.layers.TimeFreqMask()
spec = time_freq_mask(spec)

CutMix

Can be used with audio, spec, image. For spec full freq resolution can be used using full_height=True.

cutmix = tfe.layers.CutMix()
audio = cutmix(audio, training=True) # accepts both audio & spectrogram

MixUp

Can be used with audio, spec, image. For spec full freq resolution can be used using full_height=True.

mixup = tfe.layers.MixUp()
audio = mixup(audio, training=True)  # accepts both audio & spectrogram

Normalization

Applies standardization and rescaling.

norm = tfe.layers.ZScoreMinMax()
spec = norm(spec)

Activations

SmeLU: Smooth ReLU

import tensorflow as tf
import tensorflow_extra as tfe

a = tf.constant([-2.5, -1.0, 0.5, 1.0, 2.5])
b = tfe.activations.smelu(a)  # array([0., 0.04166667, 0.6666667 , 1.0416666 , 2.5])