我正在尝试为一个项目训练/使用带有 neupy 库的卷积神经网络,但我在训练阶段遇到了错误。
我有很多图像(rgb, shape=66, 160, 3),我将它们分成训练集和测试集。然后我正在尝试训练一个卷积神经网络(稍后我将尝试使用不同的算法、层数和大小进行优化)。我的项目的目标输出是一个数字 [-1, 1],我正在解决回归问题,但我之前遇到过问题。
我现在遇到的错误是:ValueError: Cannot shuffle matrices。所有矩阵应该有相同的行数
相关代码:
print numpy.array(y_train).shape
# outputs (84, 66, 160, 3)
print numpy.array(y_test).shape
# outputs (15, 66, 160, 3)
cgnet = algorithms.Adadelta(
[
layers.Input((6, 66, 160*3)),
layers.Convolution((8, 3, 3)),
layers.Relu(),
layers.Convolution((8, 3, 3)),
layers.Relu(),
layers.MaxPooling((2, 2)),
layers.Reshape(),
layers.Linear(1024),
layers.Softmax(10),
],
error='categorical_crossentropy',
step=1.0,
verbose=True,
shuffle_data=True,
#shuffle_data=False,
reduction_freq=8,
addons=[algorithms.StepDecay],
)
print cgnet.architecture()
cgnet.train(x_train, y_train, x_test, y_test, epochs=100)
输出:
Main information
[ALGORITHM] Adadelta
[OPTION] batch_size = 128
[OPTION] verbose = True
[OPTION] epoch_end_signal = None
[OPTION] show_epoch = 1
[OPTION] shuffle_data = True
[OPTION] step = 1.0
[OPTION] train_end_signal = None
[OPTION] error = categorical_crossentropy
[OPTION] addons = ['StepDecay']
[OPTION] decay = 0.95
[OPTION] epsilon = 1e-05
[OPTION] reduction_freq = 8
[THEANO] Initializing Theano variables and functions.
[THEANO] Initialization finished successfully. It took 7.01 seconds
Network's architecture
-------------------------------------------------
| # | Input shape | Layer Type | Output shape |
-------------------------------------------------
| 1 | (6, 66, 480) | Input | (6, 66, 480) |
| 2 | (6, 66, 480) | Convolution | (8, 64, 478) |
| 3 | (8, 64, 478) | Relu | (8, 64, 478) |
| 4 | (8, 64, 478) | Convolution | (8, 62, 476) |
| 5 | (8, 62, 476) | Relu | (8, 62, 476) |
| 6 | (8, 62, 476) | MaxPooling | (8, 31, 238) |
| 7 | (8, 31, 238) | Reshape | 59024 |
| 8 | 59024 | Linear | 1024 |
| 9 | 1024 | Softmax | 10 |
-------------------------------------------------
None
Start training
[TRAIN DATA] 84 samples, feature shape: (66, 160, 3)
[TEST DATA] 15 samples, feature shape: (66, 160, 3)
[TRAINING] Total epochs: 100
------------------------------------------------
| Epoch # | Train err | Valid err | Time |
------------------------------------------------
Traceback (most recent call last):
File "./ml_neupy.py", line 68, in <module>
cgnet.train(x_train, y_train, x_test, y_test, epochs=100)
File "/usr/local/lib/python2.7/dist-packages/neupy/algorithms/constructor.py", line 539, in train
*args, **kwargs
File "/usr/local/lib/python2.7/dist-packages/neupy/algorithms/learning.py", line 49, in train
summary=summary
File "/usr/local/lib/python2.7/dist-packages/neupy/algorithms/base.py", line 409, in train
target_train)
File "/usr/local/lib/python2.7/dist-packages/neupy/algorithms/utils.py", line 146, in shuffle
raise ValueError("Cannot shuffle matrices. All matrices should "
ValueError: Cannot shuffle matrices. All matrices should have the same number of rows
输入数据或网络有什么问题?
谢谢