gpt4 book ai didi

python-3.x - 索引错误: index 69791 is out of bounds for axis 0 with size 56044

转载 作者:行者123 更新时间:2023-11-30 09:17:39 25 4
gpt4 key购买 nike

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 波段)的所有图像。我收到上述错误。不知道为什么会越界,是不是图片太多了?有人知道如何解决这个问题吗?

最佳答案

您对它的 reshape 不正确。你想要laod ARGB图像,但你正在将X reshape 为reshape(-1,IMG_SIZE,IMG_SIZE,1),而不是你应该做reshape(-1,IMG_SIZE,IMG_SIZE,4) code> 用于 4 channel 图像,与您的 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)

关于python-3.x - 索引错误: index 69791 is out of bounds for axis 0 with size 56044,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50843392/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com