问题
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)
回答1:
In this line of code x
and y
are two values while data.shape
is producing only one value:
x, y = data.shape[1:]
回答2:
it seems like you data has 2 dimensions, so data.shape[1:] is only one integer. Hence the error message
来源:https://stackoverflow.com/questions/64430514/valueerror-not-enough-values-to-unpack-expected-2-got-1