TypeError: Cannot convert 0.0 to EagerTensor of dtype int32

387 views
Skip to first unread message

Yegane Aghamohammadi

unread,
Apr 20, 2020, 1:05:27 PM4/20/20
to TensorFlow Community Testing

 am new to Tensorflow and I want to build a model with weight initializer.I want to initialize the weights with random int32. I defined a function to produce random numbers as the initializer of the weights. The function itself is ok. But When I want to use the function in one layer as the kernel_initializer, I encounter this error:

TypeError: Cannot convert 0.0 to EagerTensor of dtype int32

My code is below:


from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Conv2D, Flatten, MaxPooling2D, AveragePooling2D, Softmax
import tensorflow.keras.backend as K

model = Sequential()

model.add(Conv2D(6,kernel_size=5,activation='relu',input_shape=(32,32,1),name='Conv1'))


def my_init(shape, dtype=None):
    return K.random_normal(shape, dtype=tf.int32)

model.add(Dense(64, kernel_initializer=my_init))

I also tried another function which I defined np.array datatypes. It does not get an error but when I tried to see the weights of the layers, It showed that the types of the weights are float32, not int32. My problem is to feed and to get int32 datatypes for weights. 

Any help would be appreciated.

Reply all
Reply to author
Forward
0 new messages