AttributeError: 'numpy.ndarray' object has no attribute 'mode'

class Stack(object):

def __init__(self, roll=False):

    self.roll = roll

def __call__(self, img_group):

    if img_group[0].mode == 'L':

        return np.concatenate([np.expand_dims(x, 2) for x in img_group], axis=2)

    elif img_group[0].mode == 'RGB':

        if self.roll:

            return np.array([np.array(x)[:, :, ::-1] for x in img_group])


            return np.array([np.array(x) for x in img_group])

I guess your code expects img_group to be a list (or another container) containing PIL.Images, which provide the mode attribute.

1 Like

should i make loop on img_group list to convert all images on it to PIL.images like this ?

for i in range (len(img_group)):


I don’t think you would necessarily need to transform the inputs first to PIL.Images, as the method seems to return numpy arrays.
Since you are already passing numpy arrays to this method, you would need to check the channel dimension (instead of the mode) and re-write the logic to work on numpy arrays directly.

1 Like