Tensorflow / Keras CNN错误“函数调用堆栈:distributed_function”

时间:2020-07-06 14:11:19

标签: python python-3.x tensorflow keras conv-neural-network

我正在使用CNN,一旦第一个纪元完成,我就会收到错误消息:

"Function call stack: distributed_function"   

"Fused conv implementation does not support grouped convolutions for now."

我使用的是稍作修改的代码,该代码用于在前一个代码上使用过的另一个CNN,所以对于现在为什么会出现此错误,我有些困惑。

我使用的图像是类似于this的灰度热图图像

代码:

TRAINING_DIR = '/Users/me/School/Research/mini'
training_datagen = ImageDataGenerator(
    rescale = 1./255,
    rotation_range=40,
    width_shift_range=0.2,
    height_shift_range=0.2,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True,
    fill_mode='nearest')

train_generator = training_datagen.flow_from_directory(
    TRAINING_DIR,
    target_size=(640,480),
    class_mode='categorical'
)

model = tf.keras.models.Sequential([
    # Input shape is the desired size of the image 640x480 with 1 byte color
    # This is the first convolution
    tf.keras.layers.Conv2D(64, (3,3), activation='relu', input_shape=(640, 480, 1)),
    tf.keras.layers.MaxPooling2D(2, 2), # factors to downscale by, (2,2) will halve
    tf.keras.layers.Conv2D(64, (3,3), activation='relu'),   # 2nd convo layer
    tf.keras.layers.MaxPooling2D(2,2),
    tf.keras.layers.Conv2D(128, (3,3), activation='relu'),  # 3rd convo layer
    tf.keras.layers.MaxPooling2D(2,2),
    tf.keras.layers.Conv2D(128, (3,3), activation='relu'),  # 4th convo layer
    tf.keras.layers.MaxPooling2D(2,2),
    tf.keras.layers.Flatten(),            # Flatten to DNN
    tf.keras.layers.Dropout(0.5),
    tf.keras.layers.Dense(512, activation='relu'),      # hidden layer 
    tf.keras.layers.Dense(3, activation='softmax')      # 3 class 
])

model.summary()
model.compile(loss = 'categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy'])
history = model.fit(train_generator, epochs=15, verbose = 1)
model.save("rps.h5")

acc = history.history['accuracy']
loss = history.history['loss']
epochs = range(len(acc))

2 个答案:

答案 0 :(得分:0)

对我来说,这真是一个TensorFlow版本问题。我本应该使用1.13.2时才使用2.x。为了解决这个问题,我在做“将tensorflow导入为tf”之前做了此操作:

 !pip install tensorflow==1.13.2

这为我解决了。

答案 1 :(得分:0)

已将input_shape=(640, 480, 1)更改为input_shape=(640, 480, 3)