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

ValueError: A KerasTensor cannot be used as input to a TensorFlow function. #5

Open
YasamanSamadi opened this issue Jun 17, 2024 · 0 comments

Comments

@YasamanSamadi
Copy link

YasamanSamadi commented Jun 17, 2024

Hi there,
I am studetn and am trying to run the code but haven't been able.
I migrated the code to T2 but still facing this issue and am not sure how to solve it, do you have any suggestion how I can fix this
Many thanks

My issue:
when I run the code I get this error :

 File "/home/ubuntu/ComGA-master/run.py", line 107, in <module>
    runner.erun(writer)
  File "/home/ubuntu/ComGA-master/anomaly_detection.py", line 68, in erun
    model = GCNModelAE(placeholders,num_features,num_nodes,adj,features_nonzero,2000,500,128,256,128,self.at)
  File "/home/ubuntu/ComGA-master/model.py", line 64, in __init__
    self.build()
  File "/home/ubuntu/ComGA-master/model.py", line 35, in build
    self._build()
  File "/home/ubuntu/ComGA-master/model.py", line 67, in _build
    self.hidden1 =Dense(input_dim=self.n_samples,
  File "/home/ubuntu/ComGA-master/layers.py", line 70, in __call__
    outputs = self._call(inputs)
  File "/home/ubuntu/ComGA-master/layers.py", line 179, in _call
    output = tf.matmul(x, self.vars['weights'])
  File "/opt/conda/lib/python3.10/site-packages/tensorflow/python/ops/weak_tensor_ops.py", line 142, in wrapper
    return op(*args, **kwargs)
  File "/opt/conda/lib/python3.10/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/opt/conda/lib/python3.10/site-packages/keras/src/backend/common/keras_tensor.py", line 91, in __tf_tensor__
    raise ValueError(
ValueError: A KerasTensor cannot be used as input to a TensorFlow function. A KerasTensor is a symbolic placeholder for a shape and dtype, used when constructing Keras Functional models or Keras Functions. You can only use it as input to a Keras layer or a Keras operation (from the namespaces `keras.layers` and `keras.operations`). You are likely doing something like:

x = Input(...)
...
tf_fn(x) # Invalid.


What you should do instead is wrap `tf_fn` in a layer:

class MyLayer(Layer):
def call(self, x):
return tf_fn(x)

x = MyLayer()(x)


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

1 participant