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.arraydatatypes. 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.
def create_int_matrix(shape, minval, maxval):
return tf.random.uniform(shape, minval=minval, maxval=maxval, dtype=tf.int32)