felixbur / nkululeko

Machine learning speaker characteristics
MIT License
31 stars 5 forks source link

Cannot find audio file if audio_path is given and abolute_path is True #128

Closed bagustris closed 3 months ago

bagustris commented 3 months ago

Currently, for CSV file, Nkululeko search audio files in the following ways:

If audio_path is given and absolute_path is not given (default to True) then file path is root + absolute_path + file:

https://github.com/felixbur/nkululeko/blob/31cba7c39f41159f22899d678fdae6ca4f593bc7/nkululeko/data/dataset_csv.py#L44-L61

It should be audio_path + x without adding the root (location of parent_dir or csv).

For example,
In INI file

DATA]
databases = ['train', 'dev']
train = ./data/odyssey-cat-2024/odyssey_train.csv
train.type = csv
train.split_strategy = train
train.audio_path = /data/Odyssey_SER_Challenge/Audios
dev = ./data/odyssey-cat-2024/odyssey_dev.csv
dev.type = csv
dev.split_strategy = test
dev.audio_path = /data/Odyssey_SER_Challenge/Audios

expected: /data/Odyssey-SER-Challenge/Audios/MSP-PODCAST_0003_0052.wav searched by Nkululeko: ./data/odyssey-cat-2024//data/Odyssey_SER_Challenge/Audios/MSP-PODCAST_0003_0052.wav (which leads to error file not found)

if absolute_path is set to False (interpreted as relative path) but the audio_path is given, the behavior is as expected (file path ./data/odyssey-cat-2024//data/Odyssey-SER-Challenge/Audios/MSP-PODCAST_0003_0052.wav)

I'll submit the following addition to make it work as above in dataset_csv after line 61:

        else: # absolute path is True
            if audformat.index_type(df.index) == "segmented":
                file_index = (
                    df.index.levels[0]
                    .map(lambda x: audio_path + "/" + x)
                    .values
                )
                df = df.set_index(df.index.set_levels(
                    file_index, level="file"))
            else:
                if not isinstance(df, pd.DataFrame):
                    df = pd.DataFrame(df)
                df = df.set_index(df.index.to_series().apply(
                    lambda x: audio_path + "/" + x ))