因此,我目前正在进行一个图像分类实现tutorial,我正在使用CNN来实现该模型。CNN架构如下:
model=tf.keras.models.Sequential([
#first layer an input layer a shape of 100*150 RGP array of pictures
# 2D convutional layer with 32 nodes 3*3 filter
tf.keras.layers.Conv2D(32,(3,3),activation='relu',input_shape=(100,150,3)),
#2d maxpooling with size of 2*2
tf.keras.layers.MaxPooling2D(2,2),
#second layer
tf.keras.layers.Conv2D(64,(3,3),activation='relu'),
tf.keras.layers.MaxPooling2D(2,2),
#third layer
tf.keras.layers.Conv2D(128,(3,3),activation='relu'),
tf.keras.layers.MaxPooling2D(2,2),
#forth layer
tf.keras.layers.Conv2D(256,(3,3),activation='relu'),
tf.keras.layers.MaxPooling2D(2,2),
#flatten layer
tf.keras.layers.Flatten(),
#dense layer
tf.keras.layers.Dense(512,activation='relu'),
tf.keras.layers.Dense(3,activation='softmax')
]
)
model.compile(loss='categorical_crossentropy',optimizer=tf.optimizers.Adam(),
metrics=['accuracy'])
现在,当我运行fit
时,我得到这个错误。
history=model.fit(train_gen,steps_per_epoch=25,epochs=20,
validation_data=validation_gen,validation_steps=5,verbose=2,
callbacks=[my_callback()]
)
错误追溯如下
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
c:\Users\rabee\OneDrive\Desktop\rps-final-dataset\rbs_classification.ipynb Cell 20 in <cell line: 1>()
----> 1 model.fit(train_gen,steps_per_epoch=25,epochs=20,
2 validation_data=validation_gen,validation_steps=5,verbose=2,
3 callbacks=[my_callback()]
4
5 )
File c:\Users\rabee\AppData\Local\Programs\Python\Python310\lib\site-packages\keras\utils\traceback_utils.py:67, in filter_traceback.<locals>.error_handler(*args, **kwargs)
65 except Exception as e: # pylint: disable=broad-except
66 filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67 raise e.with_traceback(filtered_tb) from None
68 finally:
69 del filtered_tb
File c:\Users\rabee\AppData\Local\Programs\Python\Python310\lib\site-packages\scipy\ndimage\_interpolation.py:574, in affine_transform(input, matrix, offset, output_shape, output, order, mode, cval, prefilter)
572 npad = 0
573 filtered = input
--> 574 mode = _ni_support._extend_mode_to_code(mode)
575 matrix = numpy.asarray(matrix, dtype=numpy.float64)
576 if matrix.ndim not in [1, 2] or matrix.shape[0] < 1:
File c:\Users\rabee\AppData\Local\Programs\Python\Python310\lib\site-packages\scipy\ndimage\_ni_support.py:54, in _extend_mode_to_code(mode)
52 return 6
53 else:
---> 54 raise RuntimeError('boundary mode not supported')
RuntimeError: boundary mode not supported
我不明白问题boundary mode not supported
和如何解决它?
2条答案
按热度按时间ldxq2e6h1#
我得到了同样的错误,后来我发现我在train_datagen中拼错了“fill_mode”参数,在更正后它工作正常。
sxpgvts32#
我在Coursera上的CNN教程中遇到了完全相同的错误信息。首先是由model(fit)引发的,然后是keras.utils,最后是scipy.ndimage。
它在Colab上运行,而不是在Python 3.7.1本地运行。
不想劫持OP线程,但很想知道解决方案是什么。为了记录在案,我在下面插入了我的ImageDataGenerator代码。如果不合适,请删除。
验证生成器=验证数据源.流_自_目录(目录=验证目录,批处理大小=20,类模式=“二进制”,目标大小=(150,150))