python - Tensorflow / Keras CNN 错误“函数调用堆栈:distributed_function”
问题描述
我正在研究 CNN,一旦第一个 epoch 完成,我就会收到错误消息:
"Function call stack: distributed_function"
和
"Fused conv implementation does not support grouped convolutions for now."
我正在使用稍微修改过的代码,该代码用于另一个 CNN,该代码在前一个上工作,所以我对为什么现在发生这个错误有点迷茫。
我使用的图像是与此类似的灰度热图图像
代码:
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))
解决方案
通过更改input_shape=(640, 480, 1)
为解决input_shape=(640, 480, 3)
推荐阅读
- html - DIV 在视觉上嵌套在以前的 DIV 中
- python - python - 反序列化 avro 字节逻辑类型十进制到十进制
- python - 如何从 python 运行 docker 命令?
- bootstrap-4 - Bootstrap4可以设置没有装订线的列吗?
- c++ - 如何在传递给 C/C++ 宏之前解析 int 变量?
- javascript - 在具有绝对位置的先前警报下方添加警报?
- dialogflow-es - 如何使用 Dialogflow webhook 在对话中存储数据
- opencv - OpenCV FileStorage 文件大小似乎太大
- laravel - Laravel Nova 显示用户友好的资源名称
- powershell - 列目录为空?