The label image will be read as NoneType when running this line:
mask = cv2.imread(os.path.join(root+'{}_mask.png').format(id), cv2.IMREAD_GRAYSCALE)
Maybe it should be changed like this:
mask = cv2.imread(os.path.join(root, '{}_mask.png').format(id), cv2.IMREAD_GRAYSCALE)