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波段)的所有图像。我收到了上述错误。我不知道为什么它会越界,不是因为太多的图像? 有谁知道如何解决这个问题?
答案 0 :(得分:0)
您正在重新错误地重塑它。您希望使用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)