markovmodel / deeptime

Deep learning meets molecular dynamics.
GNU Lesser General Public License v3.0
173 stars 39 forks source link

TypeError: 'numpy.float64' object cannot be interpreted as an integer #28

Closed deo999 closed 5 years ago

deo999 commented 5 years ago

i m try to run this code from this jupyter https://github.com/markovmodel/deeptime/blob/master/vampnet/examples/Alanine_dipeptide_multiple_files.ipynb

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: part of the code at which i getting error :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: max_vm = 0 attempts_number = 10

Pretraining with VAMP with 'symmetrized' matrices yields a bad approximation of the

eigenvectors per se, but improves the 'readability' of the states identified by VAMP-2

which would otherwise be difficult to interprete.

IMPORTANT: the function vamp.loss_VAMP2_autograd can only be used with tensorflow 1.6 or more recent.

For older versions of TF, use the function vamp.loss_VAMP2

losses = [ vamp.loss_VAMP2_autograd, vamp._loss_VAMP_sym, vamp.loss_VAMP2_autograd, ]

for attempt in range(attempts_number):

# Clear the previous tensorflow session to prevent memory leaks
clear_session()

# Build the model

nodes = [layer_width]*network_depth

Data_X = Input(shape = (input_size,))
Data_Y = Input(shape = (input_size,))

# A batch normalization layer improves convergence speed
bn_layer = BatchNormalization()

# Instance layers and assign them to the two lobes of the network
dense_layers = [Dense(node, activation = 'relu',)
                for node in nodes]

lx_branch = bn_layer(Data_X)
rx_branch = bn_layer(Data_Y)

for i, layer in enumerate(dense_layers):

    lx_branch = dense_layers[i](lx_branch)
    rx_branch = dense_layers[i](rx_branch)

# Add a softmax output layer.
# Should be replaced with a linear activation layer if
# the outputs of the network cannot be interpreted as states
softmax = Dense(output_size, activation='softmax')

lx_branch = softmax(lx_branch)
rx_branch = softmax(rx_branch)

# Merge both networks to train both at the same time
merged = concatenate([lx_branch, rx_branch])

# Initialize the model and the optimizer, and compile it with
# the loss and metric functions from the VAMPnets package
model = Model(inputs = [Data_X, Data_Y], outputs = merged)
adam = Adam(lr = learning_rate)

vm1 = np.zeros((len(losses), nb_epoch))
tm1 = np.zeros_like(vm1)
vm2 = np.zeros_like(vm1)
tm2 = np.zeros_like(vm1)

for l_index, loss_function in enumerate(losses):

    model.compile(optimizer = adam,
                  loss = loss_function,
                  metrics = [
                      vamp.metric_VAMP,
                      vamp.metric_VAMP2,
                             ])

    # Train the model

    steps_per_train_epoch = np.sum(np.ceil((train_data_source.trajectory_lengths()-tau)/batch_size))
    steps_per_valid_epoch = np.sum(np.ceil((valid_data_source.trajectory_lengths()-tau)/batch_size))

    hist = model.fit_generator(generator = vamp_data_loader.build_generator_on_source(train_data_source,
                                                          batch_size,
                                                          tau,
                                                          output_size),
                               steps_per_epoch = steps_per_train_epoch,
                               epochs = nb_epoch,
                               verbose = 0,
                               validation_data = vamp_data_loader.build_generator_on_source(valid_data_source,
                                                                batch_size,
                                                                tau,
                                                                output_size),
                               validation_steps = steps_per_valid_epoch,
                               shuffle = True
                              )

    vm1[l_index] = np.array(hist.history['val_metric_VAMP'])
    tm1[l_index] = np.array(hist.history['metric_VAMP'])

    vm2[l_index] = np.array(hist.history['val_metric_VAMP2'])
    tm2[l_index] = np.array(hist.history['metric_VAMP2'])

vm1 = np.reshape(vm1, (-1))
tm1 = np.reshape(tm1, (-1))
vm2 = np.reshape(vm2, (-1))
tm2 = np.reshape(tm2, (-1))

# Average the score obtained in the last part of the training process
# in order to estabilish which model is better and thus worth saving

score = vm1[-5:].mean()
t_score = tm1[-5:].mean()
extra_msg = ''
if score > max_vm:
    extra_msg = ' - Highest'
    best_weights = model.get_weights()
    max_vm = score
    vm1_max = vm1
    tm1_max = tm1
    vm2_max = vm2
    tm2_max = tm2

print('Attempt {0}, training score: {1:.2f}, validation score: {2:.2f}'.format(attempt+1, t_score, score) + extra_msg)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::: error that i m getting ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

WARNING:tensorflow:From /opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version. Instructions for updating: Colocations handled automatically by placer.

WARNING:tensorflow:From /opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version. Instructions for updating: Colocations handled automatically by placer.

WARNING:tensorflow:From /opt/conda/lib/python3.7/site-packages/vampnet-0.1.4.dev13+g7b9cbd9-py3.7.egg/vampnet/vampnet.py:660: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.cast instead.

WARNING:tensorflow:From /opt/conda/lib/python3.7/site-packages/vampnet-0.1.4.dev13+g7b9cbd9-py3.7.egg/vampnet/vampnet.py:660: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.cast instead.

WARNING:tensorflow:From /opt/conda/lib/python3.7/site-packages/vampnet-0.1.4.dev13+g7b9cbd9-py3.7.egg/vampnet/vampnet.py:612: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.cast instead.

WARNING:tensorflow:From /opt/conda/lib/python3.7/site-packages/vampnet-0.1.4.dev13+g7b9cbd9-py3.7.egg/vampnet/vampnet.py:612: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.cast instead.


TypeError Traceback (most recent call last)

in 96 output_size), 97 validation_steps = steps_per_valid_epoch, ---> 98 shuffle = True 99 ) 100 /opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch) 1424 use_multiprocessing=use_multiprocessing, 1425 shuffle=shuffle, -> 1426 initial_epoch=initial_epoch) 1427 1428 def evaluate_generator(self, /opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/training_generator.py in model_iteration(model, data, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch, mode, batch_size, **kwargs) 174 progbar.on_epoch_begin(epoch, epoch_logs) 175 --> 176 for step in range(steps_per_epoch): 177 batch_data = _get_next_batch(output_generator, mode) 178 if batch_data is None: TypeError: 'numpy.float64' object cannot be interpreted as an integer