question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error running model_target.py

See original GitHub issue

Hello, I am trying to recreate the results of subtask B, 2 way classification of the tweets, and I have taken the following steps: change the TASK = ‘BD’ in model_target.py

When I try running model_target.py, I am through until the model being trained, and then I get an error TypeError: Using a tf.Tensor as a Python bool is not allowed. Use if t is not None: instead of if t: to test if a tensor is defined, and use TensorFlow ops such as tf.cond to execute subgraphs conditioned on the value of a tensor.

I have tried installing an older version of Tensorflow, but still get the same result.

Here is the full error:--------- TypeError Traceback (most recent call last) <ipython-input-3-1c8602fef6c2> in <module>() 101 attention=“context”, 102 clipnorm=.1, –> 103 classes=len(classes)) 104 105 plot(nn_model, show_layer_names=True, show_shapes=True, to_file=“model_task4_sub{}.png”.format(TASK))

/models/neural/keras_models.py in target_RNN(wv, tweet_max_length, aspect_max_length, classes, **kwargs) 175 h_aspects = shared_RNN(aspects_emb) 176 h_aspects = Dropout(drop_target_rnn)(h_aspects) –> 177 h_aspects = MeanOverTime()(h_aspects) 178 h_aspects = RepeatVector(tweet_max_length)(h_aspects) 179

~/anaconda2/envs/py35/lib/python3.5/site-packages/keras/engine/topology.py in call(self, x, mask) 570 if inbound_layers: 571 # This will call layer.build() if necessary. –> 572 self.add_inbound_node(inbound_layers, node_indices, tensor_indices) 573 # Outputs were already computed when calling self.add_inbound_node. 574 outputs = self.inbound_nodes[-1].output_tensors

~/anaconda2/envs/py35/lib/python3.5/site-packages/keras/engine/topology.py in add_inbound_node(self, inbound_layers, node_indices, tensor_indices) 633 # creating the node automatically updates self.inbound_nodes 634 # as well as outbound_nodes on inbound layers. –> 635 Node.create_node(self, inbound_layers, node_indices, tensor_indices) 636 637 def get_output_shape_for(self, input_shape):

~/anaconda2/envs/py35/lib/python3.5/site-packages/keras/engine/topology.py in create_node(cls, outbound_layer, inbound_layers, node_indices, tensor_indices) 164 165 if len(input_tensors) == 1: –> 166 output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0])) 167 output_masks = to_list(outbound_layer.compute_mask(input_tensors[0], input_masks[0])) 168 # TODO: try to auto-infer shape

~/anaconda2/envs/py35/lib/python3.5/site-packages/kutilities/layers.py in call(self, x, mask) 21 if mask is not None: 22 mask = K.cast(mask, ‘float32’) —> 23 if not K.any(mask): 24 return K.mean(x, axis=1) 25 else:

~/anaconda2/envs/py35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py in bool(self) 612 TypeError. 613 “”" –> 614 raise TypeError("Using a tf.Tensor as a Python bool is not allowed. " 615 "Use if t is not None: instead of if t: to test if a " 616 "tensor is defined, and use TensorFlow ops such as "

TypeError: Using a tf.Tensor as a Python bool is not allowed. Use if t is not None: instead of if t: to test if a tensor is defined, and use TensorFlow ops such as tf.cond to execute subgraphs conditioned on the value of a tensor.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
cbaziotiscommented, Jun 8, 2018

Hi guys, sorry for taking so long to update the repository. I just updated the codebase. It now works with the latest versions of Keras (2.2.0) and Tensorflow (1.8.0). Please pull from the master and upgrade your packages from the requirements.

Please let me know if the updated code resolves your issues.

1reaction
cbaziotiscommented, Apr 21, 2018

Unfortunately, i have updated the repo in order to work with keras 2.x. There are some breaking changes from keras 1.X to 2.x. Also, this may be a TF issue. Note though, that the model initially was implemented in keras 1.2.2 with theano backend and i never tested it with TF.

Anyway, tell me also what is your version of TF and i will try to see what causes the problem when i get the time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Model Target error | Vuforia Developer Portal
Hi Im using sample Model Target in unity 2017.3.1f1, on game view i can't able to 2D guide view image and also getting...
Read more >
'Error when checking model target: expected no data, but got ...
If I run rnn.fit() again in console, I get following error message: ValueError: ('Error when checking model target: expected no data, but got ......
Read more >
Error when checking model target with ... - GitHub
I'm new to Python and Keras, but am running into something similar with my code – what does a shape of (None, 10)...
Read more >
How to Transform Target Variables for Regression in Python
In this section, we will demonstrate how to use the TransformedTargetRegressor on a real dataset. We will use the Boston housing regression ...
Read more >
tvm.driver.tvmc.TVMCImportError: onnx - Apache TVM Discuss
when i try run code like blow, i get an error : tvm.driver.tvmc. ... "/Users/chendongsheng/github/tvm/python/tvm/driver/tvmc/frontends.py", ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found