def __init__(self, name, inputSlot=None, processFunc=None, outputType=None, slotType=None, iterator=None, sequence=None, classes=None, useLazyEvaluation=armor.useLazyEvaluation, useCaching=armor.useCaching): self.name = name self.inputSlot = inputSlot self.outputType = outputType self.iterator = iterator self.sequence = sequence self.processFunc = processFunc # Create an output container if self.sequence is not None: self.container = SeqContainer(sequence=self.sequence, classes=classes, useLazyEvaluation=useLazyEvaluation, useCaching=useCaching) elif self.iterator is not None: # User defined iterator self.container = SeqContainer(generator=self.iterator, classes=classes, useLazyEvaluation=useLazyEvaluation, useCaching=useCaching) elif slotType == 'sequential': # Sequential iterator if self.processFunc is None and self.processFuncs is None: raise AttributeError, "You must provide processFunc or processFuncs to use generic iterators" self.container = SeqContainer(generator=armor.weakmethod(self, 'seqIterator'), classes=classes, useLazyEvaluation=useLazyEvaluation, useCaching=useCaching) elif slotType == 'bulk': # Bulk iterator if self.processFunc is None and self.processFuncs is None: raise AttributeError, "You must provide processFunc or processFuncs to use generic iterators" self.container = SeqContainer(generator=armor.weakmethod(self, 'bulkIterator'), classes=classes, useLazyEvaluation=useLazyEvaluation, useCaching=useCaching) else: self.container = None
def __init__(self, **kwargs): super(VectorType, self).__init__(**kwargs) self.attributes = {'shape': ['nestedlist', 'nestedarray', 'flatarray', 'flatlist'], 'length': [type(1)] } self.conversions = [{'shape': ('nestedlist', 'flatarray'), 'function': armor.weakmethod(self, 'convert_nestedlist_to_flatarray')}, {'shape': ('nestedarray', 'flatarray'), 'function': armor.weakmethod(self, 'convert_nestedlist_to_flatarray')} ]
def __init__(self, transtype, kernel=None, useLazyEvaluation=armor.useLazyEvaluation): self.transtype = transtype if self.transtype not in ['PCA','KPCA', 'LLE', 'none']: raise NotImplementedError, "No operation mode specified" if kernel is None: self.kernel = 'gaussian_kernel' elif kernel not in ['linear_kernel', 'gaussian_kernel', 'chi2_kernel']: raise NotImplementedError, "Wrong kernel chosen" else: self.kernel = kernel self.inputTypeData = armor.slots.VectorType(shape=['flatarray'], bulk=True) self.inputTypeLabels = armor.slots.VectorType(name=['labels'], shape=['flatlist']) self.outputType = armor.slots.VectorType(shape='flatarray') self.inputSlotData = armor.slots.InputSlot(name='untransformed', acceptsType=self.inputTypeData) self.inputSlotLabels = armor.slots.InputSlot(name='labels', acceptsType=self.inputTypeLabels) self.outputSlot = armor.slots.OutputSlot(name='transformed', outputType=self.outputType, useLazyEvaluation=useLazyEvaluation, iterator=armor.weakmethod(self, 'iterator'))
def __init__(self, **kwargs): super(ImageType, self).__init__(**kwargs) self.attributes = {'format': ['PIL', 'numpy'], 'color_space': ['gray', 'RGB'] } self.conversions = [{'format': ('PIL', 'PIL'), 'color_space': ('RGB', 'gray'), 'function': armor.weakmethod(self, 'convert_PIL_RGB_to_PIL_gray')}, {'format': ('PIL', 'numpy'), 'color_space': ('RGB', 'RGB'), 'function': armor.weakmethod(self, 'convert_PIL_RGB_to_numpy_RGB')}, {'format': ('PIL', 'numpy'), 'color_space': ('RGB', 'gray'), 'function': armor.weakmethod(self, 'convert_PIL_RGB_to_numpy_gray')} ]
def __init__(self, useLazyEvaluation=armor.useLazyEvaluation): self.useLazyEvaluation = useLazyEvaluation self.inputType = armor.slots.VectorType(shape=['flatarray']) self.outputType = armor.slots.VectorType(shape='flatarray') self.inputSlots = [] self.inputSlot = property(fget=self.__createSlot) self.outputSlot = armor.slots.OutputSlot(name='concatenated', iterator=armor.weakmethod(self, 'concatenate'), outputType=self.outputType, useLazyEvaluation = self.useLazyEvaluation)
def __init__(self, useLazyEvaluation=armor.useLazyEvaluation): self.inputType = armor.slots.ImageType(format=['PIL'], color_space=['gray']) self.outputType = armor.slots.VectorType(shape='flatarray') self.inputSlot = armor.slots.InputSlot(name='unnormalized', acceptsType=self.inputType) self.outputSlot = armor.slots.OutputSlot(name='normalized', inputSlot=self.inputSlot, slotType='sequential', processFunc=armor.weakmethod(self, 'fft2'), outputType=self.outputType, useLazyEvaluation=useLazyEvaluation)
def registerInput(self, senderSlot): """Register senderSlot as an inputSlot. inputType and outputType have to match (or be convertable). """ if armor.useTypeChecking and self.acceptsType is not None: if senderSlot.outputType is not None: senderType = senderSlot.outputType elif senderSlot.inputSlot.outputType is not None: # If the output slot does not transform the input # type, it may be found in the inputslot senderType = senderSlot.inputSlot.outputType else: raise ValueError, "No types specified" # Check if sender type is compatible with us or if we can # convert (compatible() will return converter functions) compatible = self.acceptsType.compatible(senderType) if compatible == False: raise TypeError, "Slots are not compatible" # Else compatible() returns the new type and conversion funcs (self.outputType, self.converters) = compatible # Register the new slot self.senderSlot = weakref.ref(senderSlot) # Callback to tell the senderSlot container to update its data # (if necessary) # senderSlot.container.recompute() if armor.useCaching: # Register us to the senderSlot senderSlot.container.registerReference(self) # Initialize the container to store the data (or the reference to it) if not self.bulk: self.container = SeqContainer(generator=armor.weakmethod(self, 'convertSequential'), useLazyEvaluation=self.useLazyEvaluation) else: self.container = SeqContainer(generator=armor.weakmethod(self, 'convertBulk'), useLazyEvaluation=self.useLazyEvaluation)
def __init__(self, useLazyEvaluation=armor.useLazyEvaluation, **kwargs): self.useLazyEvaluation = useLazyEvaluation self.kwargs = kwargs # Define types self.inputType = armor.slots.ImageType(format=["PIL"]) self.outputType = armor.slots.VectorType(shape='nestedarray') # Define slots self.inputSlot = armor.slots.InputSlot(name='Images', acceptsType = self.inputType, useLazyEvaluation=useLazyEvaluation) self.outputSlot = armor.slots.OutputSlot(name='Sift Descriptors', outputType=self.outputType, inputSlot=self.inputSlot, processFunc=armor.weakmethod(self, 'process'), slotType='sequential', useLazyEvaluation=self.useLazyEvaluation)
def __init__(self, bins, useLazyEvaluation=armor.useLazyEvaluation): self.useLazyEvaluation = useLazyEvaluation self.bins = bins inputType = armor.slots.VectorType(shape=['flatarray']) outputType = armor.slots.VectorType(shape='flatarray') self.inputSlot = armor.slots.InputSlot(name='vector', acceptsType=inputType) self.outputSlot = armor.slots.OutputSlot(name='histogram', inputSlot = self.inputSlot, slotType = 'sequential', processFunc = armor.weakmethod(self, 'histogram'), outputType = outputType, useLazyEvaluation = self.useLazyEvaluation)
def __init__(self, useLazyEvaluation=armor.useLazyEvaluation): self.inputTypeData = armor.slots.VectorType(shape=['flatarray']) self.inputTypeLabels = armor.slots.VectorType(name=['labels'], shape=['flatlist']) self.outputType = armor.slots.VectorType(shape='flatarray') self.inputSlotData = armor.slots.InputSlot(name='untransformed', acceptsType=self.inputTypeData) self.inputSlotLabels = armor.slots.InputSlot(name='labels', acceptsType=self.inputTypeLabels) self.outputSlot = armor.slots.OutputSlot(name='transformed', outputType=self.outputType, useLazyEvaluation=useLazyEvaluation, iterator=armor.weakmethod(self, 'iterator'))
def __init__(self, normtype, useLazyEvaluation=armor.useLazyEvaluation): self.normtype = normtype #if self.normtype in ['bin', 'L1','L2', 'whiten', 'bias', 'crop', 'log', 'none']: # raise ValueError, "No operation mode specified" self.inputType = armor.slots.VectorType(shape=['flatarray'], bulk=True) self.outputType = armor.slots.VectorType(shape='flatarray') self.inputSlot = armor.slots.InputSlot(name='unnormalized', acceptsType=self.inputType) self.outputSlot = armor.slots.OutputSlot(name='normalized', inputSlot=self.inputSlot, slotType='bulk', processFunc=armor.weakmethod(self, 'normalize'), outputType=self.outputType, useLazyEvaluation=useLazyEvaluation)
def __init__(self, metric = 'euclidean', plot=True, useLazyEvaluation=armor.useLazyEvaluation): self.metric = metric self.plot = plot self.inputTypeData = armor.slots.VectorType(shape=['flatarray']) self.outputType = armor.slots.VectorType(shape='flatarray') self.inputSlot = armor.slots.InputSlot(name='data', acceptsType=self.inputTypeData, bulk=True) self.outputSlot = armor.slots.OutputSlot(name='distance matrix', outputType=self.outputType, useLazyEvaluation=useLazyEvaluation, slotType = 'bulk', inputSlot=self.inputSlot, processFunc = armor.weakmethod(self, 'pdist'))
def __init__(self, scoretype='clustering', useLazyEvaluation=armor.useLazyEvaluation): self.scoretype = scoretype if self.scoretype not in ['clustering']: raise NotImplementedError, "No such score type" self.inputTypeData = armor.slots.VectorType(shape=['flatarray'], bulk=True) self.inputTypeLabels = armor.slots.VectorType(name=['labels'], shape=['flatlist']) self.outputType = armor.slots.VectorType(shape='flatarray') self.inputSlotData = armor.slots.InputSlot(name='untransformed', acceptsType=self.inputTypeData) self.inputSlotLabels = armor.slots.InputSlot(name='labels', acceptsType=self.inputTypeLabels) self.outputSlot = armor.slots.OutputSlot(name='transformed', outputType=self.outputType, useLazyEvaluation=useLazyEvaluation, iterator=armor.weakmethod(self, 'iterator'))
def __init__(self, featureType, useLazyEvaluation=armor.useLazyEvaluation, **kwargs): if featureType in Nowozin.features: self.featureType = featureType else: raise NotImplementedError, "Feature Type %s not implemented" % featureType self.kwargs = kwargs self.useLazyEvaluation = useLazyEvaluation # Define types self.inputType = armor.slots.ImageType(format=["PIL"]) self.outputType = armor.slots.VectorType(shape='nestedarray') # Define slots self.inputSlot = armor.slots.InputSlot(name='Images', acceptsType = self.inputType, useLazyEvaluation=useLazyEvaluation) self.outputSlot = armor.slots.OutputSlot(name='Sift Descriptors', outputType=self.outputType, inputSlot=self.inputSlot, processFunc=armor.weakmethod(self, 'process'), slotType='sequential', useLazyEvaluation=self.useLazyEvaluation)
def __init__(self, useLazyEvaluation=armor.useLazyEvaluation): self.inputSlot = armor.slots.MultiInputSlot(name='data') self.outputSlot = armor.slots.OutputSlot(name='combined data', iterator=armor.weakmethod(self, 'iterator'), useLazyEvaluation=useLazyEvaluation)