title: I am getting list 'index out of range' while using model.predict in keras
body: <p>This is my code and I am using transfer learning to train my model. But I am getting index out of range error. It is giving this error for model.predict() function, when tried to test my model. What could be the reason?</p>
  <pre><code>IMAGE_SIZE = [100, 100]
  
  train_path = 'input/train'
  valid_path = 'input/val'
  </code></pre>
  <p>add preprocessing layer to the front of VGG</p>
  <pre><code>vgg = VGG16(input_shape=IMAGE_SIZE + [3], weights='imagenet', include_top=False)
  
  # don't train existing weights
  for layer in vgg.layers:
    layer.trainable = False
  </code></pre>
  <p>useful for getting number of classes</p>
  <pre><code>folders = glob('input/train/*')
  </code></pre>
  <p>our layers</p>
  <pre><code>x = Flatten()(vgg.output)
  # x = Dense(1000, activation='relu')(x)
  prediction = Dense(len(folders), activation='softmax')(x)
  </code></pre>
  <p>create a model object</p>
  <pre><code>model = Model(inputs=vgg.input, outputs=prediction)
  </code></pre>
  <p>view the structure of the model</p>
  <pre><code>model.summary()
  </code></pre>
  <p>tell the model what cost and optimization method to use</p>
  <pre><code>model.compile(
    loss='categorical_crossentropy',
    optimizer='adam',
    metrics=['accuracy']
  )
  </code></pre>
  <pre><code>from keras.preprocessing.image import ImageDataGenerator
  
  train_datagen = ImageDataGenerator(rescale = 1./255,
                                     shear_range = 0.2,
                                     zoom_range = 0.2,
                                     horizontal_flip = True)
  
  test_datagen = ImageDataGenerator(rescale = 1./255)
  
  training_set = train_datagen.flow_from_directory('input/train',
                                                   target_size = (100, 100),
                                                   batch_size = 32,
                                                   class_mode = 'categorical')
  
  val_set = test_datagen.flow_from_directory('input/val',
                                              target_size = (100, 100),
                                              batch_size = 32,
                                              class_mode = 'categorical')
  </code></pre>
  <p>fit the model</p>
  <pre><code>r = model.fit(
    training_set,
    validation_data=val_set,
    epochs=50,
    steps_per_epoch=len(training_set),
    validation_steps=len(val_set)
  )
  </code></pre>
  <p>This particular line is giving error</p>
  <pre><code>model.predict('/content/input/test/0/IMG_4099.JPG')
  </code></pre>