(IndexError: индекс списка вне допустимого диапазона) Обнаружение пневмонии с использованием VGG16 - PullRequest
0 голосов
/ 06 августа 2020

Я получил ошибку при использовании VGG16 net. Это моя модель: -

    from keras.models import Model
    from keras.layers import Flatten, Dense
    from keras.applications import VGG16
    #from keras.preprocessing import image
    num_classes=2
    IMAGE_SIZE = [224, 224]  # we will keep the image size as (64,64). You can increase the size for 
   better results. 

# loading the weights of VGG16 without the top layer. These weights are trained on Imagenet dataset.

    vgg = VGG16(input_shape = (224,224,3), weights = 'imagenet', include_top = False)  # input_shape = 
   (64,64,3) as required by VGG

# this will exclude the initial layers from training phase as there are already been trained.

    for layer in vgg.layers:
        layer.trainable = False

    x = Flatten()(vgg.output)
    x = Dense(128, activation = 'relu')(x)   # we can add a new fully connected layer but it will increase the execution time.
    x = Dense(64, activation = 'relu')(x) 
    x = Dense(num_classes, activation = 'softmax')(x)  # adding the output layer with softmax function as this is a multi label classification problem.
    
    model = Model(inputs = vgg.input, outputs = x)
    
    model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
    model.summary()

это моя модель VGG16, когда я пытаюсь соответствовать моей модели, я получаю ошибку.

моя подходящая модель:

  history_pretrained = model.fit_generator(
    train_gen,
    epochs=16, shuffle = True, verbose = 1, validation_data = valid_gen)

IndexError: индекс списка вне допустимого диапазона

    train_gen = flow_from_dataframe(img_gen, train_df, 
                             path_col = 'path',
                            y_col = 'class_vec', 
                            target_size = IMG_SIZE,
                             color_mode = 'rgb',
                            batch_size = BATCH_SIZE)

valid_gen = flow_from_dataframe(img_gen, valid_df, 
                             path_col = 'path',
                            y_col = 'class_vec', 
                            target_size = IMG_SIZE,
                             color_mode = 'rgb',
                            batch_size = 256) # we can use much larger batches for evaluation

Я установил параметр intiall: -

# params we will probably want to do some hyperparameter optimization later
BASE_MODEL= 'VGG16'
IMG_SIZE = (224,224) # [(224, 224), (384, 384), (512, 512), (640, 640)]
BATCH_SIZE = 24 # [1, 8, 16, 24]
DENSE_COUNT = 128 # [32, 64, 128, 256]
DROPOUT = 0.5 # [0, 0.25, 0.5]
LEARN_RATE = 1e-4 # [1e-4, 1e-3, 4e-3]
TRAIN_SAMPLES = 6000 # [3000, 6000, 15000]
TEST_SAMPLES = 600
USE_ATTN = False # [True, False]

Получил ошибку: -

  /usr/local/lib/python3.6/dist-packages/keras_preprocessing/image/iterator.py in _get_batches_of_transformed_samples(self, index_array)
        225         filepaths = self.filepaths
        226         for i, j in enumerate(index_array):
    --> 227             img = load_img(filepaths[j],
        228                            color_mode=self.color_mode,
        229                            target_size=self.target_size,
    
    IndexError: list index out of range

почему он показывает индекс списка вне допустимого диапазона?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...