Vak prep issue with "simple-seq" annotation format and wave files

Hi,
Vak prep ran smoothly with the tutorial using cbin and notmat files; however, I encountered an issue using “vak prep” on my own dataset where it does not appear to identify the annotation files associated with the audio files. I have attached the relevant “.toml” file and a log file of the command. The only three major differences between the tutorial’s “.toml” file and my test file were the following:
audio_format, annot_format, and labelset under the [prep] section. The files carries an additional “.txt” extension to the file names for uploading.

I have checked to make sure that the “simple-seq” annotation file (.csv) as well as the wave file are in the same directory; however, it does not seem to recognize either the “.wav” extension or the “simple-seq” annotation format.

VAK_train.toml.txt (530 Bytes)
VAK_prep_train.log.txt (2.1 KB)

Thanks again for all your help!

Hi, @YMK123 . I’m @mizuki, just a tweetynet user.
I thought adding spect_format in the [PREP] section might solve your problem,though I don’t know why it worked in tutorial without it and it is one of things I want to know.

Sorry if this is besides the point.

1 Like

Hi @mizuki, thanks so much for your input! :slight_smile: It was definitely helpful to know that adding spect_format in the [PREP] section worked.

I think I may have found the issue, which may be due to using the “simple-seq” format in crowsetta. When I traced the error from vak, it started at the annotation.py script, specifically from the recursive_stem function at line 174. The audio_path fed to the function did not carry any extension.
It seems to be stemming from line 97 from the simple.py script in crowsetta where the extension is removed when creating the audio_path object in the first place:
audio_pathname = a_csv.replace('.csv', '')

As a quick fix, I revised the line 97 of the simple.py script to:
audio_pathname = a_csv.replace('.csv', '.wav')

On a cursory level, it seems like the outputs were properly generated for vak prep with this fix.

1 Like

Hi @YMK123 sorry that vak is not giving you clear enough feedback here.

I’m posting the full text of the error you got for context:

determined that purpose of config file is: train
will add 'csv_path' option to 'TRAIN' section
purpose for dataset: train
will split dataset
making array files containing spectrograms from audio files in: /Users/Lab/VAK_test/test
/Users/Lab/VAK_test/test/01-F81AD-191209_1807_halfhr1_callsegs_st_53989425-54099675
01-F81AD-191209_1807_halfhr1_callsegs_st_53989425-54099675

Traceback (most recent call last):
  File "/Users/Lab/anaconda3/envs/vak-env/bin/vak", line 10, in <module>
    sys.exit(main())
  File "/Users/Lab/anaconda3/envs/vak-env/lib/python3.9/site-packages/vak/__main__.py", line 45, in main
    cli.cli(command=args.command, config_file=args.configfile)
  File "/Users/Lab/anaconda3/envs/vak-env/lib/python3.9/site-packages/vak/cli/cli.py", line 30, in cli
    COMMAND_FUNCTION_MAP[command](toml_path=config_file)
  File "/Users/Lab/anaconda3/envs/vak-env/lib/python3.9/site-packages/vak/cli/prep.py", line 132, in prep
    vak_df, csv_path = core.prep(
  File "/Users/Lab/anaconda3/envs/vak-env/lib/python3.9/site-packages/vak/core/prep.py", line 205, in prep
    vak_df = dataframe.from_files(
  File "/Users/Lab/anaconda3/envs/vak-env/lib/python3.9/site-packages/vak/io/dataframe.py", line 137, in from_files
    spect_files = audio.to_spect(
  File "/Users/Lab/anaconda3/envs/vak-env/lib/python3.9/site-packages/vak/io/audio.py", line 174, in to_spect
    audio_annot_map = source_annot_map(audio_files, annot_list)
  File "/Users/Lab/anaconda3/envs/vak-env/lib/python3.9/site-packages/vak/annotation.py", line 210, in source_annot_map
    keys = [recursive_stem(annot.audio_path) for annot in annot_list]
  File "/Users/Lab/anaconda3/envs/vak-env/lib/python3.9/site-packages/vak/annotation.py", line 210, in <listcomp>
    keys = [recursive_stem(annot.audio_path) for annot in annot_list]
  File "/Users/Lab/anaconda3/envs/vak-env/lib/python3.9/site-packages/vak/annotation.py", line 175, in recursive_stem
    raise ValueError(f"unable to compute stem of {path}")
ValueError: unable to compute stem of /Users/Lab/VAK_test/test/01-F81AD-191209_1807_halfhr1_callsegs_st_53989425-54099675

My guess is that what’s going on here is vak expects there to be a 1:1 match for each audio and annotation file, where the name of the annotation file is ${audio-file-name.ext}.txt.

So you want to have something like:

01-F81AD-191209_1807_halfhr1_callsegs_st_53989425-54099675/
  001.wav
  001.wav.csv
  002.wav
  002.wav.csv
  003.wav
  003.wav.csv

Is that true in your case?
Can you list the names of some of your audio and annotation files here?

It just dawned on me that the examples in the “how to” here actually do not show the files this way:

We show this instead. All those .csv files should actually be named .wav.csv

BB_SGP16-1___20160521_214723.csv
BB_SGP16-1___20160521_214723.txt
BB_SGP16-1___20160521_214723.wav
BBY15-4___20150907_211645.csv
BBY15-4___20150907_211645.txt
BBY15-4___20150907_211645.wav
... # more files here
DB_1-WWS16-2___20160822_203501.csv
DB_1-WWS16-2___20160822_203501.txt
DB_1-WWS16-2___20160822_203501.wav

Could you please raise an issue on the vak repo pointing out we need to fix that in the docs?
I’m sorry that how-to isn’t clearer. I’ll be sure to credit you for bringing it to our attention.

The data in the “autoannotate” tutorial does follow this naming convention though.
You have bird1-timestamp.cbin as an audio file and bird1-timestamp.cbin.not.mat as an annotation file. The recursive_stem format that gives you the cryptic error basically removes extensions until it finds a valid audio file format (currently wav or cbin)

Note that this convention does not have to apply if you’re using some annotation format where there’s only a single annotation file but multiple audio files – in that case vak (using crowsetta) just gets the source “annotated” files (audio in this case) out of the single annotation file.

I think your fix might be working because it creates the correct situation, but a better way to fix is to use the naming convention that vak expects as above, so that you don’t have to modify the internals of crowsetta which might come back to haunt you later if you forget you did it

Thanks so much @mizuki for chiming in to help!

I know spect_format is not super clear and we probably need to document it better.

This option is for the case when you’re training on spectrograms that you have generated on your own, instead of asking vak to do it for you.

Since labs often are very particular about how they compute spectrograms, we wanted to give people the option to just use their own as long as they can put them in files in a format that vak can understand.

There is a “how to” page here with more info, would love to know if it is or isn’t clear to you: How do I use my own spectrograms? - vak documentation

Sure, of course :slight_smile:. The wave files were of the format ‘{filename}.csv’ rather than ‘{filename}.wav.csv’. I renamed the files accordingly and didn’t encounter the same error with the command. Thanks for your help!

1 Like

:tada: yay! glad to hear it. thank you for raising the issue so we can fix that

1 Like

I see.
I was missunderstanding the usage.
I had been thinking that spect_format was neccesary and that we had to give tweetynet spectrograms not raw sound files, as I prpbably got some errors with only sound files and they were solved with spectrograms, but the cause might have been in other places, though I don’t remember details.
Good to know, thank you, @YMK123 and @nicholdav !

2 Likes