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

TypeError: 'float' object cannot be interpreted as an integer #106

Closed
jzq2000 opened this issue Nov 10, 2020 · 3 comments
Closed

TypeError: 'float' object cannot be interpreted as an integer #106

jzq2000 opened this issue Nov 10, 2020 · 3 comments
Labels

Comments

@jzq2000
Copy link
Contributor

jzq2000 commented Nov 10, 2020

HI, I found this code in msaf/msaf/algorithms/sf/segmenter.py
may cause bug because

  1. F.shape[0]* red may be float
  2. np.linspace(0, F.shape[0], num=F.shape[0] * red) may have some float elements.
            if self.framesync:
                red = 0.1
                F_copy = np.copy(F)
                F = librosa.util.utils.sync(
                    F.T, np.linspace(0, F.shape[0], num=F.shape[0] * red),
                    pad=False).T

I test on librosa=0.8.0 and numpy=1.19.3 and will get this error:

Traceback (most recent call last):
  File "D:/music/tools/msaf/test_msaf.py", line 14, in <module>
    boundaries, labels = msaf.process(audio_file, feature=feature, boundaries_id=bid, framesync=True, labels_id=lid, config=config)
  File "C:\Users\v-zeju\src\lib\site-packages\msaf\run.py", line 342, in process
    est_times, est_labels = run_algorithms(file_struct, boundaries_id,
  File "C:\Users\v-zeju\src\lib\site-packages\msaf\run.py", line 214, in run_algorithms
    est_times, est_labels = run_fun(file_struct, bounds_module, labels_module,
  File "C:\Users\v-zeju\src\lib\site-packages\msaf\run.py", line 138, in run_flat
    est_idxs, est_labels = S.processFlat()
  File "C:\Users\v-zeju\src\lib\site-packages\msaf\algorithms\sf\segmenter.py", line 149, in processFlat
    F.T, np.linspace(0, F.shape[0], num=F.shape[0] * red),
  File "<__array_function__ internals>", line 5, in linspace
  File "C:\Users\v-zeju\src\lib\site-packages\numpy\core\function_base.py", line 113, in linspace
    num = operator.index(num)
TypeError: 'float' object cannot be interpreted as an integer
@jzq2000
Copy link
Contributor Author

jzq2000 commented Nov 10, 2020

Besides, after I change the code to

 librosa.util.utils.sync(
                         F.T, np.linspace(0, F.shape[0], num=int(F.shape[0] * red), dtype= np.int32),
                         pad=False).T

It will also get an error like this:

traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2020.2.1\plugins\python-ce\helpers\pydev\pydevd.py", line 1448, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2020.2.1\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/music/tools/msaf/test_msaf.py", line 14, in <module>
    boundaries, labels = msaf.process(audio_file, feature=feature, boundaries_id=bid, framesync=True, labels_id=lid, config=config)
  File "C:\Users\v-zeju\src\lib\site-packages\msaf\run.py", line 342, in process
    est_times, est_labels = run_algorithms(file_struct, boundaries_id,
  File "C:\Users\v-zeju\src\lib\site-packages\msaf\run.py", line 214, in run_algorithms
    est_times, est_labels = run_fun(file_struct, bounds_module, labels_module,
  File "C:\Users\v-zeju\src\lib\site-packages\msaf\run.py", line 138, in run_flat
    est_idxs, est_labels = S.processFlat()
  File "C:\Users\v-zeju\src\lib\site-packages\msaf\algorithms\sf\segmenter.py", line 188, in processFlat
    est_bounds /= red
TypeError: ufunc 'true_divide' output (typecode 'd') could not be coerced to provided output parameter (typecode 'l') according to the casting rule ''same_kind''

Due to the code:

            if self.framesync:
                est_bounds /= red
                F = F_copy

@urinieto
Copy link
Owner

urinieto commented Nov 11, 2020

Oh, thanks for reporting! I believe this should fix it:

    if self.framesync:
        est_bounds = np.asarray(est_bounds // red, dtype=np.int)
        F = F_copy

If this works, would you mind creating a PR with these changes?

Thanks!

@urinieto urinieto added the bug label Nov 11, 2020
@urinieto
Copy link
Owner

This was fixed here: #107
Thanks for the PR!

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

No branches or pull requests

2 participants