def create_classification_imageset(folder, image_size=10, image_count=10, add_unbalanced_category=False):
 paths = defaultdict(list)
 config = [('red-to-right', 0, 0, image_count), ('green-to-top', 1, 90, image_count), ('blue-to-left', 2, 180, image_count)]
 if add_unbalanced_category:
  config.append(('blue-to-bottom', 2, 270, (image_count / 2)))
 for (class_name, pixel_index, rotation, image_count) in config:
  os.makedirs(os.path.join(folder, class_name))
  colors = np.linspace(200, 255, image_count)
  for (i, color) in enumerate(colors):
   pixel = [0, 0, 0]
   pixel[pixel_index] = color
   pil_img = _create_gradient_image(image_size, (0, 0, 0), pixel, rotation)
   img_path = os.path.join(class_name, (str(i) + '.png'))
   pil_img.save(os.path.join(folder, img_path))
   paths[class_name].append(img_path)
 return paths

def create_classification_imageset ( folder , image_size = 10 , image_count = 10 , add_unbalanced_category = False ) : paths = defaultdict ( list ) config = [ ( 'red-to-right' , 0 , 0 , image_count ) , ( 'green-to-top' , 1 , 90 , image_count ) , ( 'blue-to-left' , 2 , 180 , image_count ) ] if add_unbalanced_category : config . append ( ( 'blue-to-bottom' , 2 , 270 , ( image_count / 2 ) ) ) for ( class_name , pixel_index , rotation , image_count ) in config : os . makedirs ( os . path . join ( folder , class_name ) ) colors = np . linspace ( 200 , 255 , image_count ) for ( i , color ) in enumerate ( colors ) : pixel = [ 0 , 0 , 0 ] pixel [ pixel_index ] = color pil_img = _create_gradient_image ( image_size , ( 0 , 0 , 0 ) , pixel , rotation ) img_path = os . path . join ( class_name , ( str ( i ) + '.png' ) ) pil_img . save ( os . path . join ( folder , img_path ) ) paths [ class_name ] . append ( img_path ) return paths
creates a folder of folders of images for classification if requested to add an unbalanced category then a category is added with half the number of samples of other categories .