593b94c120
pytest / Unit Tests (push) Has been cancelled
pytest / Integration (integration_tests_a) (push) Has been cancelled
pytest / Integration (integration_tests_b) (push) Has been cancelled
pytest / Integration (integration_tests_c) (push) Has been cancelled
pytest / Integration (integration_tests_d) (push) Has been cancelled
pytest / Integration (integration_tests_e) (push) Has been cancelled
pytest / Integration (integration_tests_f) (push) Has been cancelled
pytest / Integration (integration_tests_g) (push) Has been cancelled
pytest / Integration (integration_tests_h) (push) Has been cancelled
pytest / Integration (integration_tests_i) (push) Has been cancelled
pytest / Integration (integration_tests_j) (push) Has been cancelled
pytest / Distributed (distributed_a) (push) Has been cancelled
pytest / Distributed (distributed_b) (push) Has been cancelled
pytest / Distributed (distributed_c) (push) Has been cancelled
pytest / Distributed (distributed_d) (push) Has been cancelled
pytest / Distributed (distributed_e) (push) Has been cancelled
pytest / Distributed (distributed_f) (push) Has been cancelled
pytest / Minimal Install (push) Has been cancelled
pytest / Event File (push) Has been cancelled
pytest (slow) / py-slow (push) Has been cancelled
Publish JSON Schema / publish-schema (push) Has been cancelled
41 lines
1.6 KiB
Python
41 lines
1.6 KiB
Python
import pytest
|
|
import torch
|
|
|
|
from ludwig.constants import ENCODER_OUTPUT
|
|
from ludwig.features.audio_feature import AudioInputFeature
|
|
from ludwig.schema.features.audio_feature import AudioInputFeatureConfig
|
|
from ludwig.schema.utils import load_config_with_kwargs
|
|
from tests.integration_tests.utils import audio_feature
|
|
|
|
BATCH_SIZE = 2
|
|
SEQ_SIZE = 20
|
|
AUDIO_W_SIZE = 16
|
|
DEFAULT_OUTPUT_SIZE = 256
|
|
|
|
|
|
@pytest.mark.parametrize("enc_encoder", ["stacked_cnn", "rnn"])
|
|
def test_audio_feature(enc_encoder):
|
|
# synthetic audio tensor
|
|
audio_tensor = torch.randn([BATCH_SIZE, SEQ_SIZE, AUDIO_W_SIZE], dtype=torch.float32)
|
|
|
|
# generate audio feature config
|
|
audio_feature_config = audio_feature(
|
|
folder=".", encoder={"type": enc_encoder, "max_sequence_length": SEQ_SIZE, "embedding_size": AUDIO_W_SIZE}
|
|
)
|
|
|
|
# instantiate audio input feature object
|
|
audio_feature_config, _ = load_config_with_kwargs(AudioInputFeatureConfig, audio_feature_config)
|
|
audio_input_feature = AudioInputFeature(audio_feature_config)
|
|
|
|
# pass synthetic audio tensor through the audio input feature
|
|
encoder_output = audio_input_feature(audio_tensor)
|
|
|
|
# confirm correctness of the the audio encoder output
|
|
assert isinstance(encoder_output, dict)
|
|
assert ENCODER_OUTPUT in encoder_output
|
|
assert isinstance(encoder_output[ENCODER_OUTPUT], torch.Tensor)
|
|
if enc_encoder == "passthrough":
|
|
assert encoder_output[ENCODER_OUTPUT].shape == (BATCH_SIZE, SEQ_SIZE, AUDIO_W_SIZE)
|
|
else:
|
|
assert encoder_output[ENCODER_OUTPUT].shape == (BATCH_SIZE, DEFAULT_OUTPUT_SIZE)
|