question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can we get features from wav2vec 2.0

See original GitHub issue

❓ Questions and Help

Before asking:

  1. search the issues.
  2. search the docs.

What is your question?

Hi, for wav2vec 2.0, how can I get pre-trained features like wav2vec? https://github.com/pytorch/fairseq/tree/master/examples/wav2vec#pre-trained-models-1

My error ⬇️ /content/fairseq/fairseq/models/wav2vec/wav2vec2.py in init(self, cfg) 244 self.mask_prob = cfg.mask_prob 245 self.mask_selection = cfg.mask_selection –> 246 self.mask_other = cfg.mask_other 247 self.mask_length = cfg.mask_length 248 self.no_mask_overlap = cfg.no_mask_overlap

AttributeError: ‘Namespace’ object has no attribute ‘mask_other’

Code

import torch
from fairseq.models.wav2vec import Wav2Vec2Model

cp = torch.load('/content/pretrain_model/wav2vec_vox_new.pt')
model = Wav2Vec2Model.build_model(cp['args'], task=None)
model.load_state_dict(cp['model'])
model.eval()

wav_input_16khz = torch.randn(1,10000)
z = model.feature_extractor(wav_input_16khz)
c = model.feature_aggregator(z)

What’s your environment?

  • fairseq Version (e.g., 1.0 or master):
  • PyTorch Version (e.g., 1.0) 1.7.0
  • OS (e.g., Linux):
  • How you installed fairseq (pip, source): cd fairseq pip install --editable ./
  • Build command you used (if compiling from source):
  • Python version: 3.7
  • CUDA/cuDNN version: 10.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
alexeibcommented, Dec 1, 2020

can you load it like this instead:

import fairseq

cp = '/content/pretrain_model/wav2vec_vox_new.pt'
model, cfg, task = fairseq.checkpoint_utils.load_model_ensemble_and_task([cp])
model = model[0]

after that you can extract features from feature encoder in the way you tried it, or from the transformer by just doing a model forward (with mask=False and features_only=True). you may also want to try features from different layers of the model, but you need to make some changes to return results from each layer, here: https://github.com/pytorch/fairseq/blob/master/fairseq/models/wav2vec/wav2vec2.py#L764 and then also in the model forward()

1reaction
stonelazycommented, Feb 24, 2021

Have been facing a same problem. Faced many compatibility issues. Turns out the reason was that pip source was not updated. I tried to install and develop locally. Then XLS43, wav2vec_large,wav2vec_small everything was working properly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can we get features from wav2vec 2.0 #2967 - GitHub
To extract features you can use method suggested above: via model forward (with mask=False and features_only=True).
Read more >
Wav2Vec2 - Hugging Face
Overview. The Wav2Vec2 model was proposed in wav2vec 2.0: A Framework for Self-Supervised Learning of Speech Representations by Alexei Baevski, Henry Zhou, ...
Read more >
An Illustrated Tour of Wav2vec 2.0 | Jonathan Bgn
Feature encoder. The feature encoder's job is to reduce the dimensionality of the audio data, converting the raw waveform into a sequence of ......
Read more >
Audio Features from the Wav2Vec 2.0 Embeddings for the ...
For this purpose, we have investigated the Wav2Vec 2.0 deep neural network to extract audio features from Transformer embeddings.
Read more >
Wav2Vec 2.0: Self-Supervised Learning for ASR
Wav2Vec 2.0 : state-of-the-art model for Automatic Speech Recognition. It takes advantage from a self-supervised training and contrastive learning.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found