Fix opus_demo lossgen when using weights file
When trying to test opus_demo with both USE_WEIGHTS_FILE and ENABLE_LOSSGEN, it does not work. The "loss generator" data is invalid and therefore does not apply the loss.
This PR adds the lossgen data to the lpcnet weights file and loads it when running the opus_demo, when needed.
Actually, on this one I think the best fix may be to always include the lossgen weights in the build rather than the blob. After all, the weights aren't in libopus and opus_demo isn't meant to be shipped anyway. Makes sense?
Yes, I agree. I had tried that before but it wasn't working. However, I find that if I add
#undef USE_WEIGHTS_FILE
to the lossgen_data.h, that works. The lossgen_init() function in lossgen.c also needs the USE_WEIGHTS_FILE block adjusted.
I am not sure where lossgen_data.* is generated to adjust that or if you'd prefer to also remove all references to USE_WEIGHTS_FILE in lossgen_data.c.
@janpbuethe Any idea if there's an easy way to not have the #ifdef USE_WEIGHTS_FILE when dumping the weights? The alternative would be to have lossgen.c #include "lossgen_data.c" after an #undef USE_WEIGHTS_FILE
CWriter in the weight-exchange library has an argument enable_binary_blob which defaults to True. Setting it to False should (in theory) solve the problem.
@jim-signal can you give the exp_lossgen_fix1 branch a try and see if it fixes the problem?
Yes, that works. If I turn on USE_WEIGHTS_FILE:
-
opus_demois about 670KB and properly does not include the weight data -
./dump_weights_blobyields a ~3.3MB weights_blob.bin - Running
opus_demowithsim_lossand with/without DRED results in expected results
Thanks! Feel free to close this and merge your own patch.
@jim-signal So I merged a more complete patch to main. Let me know if there's any issue with it.