def _determine_channels_and_depth(layers, depth, color_mode):
# type: (List[Layer], Optional[int], int) -> Tuple[int, int]
num_channels = 0
for image in _iterate_all_images(layers):
if (image.color_mode is not None and
image.color_mode != color_mode):
raise ValueError("Mismatched color mode")
for index, channel in image.channels.items():
if np.isscalar(channel):
continue
num_channels = max(num_channels, index + 1)
channel_depth = channel.dtype.itemsize * 8
if depth is None:
depth = channel_depth
elif depth != channel_depth:
raise ValueError("Different image depths in input")
if num_channels == 0 or depth is None:
raise ValueError("Can't determine num channels or depth")
return num_channels, depth
评论列表
文章目录