magenta / magenta-demos

Demonstrations of Magenta Models
Apache License 2.0
1.32k stars 419 forks source link

Nsynth generate.py "TypeError: 'float' object cannot be interpreted as an integer" with numpy 1.18.4 #88

Closed jeffkile closed 4 years ago

jeffkile commented 4 years ago

Hi when using numpy 1.18.4 I'm getting the following error when trying to run the generate.py script for Nsynth

Interpolating embeddings between instruments at each pitch...
Traceback (most recent call last):
  File "~/Coding/nsynth/VIRTUAL/lib/python3.7/site-packages/numpy/core/function_base.py", line 117, in linspace
    num = operator.index(num)
TypeError: 'float' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "generate.py", line 279, in <module>
    interpolate_embeddings()
  File "generate.py", line 80, in interpolate_embeddings
    x, y = np.meshgrid(np.linspace(0, grid_size, res+1), np.linspace(0, grid_size, res+1))
  File "<__array_function__ internals>", line 6, in linspace
  File "~/Coding/nsynth/VIRTUAL/lib/python3.7/site-packages/numpy/core/function_base.py", line 121, in linspace
    .format(type(num)))
TypeError: object of type <class 'float'> cannot be safely interpreted as an integer.

This is my settings.json

{
        "instruments": [
                ["harp","guitar"],
                ["flute", "trumpet"]
        ],
        "checkpoint_dir":"~/Downloads/wavenet-ckpt",
        "pitches":      [24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68],
        "resolution":              9,
        "final_length":            64000,
        "gpus":                    1,
        "batch_size_embeddings":   32,
        "batch_size_generate":     256,
        "name":         "test_1"
}

I'm using: python 3.7.6 numpy 1.18.4 tensorflow 1.15.3 magenta 1.3.1

adarob commented 4 years ago

@JCBrouwer PTAL

JCBrouwer commented 4 years ago

Hey @jeffkile, you're running into the same issue as #86. This error message is related to numpy deprecating the use of floats as steps in linspace in 1.18. Also, most likely you'll run into the same issues with nsynth_generate never ending as well.

I've pushed a version of generate.py I was using to test here: https://github.com/JCBrouwer/magenta-demos/blob/master/nsynth/generate.py

It casts the float argument that numpy is complaining about to an int. Plus, instead of running nsynth_generate automatically for you, it prints out the command for you to run in another terminal. For some reason nsynth_generate isn't stopping once it's generated sample_length samples, so you'll need to just kill the process once you see it has generated enough samples. Then you can go back to the original terminal and continue the pipeline.

I haven't had the time to figure out what exactly is going wrong yet because I'm in the middle of writing my bachelor's thesis at the moment. Hopefully this version of generate.py can hold you over til I can track down the bug.

Regarding your other issue, #87, can you check that all your files are exactly the same length (e.g. with soxi file.wav)?

adarob commented 4 years ago

@JCBrouwer would you mind making a PR with the float fix?