I am trying to write a compact transform, instead of the if-else, if-else statement. I am, thus, getting an error saying Object None is not callable
. Any trick around this, or should I use something else than None? Or, I need to go back to the if-else if else…etc?
image_transfrom = transforms.Compose([
ImageThinning(p = cf.thinning_threshold) if cf.thinning_threshold> 0 else None,
PadImage((cf.MAX_IMAGE_WIDTH, cf.MAX_IMAGE_HEIGHT)) if cf.pad_images else None,
transforms.ToPILImage(),
transforms.Scale((cf.input_size[0], cf.input_size[1])) if cf.resize_images else None,
transforms.ToTensor(),
transforms.Normalize( (0.5, 0.5, 0.5), (0.25, 0.25 , 0.25) ) if cf.normalize_images else None,
])
Of course one way to resolve this issue is to write a class called NoneTransform
that does nothing to the image and pass it to compose instead of the value None
.
Update: The NoneTransform
does the job, here it is:
class NoneTransform(object):
""" Does nothing to the image, to be used instead of None
Args:
image in, image out, nothing is done
"""
def __call__(self, image):
return image