title: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
body: <p>This code is for classify 5 different classes of images. I have tried to use ImageDataGenerator() for image augmentation but when i run this code, I am havinh this error "error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'". </p>
  
  <p>How can i fix this error?
  Also I will appreciate if anyone can make other suitable changes to the code.</p>
  
  <pre><code>import cv2                
  import numpy as np         
  import os                
  from random import shuffle 
  from tqdm import tqdm      
  #from tensorflow import keras
  #from tensorflow.contrib import lite
  from keras.preprocessing.image import ImageDataGenerator
  from keras.models import Sequential
  
  TRAIN_DIR = 'train'
  VALID_DIR = 'validate'
  TEST_DIR = 'test'
  IMG_SIZE = 28
  LR = 1e-3
  train_samples = 250
  valdate_samples = 250
  epochs = 5
  batch_size = 10
  
  MODEL_NAME = 'snakes-{}-{}.model'.format(LR, '2conv-basic')
  
  def label_img(img):
      print("\nImage = ",img)
      print("\n",img.split('.')[-2])
      temp_name= img.split('.')[-2]
      #print("\n",temp_name[0:3])
      #temp_name=temp_name[0:3]
      print("\n",temp_name[:1])
      temp_name=temp_name[:1]
      #word_label = img.split('.')[-3]
      word_label = temp_name
  
     # word_label = img[0]
  
      if word_label == 'A': return [0,0,0,0,1]    
      elif word_label == 'B': return [0,0,0,1,0]
      elif word_label == 'C': return [0,0,1,0,0]
      elif word_label == 'D': return [0,1,0,0,0]
      elif word_label == 'E' : return [1,0,0,0,0]   
  
  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,cv2.IMREAD_GRAYSCALE)
          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
  
  
  def create_validate_data():
      validating_data = []
      for img in tqdm(os.listdir(TRAIN_DIR)):
          label = label_img(img)
          path = os.path.join(VALID_DIR,img)
          img = cv2.imread(path,cv2.IMREAD_GRAYSCALE)
          img = cv2.resize(img, (IMG_SIZE,IMG_SIZE))
          validating_data.append([np.array(img),np.array(label)])
      shuffle(validating_data)
      np.save('validate_data.npy', validating_data)
      return validating_data
  
  
  def process_test_data():
      testing_data = []
      for img in tqdm(os.listdir(TEST_DIR)):
          path = os.path.join(TEST_DIR,img)
          img_num = img.split('.')[0]
          img = cv2.imread(path,cv2.IMREAD_GRAYSCALE)
          img = cv2.resize(img, (IMG_SIZE,IMG_SIZE))
          testing_data.append([np.array(img), img_num])
      shuffle(testing_data)
      np.save('test_data.npy', testing_data)
      return testing_data
  
  train_data = create_train_data()
  validate_data = create_validate_data()
  
  
  import tflearn
  from tflearn.layers.conv import conv_2d, max_pool_2d
  from tflearn.layers.core import input_data, dropout, fully_connected
  from tflearn.layers.estimator import regression
  
  
  
  
  import tensorflow as tf
  tf.reset_default_graph()
  
  
  convnet = input_data(shape=[None, IMG_SIZE, IMG_SIZE, 1], name='input')
  
  convnet = conv_2d(convnet, 32, 5, activation='relu')
  convnet = max_pool_2d(convnet, 5)
  
  convnet = conv_2d(convnet, 64, 5, activation='relu')
  convnet = max_pool_2d(convnet, 5)
  
  convnet = conv_2d(convnet, 128, 5, activation='relu')
  convnet = max_pool_2d(convnet, 5)
  
  convnet = conv_2d(convnet, 64, 5, activation='relu')
  convnet = max_pool_2d(convnet, 5)
  
  convnet = conv_2d(convnet, 32, 5, activation='relu')
  convnet = max_pool_2d(convnet, 5)
  
  convnet = fully_connected(convnet, 1024, activation='relu')
  convnet = dropout(convnet, 0.8)
  
  convnet = fully_connected(convnet, 5, activation='softmax')
  convnet = regression(convnet, optimizer='adam', learning_rate=LR, loss='categorical_crossentropy', name='targets')
  
  model = tflearn.DNN(convnet, tensorboard_dir='log')
  
  
  
  if os.path.exists('{}.meta'.format(MODEL_NAME)):
      model.load(MODEL_NAME)
      print('model loaded!')
  
  #train = train_data[:-500]
  #test = train_data[-500:]
  
  #train = train_data[:-200]
  #test = train_data[-200:]
  train = train_data[0:]
  validate = validate_data[0:]
  
  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]
  validate_x = np.array([i[0] for i in validate]).reshape(-1,IMG_SIZE,IMG_SIZE,1)
  validate_y = [i[1] for i in validate]
  
  model.fit({'input': X}, {'targets': Y}, n_epoch=epochs, validation_set=({'input': validate_x}, {'targets': validate_y}), 
      snapshot_step=500, show_metric=True, run_id=MODEL_NAME)
  
  
  train_datagen = ImageDataGenerator(
      rescale=1. / 255,
      shear_range=0.2,
      zoom_range=0.2,
      horizontal_flip=True)
  
  validaton_datagen = ImageDataGenerator(rescale=1. / 255)
  
  train_generator = train_datagen.flow_from_directory('data/train',
                                                      target_size=(IMG_SIZE),
                                                      batch_size=batch_size,
                                                      class_mode='categorical')
  
  validation_generator = validaton_datagen.flow_from_directory('data/validation',
                                                          target_size=(IMG_SIZE),
                                                          batch_size=batch_size,
                                                          class_mode='categorical')
  
  model.fit_generator(train_generator,
                      steps_per_epoch=25,
                      epochs=epochs,
                      validation_data=validation_generator,
                      validation_steps=25)
  
  
  model.save(MODEL_NAME)
  
  #keras_file = "linear.h5"
  #keras.models.save_model(model,keras_file)
  </code></pre>