How to get or convert contents of Keras Tensor using tf.keras.Input()?

1,654 views
Skip to first unread message

shahrokh nasseri

unread,
Jun 9, 2021, 9:40:05 AM6/9/21
to Keras-users

Hello Dears Keras Developers and users

In the example given about the classification of structural data (Structured data classification from scratch in Code examples) on the web page of Keras, I want to get/see the contents of objects such as age_encoded or trestbps_encoded.

These objects are tensorflow.python.framework.ops.Tensor.

How can I get or view the contents of these tensors?

I googled very much, but could not find correct solution for doing it. I noticed that I can view the content of eager tensor, for example:

import tensorflow as tf
a = tf.constant([[1, 2], [3, 4]])
print(a)
tf.Tensor(
[[1 2]
 [3 4]], shape=(2, 2), dtype=int32)

I can not get the contents of age_encoded:

print(age_encoded)
Tensor("normalization/truediv:0", shape=(None, 1), dtype=float32)

In other words, can I convert tensorflow.python.framework.ops.Tensor to tensorflow.python.framework.ops.EagerTensor and how to do it?

Specifications Tensorflow and Keras installed in Anaconda (ipython):

Keras: 2.3.0-tf

Tensorflow: 2.2.0

Specifications Tensorflow and Keras installed Pycharm:

Keras: 2.4.0

Tensorflow: 2.3.0


Please guide me.

I am waiting for your help.

Best regards.

Shahrokh

Lance Norskog

unread,
Jun 10, 2021, 2:12:47 PM6/10/21
to shahrokh nasseri, Keras-users

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/43556053-8d41-4a50-8b97-b8f10b29c64an%40googlegroups.com.


--
Lance Norskog
lance....@gmail.com
Redwood City, CA

shahrokh nasseri

unread,
Jun 12, 2021, 4:11:32 AM6/12/21
to Keras-users

Dear Lance

Thanks a lot for your guidance. Unfortunately I got another error after using the eval function.

I run the model provided in Keras until after the object of age_encoded, and then run the following commands and get error.

a1.png


I found a solution in stackoverflow, but again I get error:

a2.png

So I still can not see the contents of the tensor object.

Please guide me.

Best regards.

Shahrokh

Reply all
Reply to author
Forward
0 new messages