flashlight / wav2letter

Facebook AI Research's Automatic Speech Recognition Toolkit
https://github.com/facebookresearch/wav2letter/wiki
Other
6.37k stars 1.01k forks source link

Export the weights of trained model #628

Closed HunterHantao closed 4 years ago

HunterHantao commented 4 years ago

Is there a way that we can export the trained model weights? For example, export the weights to numpy /pytorch dictionary format.

tlikhomanenko commented 4 years ago

@HunterHantao,

We don't support general converter.

However, for your specific model solution is not complicated for converting the weights from C++ to Python: read model in C++, take all underlying parameters arrayfire arrays, save them using http://arrayfire.org/docs/group__stream__func__save.htm and then use python ArrayFire to read into numpy with http://arrayfire.org/arrayfire-python/arrayfire.array.html?highlight=to_ndarray#arrayfire.array.Array.to_ndarray.

Hope this is answering your question and needs.

HunterHantao commented 4 years ago

Thank you very much. We will try to use it this way.

rajeevbaalwan commented 4 years ago

@HunterHantao were you able to export weigths of trained model ?

HunterHantao commented 4 years ago

I do not have a very nice way to do it. Instead, I just print out the weight and save them in txt. Later, I use python parse it.

https://github.com/facebookresearch/wav2letter/blob/master/src/common/FlashlightUtils.cpp#L16 Add this after Line 16 af::print("Weights", p.array());

rajeevbaalwan commented 4 years ago

That's a nice hack. So finally were you able to recreate the ASR architecture in pytorch and run that successfully ?

HunterHantao commented 4 years ago

I am using Tensorflow, and yes. Finally, it work well there. I am able to load the weights to tensorflow.