示例#1
0
文件: vad.py 项目: n-gineer/ELL
    def __init__(self, model):

        if isinstance(model, str):
            if os.path.splitext(model)[1] == ".ell":
                import compute_ell_model as ell
                self.model = ell.ComputeModel(model)
                self.using_map = True
            else:
                import compiled_ell_model as ell
                self.model = ell.CompiledModel(model)
        else:
            import compute_ell_model as ell
            self.model = ell.ComputeModel(model)
            self.using_map = True
示例#2
0
    def __init__(self, model_path, output_window_size):
        """
        Construct a featurizer from the given ELL model.
        The featurizer will ensure it returns an even number of 
        frames to ensure it files the given output_window_size.

        model_path - the path to the ELL compiled model
        output_window_size - the classifier window size
        """

        self.using_map = False
        if os.path.splitext(model_path)[1] == ".ell":
            import compute_ell_model as ell
            self.model = ell.ComputeModel(model_path)
            self.using_map = True
        else:
            import compiled_ell_model as ell
            self.model = ell.CompiledModel(model_path)

        self.logfile = None
        self.output_window_size = output_window_size
        ts = self.model.input_shape
        self.input_shape = (ts.rows, ts.columns, ts.channels)
        ts = self.model.output_shape
        self.output_shape = (ts.rows, ts.columns, ts.channels)
        self.input_size = int(self.model.input_shape.Size())
        self.output_size = int(self.model.output_shape.Size())
        self.frame_count = 0
        self.eof = True
        self.total_time = 0
示例#3
0
    def __init__(self,
                 model_path,
                 categories_file,
                 threshold=0,
                 smoothing_window=0,
                 ignore_list=[]):
        """
        Initialize the new AudioClassifier.
        model - the path to the ELL model module to load.
        categories_file - the path to a text file containing strings labels for each prediction
        threshold - threshold for predictions, (default 0).
        smoothing_window - controls the size of the smoothing window (defaults to 0).
        ignore_list - list of category labels to ignore (like 'background' or 'silence')
        """
        self.smoothing_window = None
        if smoothing_window is not None:
            self.smoothing_window = float(smoothing_window)

        self.threshold = threshold
        self.categories = None

        if isinstance(ignore_list, str):
            self.ignore_list = [x.strip() for x in ignore_list.split(',')]
        elif isinstance(ignore_list, list):
            self.ignore_list = ignore_list
        elif ignore_list is None:
            self.ignore_list = []
        else:
            raise Exception(
                "Expecting ignore list to be a comma separated list or a python list of strings"
            )

        if categories_file:
            with open(categories_file, "r") as fp:
                self.categories = [e.strip() for e in fp.readlines()]

        self.using_map = False
        if os.path.splitext(model_path)[1] == ".ell":
            import compute_ell_model as ell
            self.model = ell.ComputeModel(model_path)
            self.using_map = True
        else:
            import compiled_ell_model as ell
            self.model = ell.CompiledModel(model_path)

        self.logfile = None
        ts = self.model.input_shape
        self.input_shape = (ts.rows, ts.columns, ts.channels)
        ts = self.model.output_shape
        self.output_shape = (ts.rows, ts.columns, ts.channels)
        self.input_size = int(self.model.input_shape.Size())
        self.output_size = int(self.model.output_shape.Size())
        self.smoothing_items = []
        self.total_time = 0
        self.count = 0
示例#4
0
文件: classifier.py 项目: wyuzyf/ELL
    def __init__(self,
                 model_path,
                 categories_file,
                 ignore_list=[],
                 threshold=0,
                 smoothing_delay=0.2):
        """
        Initialize the new AudioClassifier.
        model - the path to the ELL model module to load.
        categories_file - the path to a text file containing strings labels for each prediction
        ignore_list - a list of prediction indices to ignore
        threshold - threshold for predictions, (default 0).
        smoothing_delay - controls the size of this window (defaults to 0.2 seconds).
        """
        self.smoothing_delay = smoothing_delay
        self.ignore_list = ignore_list
        if not self.ignore_list:
            self.ignore_list = []
        self.threshold = threshold
        self.categories = None
        if categories_file:
            with open(categories_file, "r") as fp:
                self.categories = [e.strip() for e in fp.readlines()]

        self.using_map = False
        if os.path.splitext(model_path)[1] == ".ell":
            import compute_ell_model as ell
            self.model = ell.ComputeModel(model_path)
            self.using_map = True
        else:
            import compiled_ell_model as ell
            self.model = ell.CompiledModel(model_path)

        self.logfile = None
        ts = self.model.input_shape
        self.input_shape = (ts.rows, ts.columns, ts.channels)
        ts = self.model.output_shape
        self.output_shape = (ts.rows, ts.columns, ts.channels)
        self.input_size = int(self.model.input_shape.Size())
        self.output_size = int(self.model.output_shape.Size())
        self.items = []
        self.start_time = None
        self.total_time = 0
        self.count = 0
示例#5
0
    def __init__(self, model_path, output_window_size):
        """
        Construct a featurizer from the given ELL model.
        The featurizer will ensure it returns an even number of
        frames to ensure it files the given output_window_size.

        model_path - the path to the ELL compiled model
        output_window_size - the classifier window size
        """
        self.using_map = False
        if os.path.splitext(model_path)[1] == ".ell":
            import compute_ell_model as ell
            self.model = ell.ComputeModel(model_path)
            self.using_map = True
        else:
            import compiled_ell_model as ell
            self.model = ell.CompiledModel(model_path)

        self.logfile = None
        self.output_window_size = output_window_size
        ts = self.model.input_shape
        self.input_shape = (ts.rows, ts.columns, ts.channels)
        ts = self.model.output_shape
        self.output_shape = (ts.rows, ts.columns, ts.channels)
        self.input_size = int(self.model.input_shape.Size())
        self.output_size = int(self.model.output_shape.Size())

        # if the featurizer is buffering input internally, then we need
        # to "prime" the input to that buffer until the buffer is full
        # so we don't return featurized "zeros" because the buffer not yet full.
        self.drop_frames = 0
        value = self.get_metadata("window_size")
        if value:
            buffer_size = int(value)
            self.drop_frames = int(buffer_size / self.input_size)
        self.dropped = 0
        self.reset()