Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fycheng-code opened this issue Aug 6, 2019 · 3 comments
Open

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

fycheng-code opened this issue Aug 6, 2019 · 3 comments

Comments

@fycheng-code
Copy link

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!

@windowshopr
Copy link

windowshopr commented Jul 12, 2020

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
Copy link

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

@unanan
Copy link

unanan commented Jun 15, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants