ValueError:没有足够的值要解压(预期2,得到1)? [英] ValueError: not enough values to unpack (expected 2, got 1)?
本文介绍了ValueError:没有足够的值要解压(预期2,得到1)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
def cnn_data(data):
x, y = data.shape[1:]
return data.reshape((-1, x, y, 1))
我们介绍以下代码中使用的此功能.
We introduce this function used in the following code.
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])
代码产生以下错误.它试图训练卷积神经网络.
The code produces the following error. It tries to train a convolutional neural network.
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)
推荐答案
看来您的数据具有2维,所以data.shape [1:]只是一个整数.因此,错误消息
it seems like you data has 2 dimensions, so data.shape[1:] is only one integer. Hence the error message
这篇关于ValueError:没有足够的值要解压(预期2,得到1)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文