Skuldur / Classical-Piano-Composer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[predict.py] Impossible to create network

RoiArthurB opened this issue · comments

I'm using Python3 on Windows 10 and after training my network, I try to run predict.py and I have this error message :

Classical-Piano-Composer> python predict.py
Using TensorFlow backend.
Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 1576, in _create_c_op
    c_op = c_api.TF_FinishOperation(op_desc)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Dimension 1 in both shapes must be equal, but are 358 and 359. Shapes are [256,358] and [256,359]. for 'Assign_11' (op: 'Assign') with input shapes: [256,358], [256,359].

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "predict.py", line 134, in <module>
    generate()
  File "predict.py", line 24, in generate
    model = create_network(normalized_input, n_vocab)
  File "predict.py", line 70, in create_network
    model.load_weights('weights.hdf5')
  File "C:\Python36\lib\site-packages\keras\engine\network.py", line 1161, in load_weights
    f, self.layers, reshape=reshape)
  File "C:\Python36\lib\site-packages\keras\engine\saving.py", line 928, in load_weights_from_hdf5_group
    K.batch_set_value(weight_value_tuples)
  File "C:\Python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 2435, in batch_set_value
    assign_op = x.assign(assign_placeholder)
  File "C:\Python36\lib\site-packages\tensorflow\python\ops\variables.py", line 645, in assign
    return state_ops.assign(self._variable, value, use_locking=use_locking)
  File "C:\Python36\lib\site-packages\tensorflow\python\ops\state_ops.py", line 216, in assign
    validate_shape=validate_shape)
  File "C:\Python36\lib\site-packages\tensorflow\python\ops\gen_state_ops.py", line 63, in assign
    use_locking=use_locking, name=name)
  File "C:\Python36\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "C:\Python36\lib\site-packages\tensorflow\python\util\deprecation.py", line 454, in new_func
    return func(*args, **kwargs)
  File "C:\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 3155, in create_op
    op_def=op_def)
  File "C:\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 1731, in __init__
    control_input_ops)
  File "C:\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 1579, in _create_c_op
    raise ValueError(str(e))
ValueError: Dimension 1 in both shapes must be equal, but are 358 and 359. Shapes are [256,358] and [256,359]. for 'Assign_11' (op: 'Assign') with input shapes: [256,358], [256,359].

Did you change the code at all?
If not, maybe updating keras or tensorflow might help:
pip3 install --upgrade keras tensorflow

Exactly same problem here,too.. :(

I might have found a solution.

Whenever your network finishes an epoch, it saves it weights to a new file, called something like 'weights-improvement-11-2.9103-bigger.hdf5'. These weights are what you want to generate a new midi. The file predict.py however, always loads in the same weights: Line 70: model.load_weights('weights.hdf5'). That is why you're getting an error.

You should be able to run the network with any number of nodes, be it 512, 256 or even 2048. You have to load in the correct weights for that, however. What I did as a temporary solution is copy the name of the newly-generated weight file, and paste it into line 70 before generating a new midi. This works, but it isn't exactly elegant. Hopefully there'll be some kind of fix soon.

I had the same problem too and this problem can also be caused because of the difference between the notes that you currently have while making the training and the notes file from Skuldur's repository. In case if you are using the notes file from the repository, try to create your own notes file and see if that works.

So after running lstm.py several weights weights-improvement-...... are outputted in the classical-piano-composer folder. Do you copy the name of the recent weight and replace it here model.load_weights('weights.hdf5') ?