Custom layer throws TypeError: Value passed to parameter 'x' has DataType int32 not in list of allowed values

hi everyone, i was trying to add a simple custom layer with no trainable parameters that does some arithmetical operation over the output of the previous lambda layer. it’s the first time i use a custom layer so i am not really sure of what should i do

class SimpleLayer(tf.keras.layers.Layer):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        pass


    def build(self, input_shape):
        pass


    def call(self, inputs):
        '''Defines the computation from inputs to outputs''' 
        return (25+  5/ tf.math.log( 10) *(  tf.math.log( 1/73) + tf.math.log(  inputs[:,0]) +0.5*(1- inputs[:,1]) *inputs[:,0] ))
         
import tensorflow_probability as tfp
import tensorflow as tf
from tensorflow.keras.layers import Dropout
from tensorflow.keras.layers import Input, concatenate 
from tensorflow.keras.layers import Dense
from tensorflow.keras.models import Model
from tensorflow.keras.optimizers import Adam
 
def create_aleatoric_model(train_size):
 
  def normal_sp(params): 
        return tfd.Normal(loc=params[:,0:1], scale=1e-3 + tf.math.softplus(0.05 * params[:,1:2]))
    
    
  inputs = Input(shape=(1,),name="input layer")
  x =  Dense(50, activation="relu")(inputs)
  x =  Dense(50, activation="relu")(x)
  x =  Dense(50, activation="relu")(x)


 
  params_mc = Dense(2,activation="relu")(x)
  dist_mc = tfp.layers.DistributionLambda(normal_sp, name='normal_sp', dtype=tf.float32)(params_mc) 
  conc = concatenate([inputs,dist_mc])
  
  uff=SimpleLayer()(conc)

  modello = Model(inputs=inputs, outputs=uff)
  return modello 

but when i try to train the model with

optimizer = tf.optimizers.Adam(learning_rate=0.0002)
aleatoric_model = create_aleatoric_model(train_size=train_size)
aleatoric_model.compile(optimizer=optimizer,
                  loss="mse"
                 ) 
aleatoric_model.build((None,1))
aleatoric_model.summary()



history_aleatoric_model = aleatoric_model.fit(X_train, y_train, epochs=19000, verbose=0, batch_size=batch_size )

i get the following error message

TypeError: Exception encountered when calling layer “simple_layer_15” (type SimpleLayer).

in user code:

File "<ipython-input-42-a2e7fcf3d506>", line 17, in call  *
    return 25+  5/ tf.math.log( 10) *(  tf.math.log( 1/73) + tf.math.log(  inputs[:,0]) +0.5*(1- inputs[:,1]) *inputs[:,0] )

TypeError: Value passed to parameter 'x' has DataType int32 not in list of allowed values: bfloat16, float16, float32, float64, complex64, complex128

Call arguments received:
• inputs=tf.Tensor(shape=(None, 2), dtype=float32)

what should i do to fix this problem?it’s really important

what should i do to fix this problem?it’s really important

has DataType int32

Something is mad about getting an int as input.

You’re doing too much stuff on one line here. This would be easier to debug if you split this up.
So you can see which operation is complaining.

It’s probably tf.math.log( 10). Try tf.math.log( 10.0).

ah yes thanks, it was as you said tf.math.log(10)

Good news: in tf2.10 the error messages prints the name of the failing op so you can see what broke.