@ -2,6 +2,7 @@
*Author: Jael Gu*
*Author: Jael Gu*
< br / >
## Desription
## Desription
@ -10,19 +11,21 @@ Each vector represents for an audio clip with a fixed length of around 2s.
This operator is built on top of the original implementation of [CLMR ](https://github.com/Spijkervet/CLMR ).
This operator is built on top of the original implementation of [CLMR ](https://github.com/Spijkervet/CLMR ).
The [default model weight ](clmr_checkpoint_10000.pt ) provided is pretrained on [Magnatagatune Dataset ](https://paperswithcode.com/dataset/magnatagatune ) with [SampleCNN ](sample_cnn.py ).
The [default model weight ](clmr_checkpoint_10000.pt ) provided is pretrained on [Magnatagatune Dataset ](https://paperswithcode.com/dataset/magnatagatune ) with [SampleCNN ](sample_cnn.py ).
< br / >
## Code Example
## Code Example
Generate embeddings for the audio "test.wav".
Generate embeddings for the audio "test.wav".
*Write the pipeline in simplified style* :
*Write the pipeline in simplified style*:
```python
```python
from towhee import dc
import towhee
dc.glob('test.wav')
.audio_decode()
.time_window(range=10)
.audio_embedding.clmr()
towhee.glob('test.wav') \
.audio_decode() \
.time_window(range=10) \
.audio_embedding.clmr() \
.show()
.show()
```
```
| [-2.1045141, 0.55381, 0.4537212, ...] shape=(6, 512) |
| [-2.1045141, 0.55381, 0.4537212, ...] shape=(6, 512) |
@ -30,13 +33,13 @@ dc.glob('test.wav')
*Write a same pipeline with explicit inputs/outputs name specifications:*
*Write a same pipeline with explicit inputs/outputs name specifications:*
```python
```python
from towhee import dc
import towhee
dc.glob['path']('test.wav')
.audio_decode['path', 'audio']()
.time_window['audio', 'frames'](range=10)
.audio_embedding.clmr['frames', 'vecs']()
.select('vecs')
towhee.glob['path']('test.wav') \
.audio_decode['path', 'audio']() \
.time_window['audio', 'frames'](range=10) \
.audio_embedding.clmr['frames', 'vecs']() \
.select('vecs') \
.to_vec()
.to_vec()
```
```
[array([[-2.1045141 , 0.55381 , 0.4537212 , ..., 0.18805158,
[array([[-2.1045141 , 0.55381 , 0.4537212 , ..., 0.18805158,
@ -52,6 +55,8 @@ dc.glob['path']('test.wav')
[-2.0771549 , 0.5641221 , 0.43814805, ..., 0.1822092 ,
[-2.0771549 , 0.5641221 , 0.43814805, ..., 0.1822092 ,
0.33022994, -1.2070588 ]], dtype=float32)]
0.33022994, -1.2070588 ]], dtype=float32)]
< br / >
## Factory Constructor
## Factory Constructor
Create the operator via the following factory method
Create the operator via the following factory method
@ -60,26 +65,28 @@ Create the operator via the following factory method
**Parameters:**
**Parameters:**
*framework: str*
*framework: str*
The framework of model implementation.
The framework of model implementation.
Default value is "pytorch" since the model is implemented in Pytorch.
Default value is "pytorch" since the model is implemented in Pytorch.
< br / >
## Interface
## Interface
An audio embedding operator generates vectors in numpy.ndarray given an audio file path or a [towhee audio ](link/to/AudioFrame/api/doc ).
An audio embedding operator generates vectors in numpy.ndarray given an audio file path or a [towhee audio ](link/to/AudioFrame/api/doc ).
**Parameters:**
**Parameters:**
*Union[str, towhee.types.Audio]*
*Union[str, towhee.types.Audio (a sub-class of numpy.ndarray ]*
The audio path or link in string.
The audio path or link in string.
Or audio input data in towhee audio frames.
Or audio input data in towhee audio frames.
The input data should represent for an audio longer than 2s.
The input data should represent for an audio longer than 2s.
**Returns**:
**Returns**:
*numpy.ndarray*
*numpy.ndarray*
Audio embeddings in shape (num_clips, 512).
Audio embeddings in shape (num_clips, 512).
Each embedding stands for features of an audio clip with length of 2s.
Each embedding stands for features of an audio clip with length of 2s.