Datadriven-GPVAD icon indicating copy to clipboard operation
Datadriven-GPVAD copied to clipboard

The error about “python3 extract_features.py wavs.txt -o hdf5/balanced.h5”

Open minchaoyue opened this issue 4 years ago • 8 comments

Hi,

I have some issue about extract feature.

1, In the file "configs/example.yaml"

data: data/softlabels/hdf5/balanced.h5 label: data/softlabels/csv/balanced.csv -> csv_labels/balanced.csv

2, when I run "python3 extract_features.py" command, there is an error!

in prepare_labels.py can't find "encoders/balanced.pth". it should be "labelencoders/vad.path" ? but when use models " 'gpvb':" ?

could you give me advice about it ?

MODELS = { 'crnn': { 'model': crnn, 'encoder': torch.load('encoders/balanced.pth'), 'outputdim': 527, }, 'gpvb': { 'model': crnn, 'encoder': torch.load('../labelencoders/vad.pth'), #('encoders/balanced_binary.pth'), 'outputdim': 2, } }

thanks for your response!

minchaoyue avatar May 27 '21 03:05 minchaoyue

Hey there,

  1. I didn't quite get the question here? Its just an example file. If your path of the extracted data differs from mine, just change the path.
  2. Its the same label encoder (0 - Silence, 1- Speech) for all binary vad models i.e., GPVB, VAD-C and so on.

RicherMans avatar May 27 '21 03:05 RicherMans

1, data: data/softlabels/hdf5/balanced.h5 for this set it h5 format or csv ? data: data/csv_labels/balanced.csv could you help me confirm it ? 2, Why we use binary model(eg. labelencoders/vad.path) to label the data for teaching training, since there are 527 classes in the paper? Or which model in the repo is more prefered to label the data from scratch ?

minchaoyue avatar May 27 '21 06:05 minchaoyue

  1. Just as the .yaml says:
data: data/softlabels/hdf5/balanced.h5
label: data/softlabels/csv/balanced.csv

,thus data is the extracted feature hdf5 file and label are the corresponding labels, mapping a filename to a hdf5path and a label.

  1. Well I like to be a bit flexible with my code, since it often happens that my labelset changes during research (i.e., using only 2 labels, using all 527 or using a subset of the 527). Thus I use (and still often do ) a binary "dict" that simply maps label -> number. So to be again specific for the training: The teacher model is trained on 527 label, but only predicts two frame-level labels (Speech, non-Speech) to a student. Thus it is prefferable that you use a 527 label model for any further training.

RicherMans avatar May 27 '21 06:05 RicherMans

Thanks for your patience!!

1, I use the config " data: data/softlabels/hdf5/balanced.h5 label: data/softlabels/csv/balanced.csv " but in the step "python3 run.py train configs/example.yaml", there is an error as below:

_[2021-05-27 15:13:03] threshold: null [2021-05-27 15:13:03] transforms: [2021-05-27 15:13:03] - timemask [2021-05-27 15:13:03] - freqmask [2021-05-27 15:13:03] [2021-05-27 15:13:03] Running on device cpu Traceback (most recent call last): File "run.py", line 637, in fire.Fire(Runner) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/fire/core.py", line 127, in Fire component_trace = _Fire(component, args, context, name) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/fire/core.py", line 366, in _Fire component, remaining_args) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/fire/core.py", line 542, in _CallCallable result = fn(*varargs, **kwargs) File "run.py", line 98, in train data_df = pd.read_csv(config_parameters['data'], sep='\s+') File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/pandas/io/parsers.py", line 702, in parser_f return _read(filepath_or_buffer, kwds) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/pandas/io/parsers.py", line 429, in _read parser = TextFileReader(filepath_or_buffer, **kwds) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/pandas/io/parsers.py", line 895, in init self._make_engine(self.engine) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/pandas/io/parsers.py", line 1122, in _make_engine self._engine = CParserWrapper(self.f, **self.options) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/pandas/io/parsers.py", line 1853, in init self._reader = parsers.TextReader(src, **kwds) File "pandas/_libs/parsers.pyx", line 542, in pandas._libs.parsers.TextReader.cinit File "pandas/_libs/parsers.pyx", line 782, in pandas._libs.parsers.TextReader.get_header UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

please help me confirm!

minchaoyue avatar May 27 '21 07:05 minchaoyue

Hmm seems that I am an idiot and didn't test my code well enough :(((.

Here is how to solve the issue: First check exactly the intro for training from scratch. https://github.com/RicherMans/Datadriven-GPVAD#training-from-scratch

Second, I now also know, the field:

data: csv_labels/balanced.csv
label: softlabels/csv/balanced.csv

Thus, the data file contains:

filename hdf5path
--PJHxphWEs_30.000.wav hdf5/balanced.h5                                                                                          
--ZhevVpy1s_50.000.wav hdf5/balanced.h5                                                                                          
--aE2O5G5WE_0.000.wav hdf5/balanced.h5                                                                                           
--aO5cdqSAg_30.000.wav hdf5/balanced.h5                                                                                          

and the label file is the one generated via prepare_labels.py.

RicherMans avatar May 27 '21 07:05 RicherMans

Hi,

I had a problem after training the first epoch. It looks like the label of cv data are all zero. Is there anything wrong when labeling the data? Or I use the wrong model to label the data ?

Since I didn't find your model in the prepare_labels.py, I changed to the existing one in the repo:

MODELS = { 'crnn': { 'model': crnn, 'encoder': torch.load('../labelencoders/vad.pth'), # torch.load('encoders/balanced.pth'), 'outputdim': 527, }, 'gpvb': { 'model': crnn, 'encoder': torch.load('../labelencoders/vad.pth'), #('encoders/balanced_binary.pth'), 'outputdim': 2, } }

After epoch one, the log is:

Epoch [1/15]: [389/389]

Engine run is terminating due to exception: Precision must have at least one example before it can be computed.
Engine run is terminating due to exception: Precision must have at least one example before it can be computed. Traceback (most recent call last): File "run.py", line 637, in fire.Fire(Runner) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/fire/core.py", line 127, in Fire component_trace = _Fire(component, args, context, name) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/fire/core.py", line 366, in _Fire component, remaining_args) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/fire/core.py", line 542, in _CallCallable result = fn(*varargs, **kwargs) File "run.py", line 241, in train train_engine.run(trainloader, max_epochs=config_parameters['epochs']) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 702, in run return self._internal_run() File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 775, in _internal_run self._handle_exception(e) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 469, in _handle_exception raise e File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 752, in _internal_run self._fire_event(Events.EPOCH_COMPLETED) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 424, in _fire_event func(*first, *(event_args + others), **kwargs) File "run.py", line 212, in compute_metrics inference_engine.run(cvdataloader) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 702, in run return self._internal_run() File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 775, in _internal_run self._handle_exception(e) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 469, in _handle_exception raise e File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 752, in _internal_run self._fire_event(Events.EPOCH_COMPLETED) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 424, in _fire_event func(*first, *(event_args + others), **kwargs) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/metrics/metric.py", line 309, in completed result = self.compute() File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/metrics/precision.py", line 57, in compute f"{self.class.name} must have at least one example before it can be computed." ignite.exceptions.NotComputableError: Precision must have at least one example before it can be computed.

minchaoyue avatar May 28 '21 01:05 minchaoyue

plz try to use encoder': torch.load('../pretrained_models/labelencoders/teacher.pth') instead of using 'encoder': torch.load('../labelencoders/vad.pth')

Actually I am not sure how the label encoder are trained or generated. Could you please simply explain how the label encoder work and generated ? @RicherMans

AjianIronSide avatar May 31 '21 11:05 AjianIronSide

Alright, where exactly in which file is the problem? Just in case, you can also provide me a PR if you'd like.

The encoder is just a MultiLabelBinarizer, found here.

A minimum working example can be just taken from there:

>>> mlb = MultiLabelBinarizer()
>>> mlb.fit([['sci-fi', 'thriller', 'comedy']])
MultiLabelBinarizer()
>>> mlb.classes_
array(['comedy', 'sci-fi', 'thriller'], dtype=object)

In my case just:

labelencoder =  MultiLabelBinarizer()
labelencoder.fit([df['labels'].unique())
labelencoder.transform(['Speech']) # If Speech is in df['labels']

RicherMans avatar May 31 '21 12:05 RicherMans

Hi,

I had a problem after training the first epoch. It looks like the label of cv data are all zero. Is there anything wrong when labeling the data? Or I use the wrong model to label the data ?

Since I didn't find your model in the prepare_labels.py, I changed to the existing one in the repo:

MODELS = { 'crnn': { 'model': crnn, 'encoder': torch.load('../labelencoders/vad.pth'), # torch.load('encoders/balanced.pth'), 'outputdim': 527, }, 'gpvb': { 'model': crnn, 'encoder': torch.load('../labelencoders/vad.pth'), #('encoders/balanced_binary.pth'), 'outputdim': 2, } }

After epoch one, the log is:

Epoch [1/15]: [389/389]

Engine run is terminating due to exception: Precision must have at least one example before it can be computed. Engine run is terminating due to exception: Precision must have at least one example before it can be computed. Traceback (most recent call last): File "run.py", line 637, in fire.Fire(Runner) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/fire/core.py", line 127, in Fire component_trace = _Fire(component, args, context, name) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/fire/core.py", line 366, in _Fire component, remaining_args) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/fire/core.py", line 542, in _CallCallable result = fn(*varargs, **kwargs) File "run.py", line 241, in train train_engine.run(trainloader, max_epochs=config_parameters['epochs']) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 702, in run return self._internal_run() File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 775, in _internal_run self._handle_exception(e) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 469, in _handle_exception raise e File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 752, in _internal_run self._fire_event(Events.EPOCH_COMPLETED) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 424, in _fire_event func(*first, *(event_args + others), **kwargs) File "run.py", line 212, in compute_metrics inference_engine.run(cvdataloader) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 702, in run return self._internal_run() File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 775, in _internal_run self._handle_exception(e) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 469, in _handle_exception raise e File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 752, in _internal_run self._fire_event(Events.EPOCH_COMPLETED) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/engine/engine.py", line 424, in _fire_event func(*first, *(event_args + others), **kwargs) File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/metrics/metric.py", line 309, in completed result = self.compute() File "/data/XXXXXX/anaconda3/envs/gpvad/lib/python3.6/site-packages/ignite/metrics/precision.py", line 57, in compute f"{self.class.name} must have at least one example before it can be computed." ignite.exceptions.NotComputableError: Precision must have at least one example before it can be computed.

Hi, I have a similar problem to this problem, when the code is runing at "inference_engine.run(cvdataloader)" in "run.py", it throws up the following error and then I have checked the val_datasets, there is no problem~ File "run.py", line 249, in train train_engine.run(trainloader, max_epochs=config_parameters['epochs']) File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/engine/engine.py", line 892, in run return self._internal_run() File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/engine/engine.py", line 935, in _internal_run return next(self._internal_run_generator) File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/engine/engine.py", line 993, in _internal_run_as_gen self._handle_exception(e) File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/engine/engine.py", line 638, in _handle_exception raise e File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/engine/engine.py", line 965, in _internal_run_as_gen self._fire_event(Events.EPOCH_COMPLETED) File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/engine/engine.py", line 425, in _fire_event func(*first, *(event_args + others), **kwargs) File "run.py", line 219, in compute_metrics inference_engine.run(cvdataloader) File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/engine/engine.py", line 892, in run return self._internal_run() File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/engine/engine.py", line 935, in _internal_run return next(self._internal_run_generator) File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/engine/engine.py", line 993, in _internal_run_as_gen self._handle_exception(e) File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/engine/engine.py", line 638, in _handle_exception raise e File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/engine/engine.py", line 959, in _internal_run_as_gen epoch_time_taken += yield from self._run_once_on_dataset_as_gen() File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/engine/engine.py", line 1087, in _run_once_on_dataset_as_gen self._handle_exception(e) File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/engine/engine.py", line 638, in _handle_exception raise e File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/engine/engine.py", line 1069, in _run_once_on_dataset_as_gen self._fire_event(Events.ITERATION_COMPLETED) File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/engine/engine.py", line 425, in _fire_event func(*first, *(event_args + others), **kwargs) File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context return func(*args, **kwargs) File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/metrics/metric.py", line 310, in iteration_completed self.update(output) File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/metrics/metric.py", line 607, in wrapper func(self, *args, **kwargs) File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/metrics/precision.py", line 376, in update y_pred, y, correct = self._prepare_output(output) File "/xxx/.pyenv/versions/anaconda3-2020.02/envs/xxx/lib/python3.8/site-packages/ignite/metrics/precision.py", line 71, in _prepare_output y_pred = y_pred.view(-1) RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.

Looking forward to your reply.

TryHard-LL avatar Mar 29 '23 08:03 TryHard-LL

Hey,

I had a problem after training the first epoch. It looks like the label of cv data are all zero. Is there anything wrong when labeling the data? Or I use the wrong model to label the data ?

Yep you used a wrong model actually, but its also wrong on my part I'm sorry for that. So the labelencoders are just dicts that map a label (Speech) to some value i. Thus they are not usable as a model checkpoint.

I wrote in these scripts the wrong paths, sorry, the models you are looking for are in pretrained_models/teacher1/model.pth and pretrained_models/teacher2/model.pth. These correspond to the T1 and T2 from the paper.

You can also check out the other models within forward.py.

Sorry hope that helps!

RicherMans avatar Mar 29 '23 09:03 RicherMans

Hey,

I had a problem after training the first epoch. It looks like the label of cv data are all zero. Is there anything wrong when labeling the data? Or I use the wrong model to label the data ?

Yep you used a wrong model actually, but its also wrong on my part I'm sorry for that. So the labelencoders are just dicts that map a label (Speech) to some value i. Thus they are not usable as a model checkpoint.

I wrote in these scripts the wrong paths, sorry, the models you are looking for are in pretrained_models/teacher1/model.pth and pretrained_models/teacher2/model.pth. These correspond to the T1 and T2 from the paper.

You can also check out the other models within forward.py.

Sorry hope that helps!

Thank you for your patient response

TryHard-LL avatar Mar 29 '23 09:03 TryHard-LL