microsoft / CNTK

Microsoft Cognitive Toolkit (CNTK), an open source deep-learning toolkit
https://docs.microsoft.com/cognitive-toolkit/
Other
17.52k stars 4.28k forks source link

Per-pixel/per-element-loss of a tensor/matrix #3315

Open Mut1nyJD opened 6 years ago

Mut1nyJD commented 6 years ago

What would be the best way to implement a per-pixel / per-element loss in CNTK at the moment? As far as I could gather from the python documentation nearly all the loss function expect a vector-type shape? So would you have to reshape the tensor to a vector and then evaluate the loss and then shape the gradients back to the original tensor format?

Or is there another way of doing it?

delzac commented 6 years ago

Hi,

Actually there's a PR that may be what you are looking for.

fmeasure is used for semantic segmentation, i.e. whether this particular pixel is a car/road/building/etc.

Typically, if you don't have imbalance class, you should be able to use binary_cross_entropy or cross_entropy_with_softmax (you can't use cntk's implementation as it expects one vector per sample and in semantic segmentation you have multiple vectors per sample, as many vectors as pixel. However, implementing one on your own cross entropy for semantic segmentation should be trivial)

If you only have binary class, you can use cntk's implementation as is.

YanYas commented 5 years ago

Hi @delzac, did f-measure work for the semantic segmentation task? I noticed its something that has been mentioned as work-in-progress on a few issues. Did this loss function bring you any success and if so, with which network (UNet, FCN etc)?

delzac commented 5 years ago

Yup, it worked for me. It used it with UNET and FC-DenseNet. In #3396 , i added a suggestion in the docs on an easier form of the loss function to optimise. Basically you log() it.

Do let me know if it works better for you or not at all! :)

YanYas commented 5 years ago

Great to hear. I'll have to feedback here in a couple days time, but I'll endeavour to do so