I want to extract features from the signal using DWT and then feed the results into CNN, after calling the 'dwt' library function I got a runtime error.

This is the code:
   elif FEATURE == 'wavelet':
           approx, detail = pywt.dwt(y, 'db8')
           approx = approx[:128]
           detail = detail[:128]
           feature = np.hstack([approx, detail])
           return normalize(feature).astype(np.float32)

And this is the error:

RuntimeError: Given groups=1, weight of size [32, 1, 5, 5], expected input[1, 400, 1, 256] to have 1 channels, but got 400 channels instead

I guess that 400 is a too high number for channels (correct me if I'm wrong), so I'd like to reduce that number, how can I do this?

  • $\begingroup$ What is y specifically and where does the function normalize come from as this isn't a standard python function? Have you single stepped through each line to isolate the error and if so what line causes this? $\endgroup$ Commented Apr 16, 2022 at 13:19
  • $\begingroup$ y represents the signal, its type is 'ndarray', normalize function used to lower the values of the signal (it's not Python function), but the reason for the error is that the convolutional network was built for different num of channels (one). Can I reduce the number of output channels from dwt function? Should I use another wavelet function instead? (like cwt) $\endgroup$
    – yba
    Commented Apr 16, 2022 at 13:54
  • $\begingroup$ So does normalize give you the error or something you run after that? $\endgroup$ Commented Apr 16, 2022 at 13:59
  • $\begingroup$ The error comes from the last line of conv2D function which belongs to pytorch: (torch\nn\modules\conv.py) "return F.conv2d(input, weight, bias, self.stride, self.padding, self.dilation, self.groups))". $\endgroup$
    – yba
    Commented Apr 16, 2022 at 14:26


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.