def __init__(self, keepdims=True, rgb=False, keepshape=False):
        """
        Args:
            keepdims (bool): return image of shape [H, W, 1] instead of [H, W]
            rgb (bool): interpret input as RGB instead of the default BGR
            keepshape (bool): whether to duplicate the gray image into 3 channels
                so the result has the same shape as input.
        """
        mode = cv2.COLOR_RGB2GRAY if rgb else cv2.COLOR_BGR2GRAY
        if keepshape:
            assert keepdims, "keepdims must be True when keepshape==True"
        super(Grayscale, self).__init__(mode, keepdims)
        self.keepshape = keepshape
        self.rgb = rgb

        Args:
            keepdims (bool): return image of shape [H, W, 1] instead of [H, W]
            rgb (bool): interpret input as RGB instead of the default BGR
            keepshape (bool): whether to duplicate the gray image into 3 channels
                so the result has the same shape as input.
        
tensorpack/dataflow/imgaug/convert.py