segan_pytorch icon indicating copy to clipboard operation
segan_pytorch copied to clipboard

ValueError: cannot reshape array of size 2 into shape (1,)

Open fycheng-code opened this issue 5 years ago • 3 comments

WechatIMG102 屏幕快照 2019-08-06 下午2 44 33

I was trying to train this model but an error occurred. Is there any way to resolved it?

Thanks for your time!

fycheng-code avatar Aug 06 '19 06:08 fycheng-code

Same issue with me. Trying to clean a .wav file, only about 30 seconds in length. Anyone?

Cleaning 1 wavs clean.py:62: WavFileWarning: Chunk (non-data) not understood, skipping it. rate, wav = wavfile.read(twav) Traceback (most recent call last): File "clean.py", line 110, in main(opts) File "clean.py", line 68, in main wav = pre_emphasize(wav, args.preemph) File "C:\Users...\Desktop\Python_Scripts\Audio\Segan\segan\datasets\se_dataset.py", line 114, in pre_emphasize x0 = np.reshape(x[0], (1,)) File "<array_function internals>", line 6, in reshape File "C:\Users...\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\fromnumeric.py", line 301, in reshape return _wrapfunc(a, 'reshape', newshape, order=order) File "C:\Users...\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\fromnumeric.py", line 61, in _wrapfunc return bound(*args, **kwds) ValueError: cannot reshape array of size 2 into shape (1,)

windowshopr avatar Jul 12 '20 03:07 windowshopr

Figured it out for me. It was due to my .wav file having extra metadata added to it when I exported it from Audacity. I had to clear this metadata by just selecting "Clear" when I go to export my edited .wav file. Audacity likes to add some tag to the file which scipy can't parse when you run this clean.py file. I found the answer on this page:

https://stackoverflow.com/questions/14321627/scipy-io-wavfile-gives-wavfilewarning-chunk-not-understood-error

windowshopr avatar Jul 12 '20 03:07 windowshopr

Face the same issue. I solve it to modify by:

def pre_emphasize(x, coef=0.95):
    if coef <= 0:
        return x
    if len(x.shape)>1:
        x = x[:, 0]
    x0 = np.reshape(x[0], (1,))
    diff = x[1:] - coef * x[:-1]
    concat = np.concatenate((x0, diff), axis=0)
    return concat

Use the codes above to replace: https://github.com/santi-pdp/segan_pytorch/blob/master/segan/datasets/se_dataset.py#L111-L117

============================================ However, it is a issue caused by scipy and your audio file's format do:

print(wav.shape)

at here: https://github.com/santi-pdp/segan_pytorch/blob/master/clean.py#L68 you can got (N, ) if the codes doesn't go wrong, and may got (N, 2) if the codes goes wrong with "wrong" audio file.

unanan avatar Jun 15 '21 09:06 unanan