lundi 6 décembre 2021

Design pattern or any way for data augmentation problem

I try to make data augmentation with my functions. I wrote some codes but I have a problem about one of them. Let's assume I have three data augmentation method which is zoom, rotate and reshape. I have designed these codes:

from .preprocessing import *

class customDataGenerator():

    def preprocess(self, functions : list, parameters : dict) -> list:

        """
        This function is process the all images in the database.

        functions: all functions which is desired like ['rotate','reshape','zoom']
   
        parameters: some parameters for data augmentation.
        parameters = {'zoom':{'zoomFactor':0.2, 'zoomDirectories':['in', 'out']},'reshape':{'sizes':(1920,1080),'interpolation':'nearest'}}
        
        """        

        functionsDict = {'rotate':rotate, 
                        'reshape':reshape, 
                        'zoom':zoom,
                        }

        tmImages = []
        #self.images = [[numpy.zeros((1,2,3)),0], [numpy.zeros((1,2,3))+1,1]]
        count = 0
        for image in self.images:
        
        
            
            #count+=1
            for functionName in functions:

                exposeToFunction = functionsDict[functionName]
                exposedImage = exposeToFunction(image,parameters[functionName])
                tmImages.extend(exposedImage)
                self.sampleCount +=1
        
        self.images.extend(tmImages)
        del tmImages




As you see, I get the images, process them and add the main images list as I want to have main images as well. But in reshape augmentation, it is different. It should process all images including main, original images. In this structure, it does not work because I want to reshape the all images including original and augmented, original images should be reshaped, dataset should not include different shaped images.

to solve this problem, I thought I can get all preprocessing functions into customDataGenerator class and make some process with instance variables. Like for rotate function, do everything and append original image list but for reshape, do everything in original image list. That is good idea but I want to make preprocessing step independed on customDataGenerator.And another solution is using if statements but I dont want to use it. I want to find a reproducuble, editible, developable solutions.

How can I do it ? Maybe with design pattern or other solutions.

Aucun commentaire:

Enregistrer un commentaire