IndexError: index 69791 is out of bounds for axis 0 with size 56044

IndexError: index 69791 is out of bounds for axis 0 with size 56044

def create_train_data():
    training_data = []
    for img in tqdm(os.listdir(TRAIN_DIR)):
        label = label_img(img)
        path = os.path.join(TRAIN_DIR, img)
        img = cv2.imread(path)
        img = cv2.resize(img, (IMG_SIZE, IMG_SIZE))
        training_data.append([np.array(img), np.array(label)])
    shuffle(training_data)
    np.save('train_data.npy', training_data)
    return training_data

train_data = create_train_data()

train = train_data[:-500]
test = train_data[-500:]

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

test_x = np.array([i[0] for i in test]).reshape(-1,IMG_SIZE,IMG_SIZE,1)
test_y = [i[1] for i in test]

model.fit({'input': X}, {'targets': Y}, n_epoch=3, validation_set=({'input': test_x}, {'targets': test_y}),
    snapshot_step=500, show_metric=True, run_id=MODEL_NAME)

**Getting following error**


Traceback (most recent call last):
Training samples: 168132
Validation samples: 1500
--
  File "C:\Users\Anas\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "C:\Users\Anas\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Anas\PycharmProjects\Minorproject\venv\lib\site-packages\tflearn\data_flow.py", line 187, in fill_feed_dict_queue
    data = self.retrieve_data(batch_ids)
  File "C:\Users\Anas\PycharmProjects\Minorproject\venv\lib\site-packages\tflearn\data_flow.py", line 222, in retrieve_data
    utils.slice_array(self.feed_dict[key], batch_ids)
  File "C:\Users\Anas\PycharmProjects\Minorproject\venv\lib\site-packages\tflearn\utils.py", line 187, in slice_array
    return X[start]
IndexError: index 69804 is out of bounds for axis 0 with size 56044

我有所有 32X32 像素 RGB 图像(4 波段)的图像。我收到上述错误。不知道为什么会越界,是不是图片太多了? 有谁知道我该如何解决这个问题?

您对它的整形不正确。你想加载 ARGB 图像,但你正在将 X 重塑为 reshape(-1,IMG_SIZE,IMG_SIZE,1) 而不是你应该为 4 通道图像做 reshape(-1,IMG_SIZE,IMG_SIZE,4),并且对你的 test_x 变量相同。

已编辑部分代码:

X = np.array([i[0] for i in train]).reshape(-1,IMG_SIZE,IMG_SIZE,4)
test_x = np.array([i[0] for i in test]).reshape(-1,IMG_SIZE,IMG_SIZE,4)