def frame_results_to_events(frame_results, frame_times=None):
    """
    Converting frame-by-frame results into a list of events for each label. If the classifier predicts the same label in a sequence it is considers as an event. (Filtering too short events, or merge close-by events is not included here.)

    Arguments:
        frame_results (list or numpy array): list of frame class labels in an temporal order (sequential). It can contain numeric or string values e.g. ``[1, 1, 0, ...]`` or ``['class_1', 'class_1', 'class_0', ...]``
        frame_times (list or numpy array): list of timestamps (preferably as numeric values e.g. posix time) for each frame.

    Returns:
        dictionary: list of events (tuple of start and end times/indexes) for each unique label found in the frame_results. Event start value is the first occurence of the label, event end is the time or index of the next frame after the event (also the start of the next event).
    """
    if len(frame_results) < 2:
        raise ValueError('frame_results has to contain at least 2 items.')
    if frame_times is not None and len(frame_results) != len(frame_times):
        raise ValueError(
            'Length of frame_results and frame_times has to be equal.')
    unique_labels = set(frame_results)
    results = {}
    for l in unique_labels:
        results[str(l)] = []
    event_label = frame_results[0]
    event_start_index = 0
    for index in range(1, len(frame_results)):
        if frame_results[index] != event_label:
            if frame_times is None:
                results[str(event_label)].append((event_start_index, index))
            else:
                results[str(event_label)].append((frame_times[
                    event_start_index], frame_times[index]))
            event_label = frame_results[index]
            event_start_index = index
    if frame_times is None:
        results[str(event_label)].append((event_start_index, index + 1))
    else:
        results[str(event_label)].append((frame_times[event_start_index], 
            frame_times[-1] + float(frame_times[-1] - frame_times[0]) / (
            len(frame_times) - 1)))
    return results
