Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/python3 #15

Merged
merged 16 commits into from
Oct 25, 2015
Merged
Prev Previous commit
Next Next commit
fix abstract base classes
Sebastian Böck committed Oct 21, 2015
commit 95778dbf7fde964b1093e87f345989747fd3869f
23 changes: 13 additions & 10 deletions madmom/evaluation/__init__.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@

from __future__ import absolute_import, division, print_function

import abc
import numpy as np


@@ -143,9 +142,12 @@ def calc_relative_errors(detections, annotations, matches=None):


# abstract evaluation base class
class EvaluationABC(object):
class EvaluationMixin(object):
"""
Evaluation abstract base class.
Evaluation mixin class.

This class has a `name` attribute which is used for display purposes and
defaults to 'None'.

`METRIC_NAMES` is a list of tuples, containing the attribute's name and the
corresponding label, e.g.:
@@ -157,10 +159,12 @@ class EvaluationABC(object):
]

The attributes defined in `METRIC_NAMES` will be provided as an ordered
dictionary as the `metrics` attribute of the
dictionary as the `metrics` property unless the subclass overwrites the
property.

`FLOAT_FORMAT` is used to format floats.

"""
__metaclass__ = abc.ABCMeta

name = None
METRIC_NAMES = []
@@ -177,10 +181,9 @@ def metrics(self):
metrics[metric] = getattr(self, metric)
return metrics

@abc.abstractmethod
def __len__(self):
"""Length of the evaluation object."""
return
raise NotImplementedError('must be implemented by subclass.')

def tostring(self, **kwargs):
"""
@@ -190,8 +193,8 @@ def tostring(self, **kwargs):
:return: evaluation metrics formatted as a human readable string

Note: This is a fallback method formatting the 'metrics' dictionary in
a human readable way. Classes implementing this abstract base
class should provide a better suitable method.
a human readable way. Classes inheriting from this mixin class
should provide a method better suitable.

"""
# pylint: disable=unused-argument
@@ -201,7 +204,7 @@ class should provide a better suitable method.


# evaluation classes
class SimpleEvaluation(EvaluationABC):
class SimpleEvaluation(EvaluationMixin):
"""
Simple Precision, Recall, F-measure and Accuracy evaluation based on the
numbers of true/false positive/negative detections.
4 changes: 2 additions & 2 deletions madmom/evaluation/alignment.py
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@

import numpy as np

from . import EvaluationABC
from . import EvaluationMixin


# constants for the data format
@@ -203,7 +203,7 @@ def compute_metrics(event_alignment, ground_truth, window, err_hist_bins):
return results


class AlignmentEvaluation(EvaluationABC):
class AlignmentEvaluation(EvaluationMixin):
"""
Alignment evaluation class for beat-level alignments. Beat-level aligners
output beat positions for points in time, rather than computing a time step
4 changes: 2 additions & 2 deletions madmom/evaluation/tempo.py
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
import warnings
import numpy as np

from . import EvaluationABC, MeanEvaluation, evaluation_io
from . import EvaluationMixin, MeanEvaluation, evaluation_io


def load_tempo(values, split_value=1., sort=False, norm_strengths=False,
@@ -159,7 +159,7 @@ def tempo_evaluation(detections, annotations, tolerance=TOLERANCE):


# basic tempo evaluation
class TempoEvaluation(EvaluationABC):
class TempoEvaluation(EvaluationMixin):
"""
Tempo evaluation class.

5 changes: 1 addition & 4 deletions madmom/ml/hmm.pyx
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@ If you want to change this module and use it interactively, use pyximport.

from __future__ import absolute_import, division, print_function

import abc
import numpy as np
cimport numpy as np
cimport cython
@@ -144,7 +143,6 @@ class ObservationModel(object):
different observation probability (log) densities. Type must be np.float.

"""
__metaclass__ = abc.ABCMeta

def __init__(self, pointers):
"""
@@ -156,7 +154,6 @@ class ObservationModel(object):

self.pointers = pointers

@abc.abstractmethod
def log_densities(self, observations):
"""
Log densities (or probabilities) of the observations for each state.
@@ -168,7 +165,7 @@ class ObservationModel(object):
observation log probability densities. The type
must be np.float.
"""
return
raise NotImplementedError('must be implemented by subclass')

def densities(self, observations):
"""
26 changes: 3 additions & 23 deletions madmom/ml/rnn.py
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@

from __future__ import absolute_import, division, print_function

import abc
import numpy as np

from ..processors import Processor, ParallelProcessor
@@ -129,26 +128,7 @@ def softmax(x, out=None):


# network layer classes
class Layer(object):
"""
Generic network Layer.

"""
__metaclass__ = abc.ABCMeta

@abc.abstractmethod
def activate(self, data):
"""
Activate the layer.

:param data: activate with this data
:return: activations for this data

"""
return


class FeedForwardLayer(Layer):
class FeedForwardLayer(object):
"""
Feed-forward network layer.

@@ -230,7 +210,7 @@ def activate(self, data):
return out


class BidirectionalLayer(Layer):
class BidirectionalLayer(object):
"""
Bidirectional network layer.

@@ -340,7 +320,7 @@ def __init__(self, weights, bias, recurrent_weights, peephole_weights,
self.peephole_weights = peephole_weights.flatten()


class LSTMLayer(Layer):
class LSTMLayer(object):
"""
Recurrent network layer with Long Short-Term Memory units.

9 changes: 2 additions & 7 deletions madmom/processors.py
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@

import os
import sys
import abc
import argparse
import multiprocessing as mp

@@ -27,7 +26,6 @@ class Processor(object):
Abstract base class for processing data.

"""
__metaclass__ = abc.ABCMeta

@classmethod
def load(cls, infile):
@@ -73,7 +71,6 @@ def dump(self, outfile):
pickle.dump(self, open(outfile, 'wb'),
protocol=pickle.HIGHEST_PROTOCOL)

@abc.abstractmethod
def process(self, data):
"""
Process the data.
@@ -85,7 +82,7 @@ def process(self, data):
:return: processed data

"""
return data
raise NotImplementedError('must be implemented by subclass.')

def __call__(self, *args):
"""This magic method makes a Processor instance callable."""
@@ -98,7 +95,6 @@ class OutputProcessor(Processor):

"""

@abc.abstractmethod
def process(self, data, output):
"""
Processes the data and feeds it to output.
@@ -110,8 +106,7 @@ def process(self, data, output):
"""
# pylint: disable=arguments-differ

# also return the data
return data
raise NotImplementedError('must be implemented by subclass.')


# functions for processing file(s) with a Processor