AssertionError: Incoming Tensor shape must be 4-D

AssertionError: Incoming Tensor shape must be 4-D

我正在尝试制作一个分类器,但我一直收到这个错误,这让我很困惑。由于我对机器学习的东西真的很陌生,所以我在互联网上找不到任何东西。

错误

AssertionError: Incoming Tensor shape must be 4-D

代码

IMG_SIZE = 64
    tf.reset_default_graph()
    convnet = input_data(shape=[1,IMG_SIZE,IMG_SIZE,1],name='input')
    convnet = conv_2d(convnet, 32, 5, activation='relu')
    convnet = max_pool_2d(convnet, 5)
    convnet = conv_2d(convnet, 64, 5, activation='relu')
    convnet = max_pool_2d(convnet, 5)
    convnet = conv_2d(convnet, 128, 5, activation='relu')
    convnet = max_pool_2d(convnet, 5)
    convnet = conv_2d(convnet, 64, 5, activation='relu')
    convnet = max_pool_2d(convnet, 5)
    convnet = conv_2d(convnet, 32, 5, activation='relu')
    convnet = max_pool_2d(convnet, 5)
    convnet = fully_connected(convnet, 1024, activation='relu')
    convnet = dropout(convnet, 0.8)
    convnet = fully_connected(convnet, 2, activation='softmax')
    convnet = regression(convnet, optimizer='adam', learning_rate=LR, loss='categorical_crossentropy', name='targets')
    model = tflearn.DNN(convnet, tensorboard_dir='log', tensorboard_verbose=0)
    model.fit({'input': X_train}, {'targets': y_train}, n_epoch=10,
              validation_set=({'input': X_test}, {'targets': y_test}),
              snapshot_step=500, show_metric=True, run_id=MODEL_NAME)

如果我给convnet = input_data(shape=[None,IMG_SIZE,IMG_SIZE,1],name='input') 它给了我这个错误

Exception in thread Thread-3:

Traceback (most recent call last):
  File "C:\Users\zeele\Miniconda3\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "C:\Users\zeele\Miniconda3\lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\zeele\Miniconda3\lib\site-packages\tflearn\data_flow.py", line 187, in fill_feed_dict_queue
    data = self.retrieve_data(batch_ids)
  File "C:\Users\zeele\Miniconda3\lib\site-packages\tflearn\data_flow.py", line 222, in retrieve_data
    utils.slice_array(self.feed_dict[key], batch_ids)
  File "C:\Users\zeele\Miniconda3\lib\site-packages\tflearn\utils.py", line 187, in slice_array
    return X[start]
TypeError: 'generator' object is not subscriptable

编辑:错误是由于这个

train = training_data[:-5000]
test = testing_data[-5000:]

X_train = np.array([i[0] for i in train]).reshape(-1, IMG_SIZE, IMG_SIZE, 3)
#The error was here
y_train = (i[1] for i in train)

X_test = np.array([i[0] for i in test]).reshape(-1, IMG_SIZE, IMG_SIZE, 3)
#The error was here
y_test = (i[1] for i in test)

在 Y_train 中列出列表后,它开始工作,如下所示。

train = training_data[:-5000]

test = testing_data[-5000:]

X_train = np.array([i[0] for i in train]).reshape(-1, IMG_SIZE, IMG_SIZE, 3)

y_train = [i[1] for i in train]

X_test = np.array([i[0] for i in test]).reshape(-1, IMG_SIZE, IMG_SIZE, 3)
y_test = [i[1] for i in test]