skyunyoo:

All of my targets consist of a pixel value 0 (background) or other(desire target).


That would mean, that the background class is the class index 0.



 skyunyoo:

I this case, If I apply the transform method that you suggested without having to process a pixel with a value of 0, will it have two classes?


In my example I created a target containing only two valid classes:

background with class index 0
not-background with class index 1

If your non-background class uses another index than 1, you should also convert it to 1 for a binary classification use case.