Funny, but i ran into the exact same problem.
Using imagemagick to resize my masks resulted in mask images that contained interpolated RGB-color-values that didn’t match any entry of the dict. Imagemagick seems to use bilinear interpolation as the default method here.
So like @ptrblck and @robsoncs already stated, it is essential that operations on images should not create interpolated values. For resizing use an interpolation method like Nearest Neighbour.