MyClass is
class MyCalcSqureLayer(keras.layers.Layer):
def __init__(self, shape ):
super(MyCalcSqureLayer, self).__init__()
self.total = self.add_weight(initializer="zero", shape=shape, trainable=False)
def call(self,inputs):
print('type=',type(inputs))
x =inputs.shape[0]
print(x,type(x))
for i in range(x): <--- the valiable x's type will be change if this line.
print(i)
return inputs
When this code is running, the results shows as follows:
type= <class 'tensorflow.python.framework.ops.SymbolicTensor'>
None <class 'NoneType'>
But I commented the line out and the runs show:
type= <class 'tensorflow.python.framework.ops.EagerTensor'>
5 <class 'int'>
My enciroments information as follow:
tensorflow 2.17.0
python 3.11.8
PC MacOS M2
I would like to get the type int and want to make a code the follow rows tensor.
New contributor
Iwao Shikase is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.