I have a network for semantic segmentation and the last layer of my model applies a sigmoid activation, so all predictions are scaled between 0-1. There is this validation metric tf.keras.metrics.MeanIoU(num_classes), which compares classified predictions (0 or 1) with validation (0 or 1). So if i make a prediction and apply this metric, will it automatically map the continuous predictions to binary with threshold = 0.5? Are there any possibilities to manually define the threshold?
tf.keras.metrics.MeanIoU with sigmoid layer
3.4k Views Asked by WillemBoone At
2
There are 2 best solutions below
0
刘亚龙
On
Try this(remember to replace the space with tab):
def mean_iou(y_true, y_pred):
th = 0.5
y_pred_ = tf.to_int32(y_pred > th)
score, up_opt = tf.metrics.mean_iou(y_true, y_pred_, 2)
K.get_session().run(tf.local_variables_initializer())
with tf.control_dependencies([up_opt]):
score = tf.identity(score)
return score
Related Questions in VALIDATION
- Escape dot in jquery validate plugin
- PHP form validation: Where to plop the code
- i want to create a service that does the login functionality?
- Stray start tag head, Element style not allowed as child of element body in this context. (Suppressing further errors from this subtree.)
- Html File Input on Chrome for Android missing extension and mime type
- javascript check input fields are not blank and check input field length?
- Symfony 2 form - date widget and validator
- Bean Validation message interpolation with array constraint parameter used as variable in message
- Bash regular expression execution hangs on long expressions
- Accessing the main object in a javax.validation.ConstraintValidator
- RAILS: date_select validation
- How can I define items of an array in a form in AngularJS
- Validation DataGridView Windows Forms
- How to handle multiple if statements PHP
- Restrict comma in asp.net textbox
Related Questions in BINARY
- Serializing to disk and deserializing Scala objects using Pickling
- Need Helped Understanding an 8-Bit Signed Decimal with 2's Compliment
- writing into file (Converting Base64 to Binary) values Using VFS and ESB 4.8.1
- Store 3 bit binary numbers in C++ array
- Benefits of storing hex in DB over file
- Binary to CSV record Converstion
- Add binary numbers like decimal numbers in Java. eg 0101 + 0110 = 0211
- Reading a line of binary file MATLAB
- Long.parseLong Error
- Reading binary file in Perl
- Fast Random Permutation of Binary Array
- Type safety and NEG instruction
- Populating data from a binary stream using byte array in java
- 1MiB = 1024KiB = 2^10. Nonetheless, why not use just 1000 byte instead 1024 to calculate size?
- Need help understanding how vectors are represented in binary [C++]
Related Questions in TF.KERAS
- Keras crashes when calling model.fit with GPU with large-ish datasets, without giving Out of memory however
- Error when Loading a .pb Tensorflow Model
- In tensorflow understanding pipeline what is use of take(1) in 'for feature_batch, label_batch in train_ds.take(1)'
- How to fine-tune pre-trained embeddings in embedding layer?
- Can I replace tf.keras.backend with tf?
- Transfer learning InceptionV3 show poor validation accuracy with training
- Can this be considered overfitting?
- TensorFlow: getting gradients batch-norm and bias
- tf.keras: feeding bool type variable along the input in model.fit method
- Why is my validation accuracy so much lower when I switch from doing all in-memory learning to a dada generator?
- tensorflow model with keras and tensorflow_addons layer is not getting loaded
- ValueError: You called `set_weights(weights)` on optimizer RMSprop with a weight list of length 3, but the optimizer was expecting 0 weights
- Why is my GAN not producing more good images after a certain point?
- Tensorflow Federated in a hierarchical fashion
- ValueError: Input 0 of layer lstm_17 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: [None, 128]
Related Questions in SIGMOID
- What is the difference between a sigmoid followed by the cross entropy and sigmoid_cross_entropy_with_logits in TensorFlow?
- Tensorflow 2.2 [predictions must be >= 0] [Condition x >= y did not hold element-wise:] [x (dense_1/Sigmoid:0) = ]
- How to get numpy.exp to work with an array as well as a scalar?
- Is there a way to round very large fractions like 3.7625745528893614e-83?
- Why XOR problem works better with bipolar representation?
- Simulate sklearn logistic regression predict_proba with only coefficients and intercept
- ValueError: Input 0 of layer "sequential_17" is incompatible with the layer: expected shape=(None, 6), found shape=(None, 5)
- My one neuron neural network does not work with my dataset
- Activation functions: Softmax vs Sigmoid
- Why is the decoder in an autoencoder uses a sigmoid on the last layer?
- How can I calculate cross-entropy on a sigmoid neural network binary outcome?
- How can I find a good fit for my function?
- How to specifiy a formula for combined linear and sigmoid function
- How to change PyTorch sigmoid function to be steeper
- How to pass on the output of a function to a sigmoid's function?
Related Questions in KERAS-METRICS
- Custom metric for Keras model, using Tensorflow 2.1
- ValueError: Shapes (None,) and (None, 1) are incompatible
- tf.keras.metrics.MeanIoU with sigmoid layer
- How do I solve Kera's MeanIoU Confusion matrix error?
- Custom keras metric with tensorflowflow functions. Uninitialized variables
- Separating custom keras metric inputs into two seperate metrics and finding median error
- Why does IoU as metrics for Semantic Segmentation raise a values error in Keras?
- Why keras AUC returns zero when multi-label is set?
- Tensorflow metrics with residual not zero during training
- How to use False Positives metric in Tensorflow 2.0?
- Whats the output for Keras categorical_accuracy metrics?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
No,
tf.keras.metrics.MeanIoUwill not automatically map the continuous predictions to binary with threshold = 0.5.It will convert the continuous predictions to its binary, by taking the binary digit before decimal point as predictions like
0.99as0,0.50as0,0.01as0,1.99as1,1.01as1etc whennum_classes=2. So basically if your predicted values are between0to1andnum_classes=2, then everything is considered0unless the prediction is1.Below are the experiments to justify the behavior in
tensorflow version 2.2.0:All binary result :
Output -
Change one prediction to continuous 0.99 - Here it considers
0.99as0.Output -
Change one prediction to continuous 0.01 - Here it considers
0.01as0.Output -
Change one prediction to continuous 1.99 - Here it considers
1.99as1.Output -
So ideal way is to define a function to convert the continuous to binary before evaluating the
MeanIoU.Hope this answers your question. Happy Learning.