Boolean indexing with keras
See original GitHub issueHi everyone,
Is it possible to use boolean indexing in Keras (with TF backend) ?
Here is a little script to see what I want to do, with the errors I get:
import numpy as np
import keras
from keras import backend as K
print(keras.__version__,K.tensorflow_backend.tf.__version__)
# 1.2.0 0.11.0rc2
m = np.random.randn(10,10)
b = np.random.uniform(size=(10,10))
M = K.variable(m)
B = K.variable(B)
boolean_mask = K.greater(B,0.5)
# This works fine, in numpy
np_bool = M.eval(session=K.get_session())[boolean_mask.eval(session=K.get_session())]
# But this does not
keras_bool = M[boolean_mask]
I am looking for something that is similar to tf.boolean_mask
.
Thank you in advance !
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:5
Top Results From Across the Web
Tensorflow indexing with boolean tensor - Stack Overflow
Is there a way to index with a boolean tensor right now or is that currently unsupported? python · indexing · tensorflow ·...
Read more >Pandas Boolean indexing - Javatpoint
Boolean indexing is defined as a very important feature of numpy, which is frequently used in pandas. Its main task is to use...
Read more >How Boolean Indexing works in Pandas. - Life With Data
Boolean Indexing on a DataFrame with single condition –. Let's read the data to work with. import pandas as pd import numpy as...
Read more >tf.boolean_mask | TensorFlow v2.11.0
K-D boolean Tensor, K <= N and K must be known statically. A 0-D int Tensor representing the axis in tensor to mask...
Read more >NumPy Boolean Indexing - Finxter
You can index specific values from a NumPy array using another NumPy array of Boolean values on one axis to specify the indices...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
this is a very desirable feature to have when writing custom loss functions. The solution by @MarkSeygan might works if loss then aggregated by sum, but breaks if the aggregation is performed with mean.
See tf.boolean_mask