Giter Site home page Giter Site logo

about Loss Function about keras-fcn HOT 7 CLOSED

aurora95 avatar aurora95 commented on July 22, 2024
about Loss Function

from keras-fcn.

Comments (7)

aurora95 avatar aurora95 commented on July 22, 2024

Well it's an ugly implementation actually... The ignoring_last_label is used for many segmentation datasets like PASCAL VOC or Cityscapes, since they have a 255 label denoting the edge of objects or unknown part that should be ignored. I change 255 to nb_classes in data generator so that it becomes the last label, and then I ignore it in the loss function.
For your case, I think you can simply use a softmax or sigmoid loss (maybe you want to wrap a tensorflow loss instead of directly using the losses from keras, i'm not sure).

(modify: softmax of sigmoid => softmax or sigmoid)

from keras-fcn.

Amandaynzhou avatar Amandaynzhou commented on July 22, 2024

Thank you for your response^^.
I save img&label generated by SegDataGenerator I find that the label_cval, set 255. The label'.png' has white background around. So maybe it ignore this label? I'm not sure ....
Also my label'1' area is too small compared with '0'. I'm wondering if it is possible to multiply different weights to different label then calculate loss, changing some parts of the loss function.

from keras-fcn.

aurora95 avatar aurora95 commented on July 22, 2024

Yes by default ignore_label and label_cval are both 255 and it will be ignored.

You can pass a class_weight to fit_generator, note that considering the ignored label, there is actually nb_classes+1 classes. But some paper reports that for segmentation you don't need to deal with the unbalanced samples and it can still get good results, so maybe you can just try not using class_weights first.

from keras-fcn.

Ssica avatar Ssica commented on July 22, 2024

Hi @aurora95,
I have a quick question regarding your loss function too I was hoping you could help me out with:
I have my training data: 155x240x4 and my labels: 155x240 (a segmented image), am I still able to use your loss function? I'm unsure because of the following line in your loss function:

  • y_true = K.one_hot(tf.to_int32(K.flatten(y_true)), K.int_shape(y_pred)[-1]+1)

where u create a one_hot matrix from your y_train.

EDIT: grammar and phrasing
EDIT2: I'm trying to modify your loss function as I do not wish to remove the last label, I'm running the code but I'm assuming it is this part which removes the label:

  • unpacked = tf.unstack(y_true, axis=-1)
    
  • y_true = tf.stack(unpacked[:-1], axis=-1)
    

from keras-fcn.

aurora95 avatar aurora95 commented on July 22, 2024

@Ssica Yes you should be able to use the loss, and yes it's the code that removes the last label

from keras-fcn.

munanning avatar munanning commented on July 22, 2024

Hi @aurora95
use your loss and accurate funcion, we can fit the model.
But when I want to use the model to predict, the output has nb_classes maps, what should I do?
should I add softmax activation layer then use the argmax?
I'm sorry to bother you ,but I hope that you can give me some short codes to show how to make the (21,w,d) into (1, w, d) martix and whether we need softmax, because i had some issues when I try to implement it. Thanks a lot.

from keras-fcn.

aurora95 avatar aurora95 commented on July 22, 2024

@godissaw You can directly use argmax, since argmax(y) would yield the same result with argmax(softmax(y))

from keras-fcn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.