KeyError 0 в Google Colab - PullRequest
       84

KeyError 0 в Google Colab

0 голосов
/ 01 августа 2020

Несмотря на то, что я не использую словарь python, я получаю KeyError: 0!

Это ошибка, которую я получаю при попытке обучения моей модели CNN.

ERROR

Это соответствующий фрагмент кода:

epochs = 5
batch_size = 64
num = len(x_train)

for epoch in range(epochs):
  for i in tqdm(range(int(num / batch_size))):
    train_x_ep, train_y_ep= TrainImageLoad(batch_size)
    train_x_ep = np.array(train_x_ep)
    train_x_ep = train_x_ep.astype(np.float16)
    train_y_ep = np.array(train_y_ep)
    train_y_ep = train_y_ep.astype(np.float16)
    train_y_ep.reshape(-1, 1)

    test_x_ep, test_y_ep = TestImageLoad(batch_size)  # THIS IS LINE 40
    test_x_ep = np.array(test_x_ep)
    test_x_ep = test_x_ep.astype(np.float16)
    test_y_ep = np.array(test_y_ep)
    test_y_ep = test_y_ep.astype(np.float16)
    test_y_ep.reshape(-1, 1)

    model.fit(train_x_ep, train_y_ep, validation_data = [test_x_ep, test_y_ep])

Функция TestImageLoad определяется следующим образом:

def TestImageLoad(batch_size):
  global Tester
  global x_test
  global y_test
  xt = []
  yt = []
  l = len(x_test)
  for i in range(batch_size):
    img1 = image.load_img(data_path + str(x_test[(i + Tester) % l]) +'.jpg', color_mode = 'rgb', target_size = [224, 224])
    img1 = image.image.img_to_array(img1) / 255.0
    img1 = img1.astype(np.float16)
    xt.append(img1)
    yt.append(y_test[(i + Tester) % l]) #*np.pi/180
    Tester += 1 

  return xt, yt

Я пробовал запустить ее Google Colab, на GPU, и каждый раз он показывал мне эту ошибку 1 Как преодолеть эту ошибку?

...