【发布时间】:2021-06-09 15:01:00
【问题描述】:
我注意到有一个 preprocess_input 函数根据您要在 tensorflow.keras.applications 中使用的模型而有所不同。
我正在使用ImageDataGenerator 类来扩充我的数据。更具体地说,我使用的是 CustomDataGenerator,它扩展自 ImageDataGenerator 类并添加了颜色转换。
看起来是这样的:
class CustomDataGenerator(ImageDataGenerator):
def __init__(self, color=False, **kwargs):
super().__init__(preprocessing_function=self.augment_color, **kwargs)
self.hue = None
if color:
self.hue = random.random()
def augment_color(self, img):
if not self.hue or random.random() < 1/3:
return img
img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
img_hsv[:, :, 0] = self.hue
return cv2.cvtColor(img_hsv, cv2.COLOR_HSV2BGR)
我在ImageDataGenerator 上使用了rescale=1./255,但有些模型需要不同的预处理。
所以当我尝试时
CustomDataGenerator(preprocessing_function=tf.keras.applications.xception.preprocess_input)
我收到此错误:
__init__() got multiple values for keyword argument 'preprocessing_function'
【问题讨论】:
标签: python tensorflow machine-learning keras