ylliX - Online Advertising Network
Vertex AI - Antrophic and Mistral models: Why does it require Imegen access?

How to apply a threshold filter to a layer?


Having an array like this :

input = np.array([0.04, -0.8, -1.2, 1.3, 0.85, 0.09, -0.08, 0.2])

I want to change all the values between -0.1 and 0.1 to zero and change the rest to 1

filtred = [0, 1, 1, 1, 1, 0, 0, 1]

Using the lamnda layer is not my favor choice (I would prefer to get find a solution with a native layer which could be easily converted to TfLite) but I tried anyway :

layer = tf.keras.layers.Lambda(lambda x: 0 if x <0.1 and x>-0.1 else x)
layer(input)

I am getting :

ValueError: Exception encountered when calling Lambda.call().

The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Arguments received by Lambda.call():
  โ€ข inputs=tf.Tensor(shape=(6,), dtype=float32)
  โ€ข mask=None
  โ€ข training=None



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *