Skip to content

RuntimeError: Variable *= value not supported. Use var.assign(var * value) to modify the variable or var = var * value to get a new Tensor object. #18

@RaghuRajRai

Description

@RaghuRajRai

I'm able to get a summary of the model and while using the adam optimizer, I'm able to train the model. But while using the SGDWithWeightNorm, I'm getting an error.
I'm using:
Python 3.7
tensorflow 2.0
keras 2.3.1
in a conda environment.

I'm using a generator for training:
def imageX_generator(): i = 0 while(True): img1 = np.array(Image.open(X_filelist[i])) img1 = img1.astype('float32') img1 /= 255 img1 = np.reshape(img1, (1, 256, 256, 3)) img2 = np.array(Image.open(y_filelist[i])) img2 = img2.astype('float32') img2 /= 255 img2 = np.reshape(img2, (1, 256, 256, 3)) yield (img1, img2) i += 1 if i >= len(X_filelist) : i = 0

and calling it as:

history = model.fit_generator(imageX_generator(),steps_per_epoch=1, epochs=2)

Error:

`RuntimeError Traceback (most recent call last)
in
----> 1 history = model.fit_generator(imageX_generator(),steps_per_epoch=1, epochs=2)

d:\anaconda3\envs\env1\lib\site-packages\keras\legacy\interfaces.py in wrapper(*args, **kwargs)
89 warnings.warn('Update your ' + object_name + ' call to the ' +
90 'Keras 2 API: ' + signature, stacklevel=2)
---> 91 return func(*args, **kwargs)
92 wrapper._original_function = func
93 return wrapper

d:\anaconda3\envs\env1\lib\site-packages\keras\engine\training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
1730 use_multiprocessing=use_multiprocessing,
1731 shuffle=shuffle,
-> 1732 initial_epoch=initial_epoch)
1733
1734 @interfaces.legacy_generator_methods_support

d:\anaconda3\envs\env1\lib\site-packages\keras\engine\training_generator.py in fit_generator(model, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
40
41 do_validation = bool(validation_data)
---> 42 model._make_train_function()
43 if do_validation:
44 model._make_test_function()

d:\anaconda3\envs\env1\lib\site-packages\keras\engine\training.py in _make_train_function(self)
314 training_updates = self.optimizer.get_updates(
315 params=self._collected_trainable_weights,
--> 316 loss=self.total_loss)
317 updates = self.updates + training_updates
318

~\Desktop\weightnorm.py in get_updates(self, loss, params)
12 if self.initial_decay > 0:
13 lr *= (1. / (1. + self.decay * self.iterations))
---> 14 self.updates .append(K.update_add(self.iterations, 1))
15
16 # momentum

d:\anaconda3\envs\env1\lib\site-packages\tensorflow_core\python\ops\resource_variable_ops.py in imul(self, unused_other)
1227
1228 def imul(self, unused_other):
-> 1229 raise RuntimeError("Variable *= value not supported. Use "
1230 "var.assign(var * value) to modify the variable or "
1231 "var = var * value to get a new Tensor object.")

RuntimeError: Variable *= value not supported. Use var.assign(var * value) to modify the variable or var = var * value to get a new Tensor object.`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions