def _create_essentia_class(name, moduleName = __name__): essentia.log.debug(essentia.EPython, 'Creating essentia.standard class: %s' % name) _algoInstance = _essentia.Algorithm(name) _algoDoc = _algoInstance.getDoc() _algoStruct = _algoInstance.getStruct() del _algoInstance class Algo(_essentia.Algorithm): __doc__ = _algoDoc __struct__ = _algoStruct def __init__(self, **kwargs): # init the internal cpp wrapper _essentia.Algorithm.__init__(self, name) # configure the algorithm self.configure(**kwargs) def configure(self, **kwargs): # verify that all types match and do any necessary conversions for name, val in kwargs.iteritems(): goalType = self.paramType(name) try: convertedVal = _c.convertData(val, goalType) except TypeError: # as e: # catching exception as sth is only #available as from python 2.6 raise TypeError('Error cannot convert parameter %s to %s'\ %(str(_c.determineEdt(val)),str(goalType))) #\''+name+'\' parameter: '+str(e)) kwargs[name] = convertedVal self.__configure__(**kwargs) def compute(self, *args): inputNames = self.inputNames() if len(args) != len(inputNames): raise ValueError(name+'.compute requires '+str(len(inputNames))+' argument(s), '+str(len(args))+' given') # we have to make some exceptions for YamlOutput and PoolAggregator # because they expect cpp Pools if name in ('YamlOutput', 'PoolAggregator', 'SvmClassifier', 'PCA', 'GaiaTransform'): args = (args[0].cppPool,) # verify that all types match and do any necessary conversions result = [] convertedArgs = [] for i in range(len(inputNames)): goalType = _c.Edt(self.inputType(inputNames[i])) try: convertedData = _c.convertData(args[i], goalType) except TypeError: raise TypeError('Error cannot convert argument %s to %s' \ %(str(_c.determineEdt(args[i])), str(goalType))) convertedArgs.append(convertedData) results = self.__compute__(*convertedArgs) # we have to make an exceptional case for YamlInput, because we need # to wrap the Pool that it outputs w/ our python Pool from common.py if name in ('YamlInput', 'PoolAggregator', 'SvmClassifier', 'PCA', 'GaiaTransform', 'Extractor'): return _c.Pool(results) # In the case of MetadataReader, the 7th output is also a Pool if name in ('MetadataReader'): return results[:7] + (_c.Pool(results[7]),) + results[8:] else: return results def __call__(self, *args): return self.compute(*args) def __str__(self): return __doc__ algoClass = _c.algoDecorator(Algo) setattr(_sys.modules[moduleName], name, algoClass) return algoClass
for name, val in kwargs.iteritems(): goalType = self.paramType(name) try: convertedVal = _c.convertData(val, goalType) except TypeError, e: raise TypeError('Error verifying \''+name+'\' parameter: '+str(e)) kwargs[name] = convertedVal # we need to keep a reference to these parameters so that they won't get cleaned up for # the lifetime of this algo self.__pyparams__ = kwargs self.__configure__(**kwargs) algoClass = _c.algoDecorator(StreamingAlgo) setattr(_sys.modules[__name__], givenname, algoClass) # load all streaming algorithms into module def _reloadStreamingAlgorithms(): for name in algorithmNames(): _create_streaming_algo(name) _reloadStreamingAlgorithms() # This subclass provides some more functionality for VectorInput class VectorInput(_essentia.VectorInput): __doc__ = 'VectorInput v1.0\n\n\n'+\ ' Outputs:\n\n'+\ ' [variable] data - the given data\n\n\n'+\
goalType = self.paramType(name) try: convertedVal = _c.convertData(val, goalType) except TypeError, e: raise TypeError('Error verifying \'' + name + '\' parameter: ' + str(e)) kwargs[name] = convertedVal # we need to keep a reference to these parameters so that they won't get cleaned up for # the lifetime of this algo self.__pyparams__ = kwargs self.__configure__(**kwargs) algoClass = _c.algoDecorator(StreamingAlgo) setattr(_sys.modules[__name__], givenname, algoClass) # load all streaming algorithms into module def _reloadStreamingAlgorithms(): for name in algorithmNames(): _create_streaming_algo(name) _reloadStreamingAlgorithms() # This subclass provides some more functionality for VectorInput class VectorInput(_essentia.VectorInput): __doc__ = 'VectorInput v1.0\n\n\n'+\
def _create_essentia_class(name, moduleName = __name__): essentia.log.debug(essentia.EPython, 'Creating essentia.standard class: %s' % name) _algoInstance = _essentia.Algorithm(name) _algoDoc = _algoInstance.getDoc() _algoStruct = _algoInstance.getStruct() del _algoInstance class Algo(_essentia.Algorithm): __doc__ = _algoDoc __struct__ = _algoStruct def __init__(self, **kwargs): # init the internal cpp wrapper _essentia.Algorithm.__init__(self, name) # configure the algorithm self.configure(**kwargs) def configure(self, **kwargs): # verify that all types match and do any necessary conversions for name, val in kwargs.iteritems(): goalType = self.paramType(name) if type(val).__module__ == 'numpy': if not val.flags['C_CONTIGUOUS']: val = copy(val) try: convertedVal = _c.convertData(val, goalType) except TypeError: # as e: # catching exception as sth is only #available as from python 2.6 raise TypeError('Error cannot convert parameter %s to %s'\ %(str(_c.determineEdt(val)),str(goalType))) #\''+name+'\' parameter: '+str(e)) kwargs[name] = convertedVal self.__configure__(**kwargs) def compute(self, *args): inputNames = self.inputNames() if len(args) != len(inputNames): raise ValueError(name+'.compute requires '+str(len(inputNames))+' argument(s), '+str(len(args))+' given') # we have to make some exceptions for YamlOutput and PoolAggregator # because they expect cpp Pools if name in ('YamlOutput', 'PoolAggregator', 'SvmClassifier', 'PCA', 'GaiaTransform'): args = (args[0].cppPool,) # verify that all types match and do any necessary conversions result = [] convertedArgs = [] for i in range(len(inputNames)): arg = args[i] if type(args[i]).__module__ == 'numpy': if not args[i].flags['C_CONTIGUOUS']: arg = copy(args[i]) goalType = _c.Edt(self.inputType(inputNames[i])) try: convertedData = _c.convertData(arg, goalType) except TypeError: raise TypeError('Error cannot convert argument %s to %s' \ %(str(_c.determineEdt(arg)), str(goalType))) convertedArgs.append(convertedData) results = self.__compute__(*convertedArgs) # we have to make an exceptional case for YamlInput, because we need # to wrap the Pool that it outputs w/ our python Pool from common.py if name in ('YamlInput', 'PoolAggregator', 'SvmClassifier', 'PCA', 'GaiaTransform', 'Extractor'): return _c.Pool(results) # MusicExtractor and FreesoundExtractor output two pools if name in ('MusicExtractor', 'FreesoundExtractor'): return (_c.Pool(results[0]), _c.Pool(results[1])) # In the case of MetadataReader, the 7th output is also a Pool if name in ('MetadataReader'): return results[:7] + (_c.Pool(results[7]),) + results[8:] else: return results def __call__(self, *args): return self.compute(*args) def __str__(self): return __doc__ algoClass = _c.algoDecorator(Algo) setattr(_sys.modules[moduleName], name, algoClass) return algoClass