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

Compatibility with tensorflow = 2.5.0 and Keras = 2.4 #34

Closed
zeydabadi opened this issue Jun 15, 2021 · 4 comments
Closed

Compatibility with tensorflow = 2.5.0 and Keras = 2.4 #34

zeydabadi opened this issue Jun 15, 2021 · 4 comments

Comments

@zeydabadi
Copy link

I tried to run the example code below and receive the following error:
model = tf.keras.Sequential( layers=tf.keras.layers.Dense(units=2), name="Linear") model.compile(loss=tf.keras.losses.MeanSquaredError(), optimizer="adam")
ImportanceTraining(model).fit( x_train, y_train, batch_size=32, epochs=10, verbose=1,validation_data=(x_val, y_val) )

The error is below:

`---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
in
----> 1 ImportanceTraining(model).fit(
2 x_train, y_train,
3 batch_size=32,
4 epochs=10,
5 verbose=1,validation_data=(x_val, y_val)

~/myvenv/mykears3.9/lib/python3.9/site-packages/importance_sampling/training.py in init(self, model, presample, tau_th, forward_batch_size, score, layer)
368
369 # Call the parent to wrap the model
--> 370 super(ImportanceTraining, self).init(model, score, layer)
371
372 def sampler(self, dataset, batch_size, steps_per_epoch, epochs):

~/myvenv/mykears3.9/lib/python3.9/site-packages/importance_sampling/training.py in init(self, model, score, layer)
338 self._reweighting = BiasedReweightingPolicy(1.0) # no bias
339
--> 340 super(_UnbiasedImportanceTraining, self).init(model, score, layer)
341
342 @Property

~/myvenv/mykears3.9/lib/python3.9/site-packages/importance_sampling/training.py in init(self, model, score, layer)
33 self._check_model(model)
34 self.original_model = model
---> 35 self.model = OracleWrapper(
36 model,
37 self.reweighting,

~/myvenv/mykears3.9/lib/python3.9/site-packages/importance_sampling/model_wrappers.py in init(self, model, reweighting, score, layer)
167 # Augment the model with reweighting, scoring etc
168 # Save the new model and the training functions in member variables
--> 169 self._augment_model(model, score, reweighting)
170
171 def _gnorm_layer(self, model, layer):

~/myvenv/mykears3.9/lib/python3.9/site-packages/importance_sampling/model_wrappers.py in _augment_model(self, model, score, reweighting)
203 loss = model.loss
204 optimizer = model.optimizer.class(**model.optimizer.get_config())
--> 205 output_shape = model.get_output_shape_at(0)[1:]
206 if isinstance(loss, str) and loss.startswith("sparse"):
207 output_shape = output_shape[:-1] + (1,)

~/myvenv/mykears3.9/lib/python3.9/site-packages/tensorflow/python/keras/engine/base_layer.py in get_output_shape_at(self, node_index)
1986 RuntimeError: If called in Eager mode.
1987 """
-> 1988 return self._get_node_attribute_at_index(node_index, 'output_shapes',
1989 'output shape')
1990

~/myvenv/mykears3.9/lib/python3.9/site-packages/tensorflow/python/keras/engine/base_layer.py in _get_node_attribute_at_index(self, node_index, attr, attr_name)
2582 """
2583 if not self._inbound_nodes:
-> 2584 raise RuntimeError('The layer has never been called '
2585 'and thus has no defined ' + attr_name + '.')
2586 if not len(self._inbound_nodes) > node_index:

RuntimeError: The layer has never been called and thus has no defined output shape.
`

@angeloskath
Copy link
Collaborator

Hi,

I will close this issue since it is a known incompatibility. Check #25 for more information.

Cheers,
Angelos

@QuetzalcoatlRosso
Copy link

Here is a working example (as of earlier this year):
https://github.com/ibarrien/Adam-with-Bandit-Sampling/blob/main/banditutils/setup.py

See in general that repo:
https://github.com/ibarrien/Adam-with-Bandit-Sampling/

@angeloskath
Copy link
Collaborator

@QuetzalcoatlRosso wow thanks for the help :-). Admittedly, I should put this in the README.

@QuetzalcoatlRosso
Copy link

@angeloskath : cool, most welcome! README + setup.py that explicate the required versions would be awesome

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

No branches or pull requests

3 participants