def cnn_data(data):
x, y = data.shape[1:]
return data.reshape((-1, x, y, 1))
我们在下面的代码中介绍这个函数的使用。
model.fit(cnn_data(self.train_X), np.array(self.train_y),
batch_size=batch_size,
epochs=num_epochs,
verbose=1,
class_weight=class_weight,
validation_data=(cnn_data(self.val_X), np.array(self.val_y)),
shuffle=True,
use_multiprocessing=True,
callbacks=[tensorboard, early_stopping])
该代码产生以下错误。它尝试训练卷积神经网络。
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Program Files\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "drunk_detector\__main__.py", line 808, in <module>
dd.train()
File "drunk_detector\__main__.py", line 283, in train
cnn = self.train_cnn_hyperparameters()
File "drunk_detector\__main__.py", line 653, in train_cnn_hyperparameters
model.fit(cnn_data(self.train_X), np.array(self.train_y),
File "drunk_detector\__main__.py", line 776, in cnn_data
x, y = data.shape[1:]
ValueError: not enough values to unpack (expected 2, got 1)