作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我从我的NN代码中收到一个相当烦人的错误,并希望对Keras如何工作有更好了解的人可以向我解释为什么我会收到该错误。感谢您的帮助!
错误:
AttributeError: 'DirectoryIterator' object has no attribute 'ndim'
Traceback (most recent call last):
File "C:\Users\Cameron\Desktop\AI\CubeFieldNN_Train -fix.py", line 80, in <module>
validation_steps = (validation_samples / batch_size))
NN.fit(
train_set, train_labels,
batch_size = batch_size,
epochs = epochs,
validation_data = (validation_set, validation_labels),
validation_steps = (validation_samples / batch_size))
Traceback (most recent call last):
File "C:\Users\Cameron\Desktop\AI\CubeFieldNN_Train -fix.py", line 80, in <module>
validation_steps = (validation_samples / batch_size))
File "C:\Python\lib\site-packages\keras\models.py", line 1002, in fit
validation_steps=validation_steps)
File "C:\Python\lib\site-packages\keras\engine\training.py", line 1630, in fit
batch_size=batch_size)
File "C:\Python\lib\site-packages\keras\engine\training.py", line 1476, in _standardize_user_data
exception_prefix='input')
File "C:\Python\lib\site-packages\keras\engine\training.py", line 76, in _standardize_input_data
data = [np.expand_dims(x, 1) if x is not None and x.ndim == 1 else x for x in data]
File "C:\Python\lib\site-packages\keras\engine\training.py", line 76, in <listcomp>
data = [np.expand_dims(x, 1) if x is not None and x.ndim == 1 else x for x in data]
AttributeError: 'DirectoryIterator' object has no attribute 'ndim'
最佳答案
确实没有必要从previous question从fit
过渡到fit_generator
。
flow_from_directory
返回一个生成器类型的对象,该对象返回数据和标签的元组。对于validation_set
同样如此。还要注意,如果指定validation_steps
,还必须指定steps_per_epoch
。因此,您可以使用:
NN.fit_generator(train_set,
steps_per_epoch=steps_per_epoch,
epochs=epochs,
validation_data=validation_set,
validation_steps=validation_steps)
NN.fit()
函数。
关于python - 错误-使用Keras的多分类神经网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50186035/
我是一名优秀的程序员,十分优秀!