ValueError: not enough values to unpack (expected 2, got 1)?

房东的猫 提交于 2021-02-05 11:16:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!