GuitarML / GuitarLSTM

Deep learning models for guitar amp/pedal emulation using LSTM with Keras.
https://guitarml.com/
GNU General Public License v3.0
367 stars 49 forks source link

Investigate using error to signal with pre-emphasis filter and custom dataloader #11

Open GuitarML opened 3 years ago

GuitarML commented 3 years ago

A new method of loading the data by batch was developed and applied to the Colab notebook. This method caused the original error to signal loss calculation to blow up, so the loss function was changed to MSE. This fixed the out of memory issues by loading the data by batch_size, instead of all at once or in large chunks. However, the original error to signal loss produces more accurate models, especially on highly distorted/complex guitar signals.

Investigate using the original error to signal loss function with the custom Sequence dataloader class from the Colab notebook.

Update: It looks like the pre-emphasis filter is calculated incorrectly, as noted here: https://github.com/GuitarML/PedalNetRT/issues/16#issuecomment-772766160 Apply the fix of using [t-1] and see if this fixed the instability issues.

jmiller656 commented 3 years ago

@GuitarML I had a look at the paper you sent me and realized that there might be a problem with the way the error_to_signal loss was being used. It looks like in the paper they formulate the problem such that the input is a window of size n over the original signal, and the output is a window of size n over the distorted signal (at the same point in time).

The way the model is trained in this repo, it looks like we're taking a window of size n for input, but providing an output for timestep n+1. I think if we switch to that formulation (I'll start trying tonight and let you know how it goes), then we should hopefully see some better results.

jmiller656 commented 3 years ago

Still working on this! Found a pretty big contributor to the problem. As was mentioned in the issue you linked to, there is a problem with how the pre-emphasis filter is being calculated.

Right now, you are concatenating the vector and the coefficient * the filter. Ex:

coeff = 0.95
original = [1 ,1, 1]
output = [1, 1, 1, 0.95, 0.95, 0.95]

What we really want to do is subtract the coefficient * the previous value from the array. For example:

coeff =0.95
original = [1, 2, 3]
output = [1, 2-(1*0.95), 3-(2*0.95)] -> [1, 1.05, 1.1]

Practically, here's how we'd implement this in tensorflow:

def pre_emphasis_filter(x, coeff=0.95):
    return tf.concat([x[:, 0:1, :], x[:, 1:, :] - coeff*x[:, :-1, :]], axis=1)

I'm just starting to test this out, and it's looking good so far! Trying to listen better for audio quality now. I'm going to try and have a PR open for this either tonight or tomorrow. Happy Valentine's day!

GuitarML commented 3 years ago

Cant wait to try it out, good work!