类型错误:'int' 对象在 np.random.seed 中不可调用

Nou*_*ssa 7 python random numpy

我正在尝试在 Kaggle 上的 2018 Data Science Bowl 之前的比赛中进行数据增强。我正在尝试这个代码:

## Data augmentation
# Creating the training Image and Mask generator
image_datagen = image.ImageDataGenerator(shear_range=0.5, rotation_range=50, zoom_range=0.2, width_shift_range=0.2, height_shift_range=0.2, fill_mode='reflect')
mask_datagen = image.ImageDataGenerator(shear_range=0.5, rotation_range=50, zoom_range=0.2, width_shift_range=0.2, height_shift_range=0.2, fill_mode='reflect')

# Keep the same seed for image and mask generators so they fit together
image_datagen.fit(X_train[:int(X_train.shape[0]*0.9)], augment=True, seed=42)
mask_datagen.fit(Y_train[:int(Y_train.shape[0]*0.9)], augment=True, seed=42)

x=image_datagen.flow(X_train[:int(X_train.shape[0]*0.9)],batch_size=BATCH_SIZE,shuffle=True, seed=42)
y=mask_datagen.flow(Y_train[:int(Y_train.shape[0]*0.9)],batch_size=BATCH_SIZE,shuffle=True, seed=seed)



# Creating the validation Image and Mask generator
image_datagen_val = image.ImageDataGenerator()
mask_datagen_val = image.ImageDataGenerator()

image_datagen_val.fit(X_train[int(X_train.shape[0]*0.9):], augment=True, seed=seed)
mask_datagen_val.fit(Y_train[int(Y_train.shape[0]*0.9):], augment=True, seed=seed)

x_val=image_datagen_val.flow(X_train[int(X_train.shape[0]*0.9):],batch_size=BATCH_SIZE,shuffle=True, seed=seed)
y_val=mask_datagen_val.flow(Y_train[int(Y_train.shape[0]*0.9):],batch_size=BATCH_SIZE,shuffle=True, seed=seed)
Run Code Online (Sandbox Code Playgroud)

这是错误消息:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-126-6b608552652e> in <module>
      5 
      6 # Keep the same seed for image and mask generators so they fit together
----> 7 image_datagen.fit(X_train[:int(X_train.shape[0]*0.9)], augment=True, seed=42)
      8 mask_datagen.fit(Y_train[:int(Y_train.shape[0]*0.9)], augment=True, seed=42)
      9 

~\Anaconda3\lib\site-packages\keras_preprocessing\image\image_data_generator.py in fit(self, x, augment, rounds, seed)
    941 
    942         if seed is not None:
--> 943             np.random.seed(seed)
    944 
    945         x = np.copy(x)

TypeError: 'int' object is not callable
Run Code Online (Sandbox Code Playgroud)

据我所知,错误seedimage_datagen.fit. fit就我而言,错误消息显示了代码中的一些内部问题。我不明白为什么。

我探索了其他类似的问题,但我发现它们都不适合我的问题。

这些是我读过的解决方案:

获取 TypeError: 'int' 对象不可调用

Python“int对象不可调用”

类方法 TypeError “Int 对象不可调用”

小智 12

确保您没有np.random.seed分配给脚本中某处的某个整数

像这样:

np.random.seed = 42
Run Code Online (Sandbox Code Playgroud)