]> git.parisson.com Git - timeside.git/commitdiff
Update Irit analyzer to support new package structure
authorThomas Fillon <thomas@parisson.com>
Thu, 15 May 2014 13:34:58 +0000 (15:34 +0200)
committerThomas Fillon <thomas@parisson.com>
Thu, 15 May 2014 13:34:58 +0000 (15:34 +0200)
timeside/analyzer/irit_diverg.py
timeside/analyzer/irit_monopoly.py
timeside/analyzer/irit_music_.py
timeside/analyzer/irit_music_SLN.py
timeside/analyzer/irit_music_SNB.py
timeside/analyzer/irit_noise_startSilences.py

index 2c5487699107d17996cc8ced216419575c8fea14..47c73d7f701fedc07d39368bed4285ca95fcbcf8 100644 (file)
@@ -21,7 +21,7 @@
 
 from timeside.core import implements, interfacedoc
 from timeside.analyzer.core import Analyzer
-from timeside.analyzer import Waveform
+from timeside.analyzer.waveform import Waveform
 from timeside.api import IAnalyzer
 from numpy import spacing
 from collections import deque
@@ -76,7 +76,6 @@ class ModelLongTerm(object):
             self.cor[n] = self.cor[n] + oubli*(self.ftm1[n]*self.et[n]-self.cor[n])
 
             knplus1 = 2*self.cor[n]/(self.variance_f[n] + self.variance_b[n])
-
             self.et[n+1] = self.et[n]-knplus1*self.ftm1[n]
             self.ft[n+1] = self.ftm1[n]-knplus1*self.et[n]
 
index e45ac3f1522e69cb3d81f7699ba1e45304effccc..5850f8070d3b0cd699df758ab316eb68d7d1b176 100644 (file)
@@ -18,6 +18,7 @@
 # along with TimeSide.  If not, see <http://www.gnu.org/licenses/>.
 
 # Author: Maxime Le Coz <lecoz@irit.fr>
+from __future__ import absolute_import
 
 from timeside.analyzer.utils import segmentFromValues
 from timeside.core import Processor, implements, interfacedoc, FixedSizeInputAdapter
@@ -48,7 +49,7 @@ class IRITMonopoly(Analyzer):
         self.block_read = 0
         self.pitches = []
         self.pitch_confidences = []
-                
+
     @staticmethod
     @interfacedoc
     def id():
@@ -79,7 +80,7 @@ class IRITMonopoly(Analyzer):
         '''
 
         '''
-        frameLenModulation = int(self.decisionLen * self.samplerate() / self.blocksize())        
+        frameLenModulation = int(self.decisionLen * self.samplerate() / self.blocksize())
         epsilon = numpy.spacing(self.pitch_confidences[0])
 
         w = int(self.decisionLen * self.samplerate() /(self.blocksize()*2))
@@ -88,19 +89,19 @@ class IRITMonopoly(Analyzer):
             d = self.pitch_confidences[i-w:i+w]
             conf_mean= numpy.mean(d)
             conf_var = numpy.var(d+epsilon)
-            if self.monoLikelihood(conf_mean,conf_var) > self.polyLikelihood(conf_mean,conf_var) : 
+            if self.monoLikelihood(conf_mean,conf_var) > self.polyLikelihood(conf_mean,conf_var) :
                 is_mono += [True]
             else :
                                is_mono += [False]
-                                       
-        conf = self.new_result(data_mode='value', time_mode='framewise')        
+
+        conf = self.new_result(data_mode='value', time_mode='framewise')
         conf = self.new_result(data_mode='value', time_mode='framewise')
         conf.id_metadata.id += '.' + 'yin_confidence'
         conf.id_metadata.name += ' ' + 'Yin Confidence'
         conf.data_object.value = self.pitch_confidences
-        
+
         self.process_pipe.results.add(conf)
-        
+
         convert = {False: 0, True: 1}
         label = {0: 'Poly', 1: 'Mono'}
         segList = segmentFromValues(is_mono)
@@ -110,7 +111,7 @@ class IRITMonopoly(Analyzer):
 
         segs.label_metadata.label = label
 
-        
+
         segs.data_object.label = [convert[s[2]] for s in segList]
         segs.data_object.time = [(float(s[0]) * self.blocksize() /
                                   self.samplerate())
@@ -119,17 +120,17 @@ class IRITMonopoly(Analyzer):
                                   self.samplerate())
                                   for s in segList]
         self.process_pipe.results.add(segs)
-        
+
     def monoLikelihood(self,m,v):
-               
+
         theta1=0.1007;
         theta2=0.0029;
         beta1=0.5955;
         beta2=0.2821;
         delta=0.848;
         return self.weibullLikelihood(m,v,theta1,theta2,beta1,beta2,delta)
-    
-       
+
+
     def polyLikelihood(self,m,v):
         theta1=0.3224;
         theta2=0.0121;
@@ -137,11 +138,11 @@ class IRITMonopoly(Analyzer):
         beta2=0.8705;
         delta=0.644;
         return self.weibullLikelihood(m,v,theta1,theta2,beta1,beta2,delta)
-               
+
     def weibullLikelihood(self,m,v,theta1,theta2,beta1,beta2,delta):
         m = numpy.array(m)
         v= numpy.array(v)
-        
+
         c0=numpy.log(beta1*beta2/(theta1*theta2));
         a1=m/theta1;
         b1=a1**(beta1/delta);
@@ -151,5 +152,5 @@ class IRITMonopoly(Analyzer):
         c2=numpy.log(a2);
         somme1=(b1+b2)**delta;
         Pxy=c0+(beta1/delta-1)*c1+(beta2/delta-1)*c2+(delta-2)*numpy.log(b1+b2)+numpy.log(somme1+1/delta-1)-somme1;
-        
+
         return numpy.mean(Pxy)
index 783bb52104c8d629dea46cf96f8da92b248e3915..699497064f15687a7128dd751d45cadad7dc63fa 100644 (file)
@@ -23,7 +23,7 @@ from timeside.core import implements, interfacedoc
 from timeside.analyzer.core import Analyzer
 from timeside.analyzer.utils import melFilterBank, computeModulation
 from timeside.analyzer.utils import segmentFromValues
-from timeside.analyzer import IRITDiverg
+from timeside.analyzer.irit_diverg import IRITDiverg
 from timeside.api import IAnalyzer
 from numpy import logical_and,array, hamming, dot, mean, float, arange, nonzero
 from numpy.fft import rfft
index ab1e7141952e1eaa1d810be592ab8f0e7db6c2aa..72d90912b34e53e29b4fc8d9916dfcc44f9a1786 100644 (file)
@@ -23,7 +23,7 @@ from timeside.core import implements, interfacedoc
 from timeside.analyzer.core import Analyzer
 from timeside.analyzer.utils import melFilterBank, computeModulation
 from timeside.analyzer.utils import segmentFromValues
-from timeside.analyzer import IRITDiverg
+from timeside.analyzer.irit_diverg import IRITDiverg
 from timeside.api import IAnalyzer
 from numpy import mean, diff, arange
 from timeside.analyzer.preprocessors import frames_adapter
@@ -34,7 +34,7 @@ class IRITMusicSLN(Analyzer):
 
     def __init__(self, blocksize=None, stepsize=None) :
         super(IRITMusicSLN, self).__init__();
-        
+
         self.parents.append(IRITDiverg())
         self.wLen      = 1.0
         self.wStep     = 0.1
@@ -48,7 +48,7 @@ class IRITMusicSLN(Analyzer):
         super(IRITMusicSLN, self).setup(
             channels, samplerate, blocksize, totalframes)
         self.input_blocksize = int(self.wLen * samplerate)
-        self.input_stepsize = int(self.wStep * samplerate)            
+        self.input_stepsize = int(self.wStep * samplerate)
 
     @staticmethod
     @interfacedoc
@@ -67,23 +67,23 @@ class IRITMusicSLN(Analyzer):
 
     def __str__(self):
         return "Music confidence indexes"
-        
+
     @frames_adapter
     def process(self, frames, eod=False):
                return frames,eod
-               
+
     def post_process(self):
         '''
 
         '''
 
         segList = self.process_pipe.results['irit_diverg.segments'].time
-        
+
         w = self.wLen/ 2
         end = segList[-1]
-        
+
         tLine = arange(w,end-w,self.wStep)
-        
+
         #  Les plus petits  ! <> article
         segLen         = [mean(diff(getBoundariesInInterval(t-w, t+w, segList))) for t in tLine]
 
index 98caee3ae9bb23ae6b8e2d3d4f4eb4d83fa5e726..e202e82353a1d97ebf222d815d97447fff6ca6d3 100644 (file)
@@ -23,14 +23,14 @@ from timeside.core import implements, interfacedoc
 from timeside.analyzer.core import Analyzer
 from timeside.analyzer.utils import melFilterBank, computeModulation
 from timeside.analyzer.utils import segmentFromValues
-from timeside.analyzer import IRITDiverg
+from timeside.analyzer.irit_diverg import IRITDiverg
 from timeside.api import IAnalyzer
 from numpy import array, mean, arange, nonzero
 from timeside.analyzer.preprocessors import frames_adapter
 
 
 class IRITMusicSNB(Analyzer):
-    
+
     implements(IAnalyzer)
 
     def __init__(self, blocksize=1024, stepsize=None, samplerate=None) :
@@ -39,7 +39,7 @@ class IRITMusicSNB(Analyzer):
         self.wLen      = 1.0
         self.wStep     = 0.1
         self.input_blocksize = 0;
-        self.input_stepsize = 0;      
+        self.input_stepsize = 0;
         self.threshold = 20
 
     @interfacedoc
@@ -48,8 +48,8 @@ class IRITMusicSNB(Analyzer):
         super(IRITMusicSNB, self).setup(
             channels, samplerate, blocksize, totalframes)
         self.input_blocksize = int(self.wLen * samplerate)
-        self.input_stepsize = int(self.wStep * samplerate)     
-        
+        self.input_stepsize = int(self.wStep * samplerate)
+
     @staticmethod
     @interfacedoc
     def id():
@@ -67,23 +67,23 @@ class IRITMusicSNB(Analyzer):
 
     def __str__(self):
         return "Music confidence indexes"
-        
+
     @frames_adapter
     def process(self, frames, eod=False):
                return frames,eod
-               
+
     def post_process(self):
         '''
 
         '''
-        
-        segList = self.process_pipe.results['irit_diverg.segments'].time  
+
+        segList = self.process_pipe.results['irit_diverg.segments'].time
         w = self.wLen/ 2
         end = segList[-1]
         tLine = arange(0, end, self.wStep)
-        
+
         segNB = [ len(getBoundariesInInterval(t-w,t+w,segList)) for t in tLine ]
-        
+
        # Confidence Index
         conf = [float(v - self.threshold) / float(self.threshold) if v < 2*self.threshold else 1.0 for v in segNB]
         segLenRes = self.new_result(data_mode='value', time_mode='framewise')
index 2128bbc909557689e043db58d123a1ac7317f308..d9442cea3b324dce1d04b4a3d8e602b9bd0cf872 100644 (file)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with TimeSide.  If not, see <http://www.gnu.org/licenses/>.
 # Author: Maxime Le Coz <lecoz@irit.fr>
+from __future__ import absolute_import
+
 
 from timeside.analyzer.utils import segmentFromValues
 from timeside.core import Processor, implements, interfacedoc, FixedSizeInputAdapter
@@ -27,9 +29,9 @@ from aubio import pitch
 import numpy
 from scipy.signal import firwin,lfilter
 from scipy.ndimage.morphology import binary_opening,binary_closing
-import pylab 
+import pylab
+
 
-               
 
 
 class IRITStartSeg(Analyzer):
@@ -43,22 +45,22 @@ class IRITStartSeg(Analyzer):
     @interfacedoc
     def setup(self, channels=None, samplerate=None,
               blocksize=None, totalframes=None):
-                                 
+
         super(IRITStartSeg, self).setup(channels,
                                       samplerate,
                                       blocksize,
                                       totalframes)
         lowFreq = 100.0
-        
+
         self.input_blocksize = int(0.02 * samplerate)
         self.input_stepsize = int(0.008 * samplerate)
-        
-        
+
+
         sr = float(samplerate)
-        highFreq = sr/2 
+        highFreq = sr/2
         f1= lowFreq/sr
-        f2= highFreq/sr   
-        self.filtre = firwin(10, [f1,f2], pass_zero=False)         
+        f2= highFreq/sr
+        self.filtre = firwin(10, [f1,f2], pass_zero=False)
         self.energy = []
         self.maxenergy = 0.002
         self.min_overlap = 20
@@ -66,7 +68,7 @@ class IRITStartSeg(Analyzer):
     @staticmethod
     @interfacedoc
     def id():
-        return "irit_monopoly"
+        return "irit_startseg"
 
     @staticmethod
     @interfacedoc
@@ -80,13 +82,13 @@ class IRITStartSeg(Analyzer):
 
     def __str__(self):
         return "Labeled Monophonic/Polyphonic segments"
-        
+
     @frames_adapter
     def process(self, frames, eod=False):
         '''
 
         '''
-        
+
         self.energy += [numpy.sqrt(numpy.mean(lfilter(self.filtre,1.0,frames.T[0])**2))]
         return frames, eod
 
@@ -94,13 +96,13 @@ class IRITStartSeg(Analyzer):
         '''
 
         '''
-        self.energy = numpy.array(self.energy)/max(self.energy) 
+        self.energy = numpy.array(self.energy)/max(self.energy)
         silences = numpy.zeros((1,len(self.energy)))[0]
-        silences[self.energy<self.maxenergy] = 1  
-        
+        silences[self.energy<self.maxenergy] = 1
+
         step = float(self.input_stepsize) / float(self.samplerate())
-        tL = numpy.arange(len(silences))*step      
-         
+        tL = numpy.arange(len(silences))*step
+
         prototype = numpy.load('timeside/analyzer/protoStart2.dat')
         prototype2 = numpy.load('timeside/analyzer/protoStart3.dat')
         # Lissage pour éliminer les petits segments dans un sens ou l'autre
@@ -115,12 +117,12 @@ class IRITStartSeg(Analyzer):
                 silencesList.append(tuple(seg))
                 seg = [i,-1,v]
         seg[1] = i
-        silencesList.append(tuple(seg)) 
+        silencesList.append(tuple(seg))
         segsList = []
         candidates = []
         l = len(prototype)
         #import pylab
-        for s in silencesList : 
+        for s in silencesList :
                        if s[2] == 1 :
                                shape = numpy.array(self.energy[s[0]:s[1]])
                                #shape = shape/numpy.max(shape)
@@ -128,23 +130,23 @@ class IRITStartSeg(Analyzer):
                                d1,_ = computeDist2(prototype,shape)
                                d2,_ = computeDist2(prototype2,shape)
                                dist = min([d1,d2])
-                               
+
                                candidates.append((s[0],s[1],dist))
                                #pylab.plot(shape)
                                #pylab.plot(range(decal,decal+l),prototype)
                                #pylab.show()
-                               if dist < self.threshold : 
+                               if dist < self.threshold :
                                        segsList.append(s)
-                               
+
         label = {0: 'Start',1:'Session'}
-        with open('out.lab','w') as f : 
-            for s in segsList : 
+        with open('out.lab','w') as f :
+            for s in segsList :
                                f.write('%.2f\t%.2f\t%s\n'%(s[0]*step,s[1]*step,label[s[2]]))
-                               
-        with open('cand.lab','w') as f : 
-            for s in candidates : 
-                               f.write('%.2f\t%.2f\t%f\n'%(s[0]*step,s[1]*step,s[2]))                          
-                               
+
+        with open('cand.lab','w') as f :
+            for s in candidates :
+                               f.write('%.2f\t%.2f\t%f\n'%(s[0]*step,s[1]*step,s[2]))
+
         segs = self.new_result(data_mode='label', time_mode='segment')
         segs.id_metadata.id += '.' + 'segments'
         segs.id_metadata.name += ' ' + 'Segments'
@@ -157,37 +159,37 @@ class IRITStartSeg(Analyzer):
         self.process_pipe.results.add(segs)
 
 
-def computeDist2(proto,serie) : 
+def computeDist2(proto,serie) :
        l = len(proto)
        r=  range(len(serie))
        serie = numpy.array(list(serie)+[0]*(l-1))
        v = [numpy.mean(numpy.abs((serie[i:i+l]/numpy.max(serie[i:i+l]))-proto))for i in r]
        return numpy.min(v),numpy.argmin(v)
-       
+
 def computeDist(v1,v2,min_overlap):
                '''
-               
+
                '''
                m1 = numpy.argmax(v1)
                m2 = numpy.argmax(v2)
                l1 = len(v1)
                l2 = len(v2)
                decal = numpy.abs(m1-m2)
-               
+
                if m1  >= m2 :
                        fin = numpy.min([l1-decal,l2])
                        if fin-decal > min_overlap:
-                               
+
                                v1_out = numpy.array(v1[decal:decal+fin])
                                v2_out = numpy.array(v2[:fin])
                                d = numpy.mean(numpy.abs(v1_out-v2_out))
                        else :
                                v1_out = [0]
                                v2_out = [1]
-                               d = 1 
+                               d = 1
                else :
                        return computeDist(v2, v1,min_overlap)
 
-               
+
                return d,v1_out,v2_out