Tonic.Transforms.ToFrame()

Tonic.Transforms.ToFrame()

Tonic是一个方便下载、操作和加载基于事件/基于峰值的数据的工具。它就像PyTorch Vision,但用于神经形态数据!

函数链接

事件相机的数据处理:该博客中介绍了如何对事件数据进行可视化

函数原型:

函数作用:通过一定的方法,将事件流可视化,得到帧

@dataclass(frozen=True)
class ToFrame:
    """Accumulate events to frames by slicing along constant time (time_window), constant number of
    events (spike_count) or constant number of frames (n_time_bins / n_event_bins). All the events
    in one slice are added up in a frame for each polarity. You can set one of the first 4
    parameters to choose the slicing method. Depending on which method you choose, overlap will
    assume different functionality, whether that might be temporal overlap, number of events or
    fraction of a bin. As a rule of thumb, here are some considerations if you are unsure which
    slicing method to choose:
	通过沿着常数时间(时间窗口)、常数数量的事件(峰值计数)或常数数量的帧(n个时间箱/ n个事件箱)将事件累积到帧中。一个切片中的所有事件都被添加到每个极性的帧	   中。您可以设置前4个参数中的一个来选择切片方法。根据您选择的方法,重叠将假设不同的功能,无论是时间重叠、事件数量还是bin的部分。根据经验,如果你不确定     要选择哪种切片方法,这里有一些注意事项

    * If your recordings are of roughly the same length, a safe option is to set time_window. Bare in mind
      that the number of events can vary greatly from slice to slice, but will give you some consistency when
      training RNNs or other algorithms that have time steps.
      如果你的录音长度大致相同,一个安全的选择是设置时间窗口。请记住,不同切片的事件数量可能会有很大差异,但在训练rnn或其他具有时间步长的算法时,会给你一       些一致性。
      方法:利用固定时间窗口。以某一固定时间进行累计得到事件帧。但是不能改善状态差异导致的帧间的信息量差异

    * If your recordings have roughly the same amount of activity / number of events and you are more interested
      in the spatial composition, then setting spike_count will give you frames that are visually more consistent.
      如果您的记录具有大致相同的活动数量/事件数量,并且您对空间构成更感兴趣,那么设置峰值计数将为您提供视觉上更一致的帧
      方法:利用事件数量。以达到某一数量的事件数为阈值,输出一个事件帧

    * The previous time_window and spike_count methods will likely result in a different amount of frames for each
      recording. If your training method benefits from consistent number of frames across a dataset (for easier
      batching for example), or you want a parameter that is easier to set than the exact window length or number
      of events per slice, consider fixing the number of frames by setting n_time_bins or n_event_bins. The two
      methods slightly differ with respect to how the slices are distributed across the recording. You can define
      an overlap between 0 and 1 to provide some robustness.
      之前的时间窗口和峰值计数方法可能会导致每个记录的帧数不同。如果你的训练方法受益于数据集中一致的帧数(例如,为了更容易批处理),或者你想要一个比精确的       窗口长度或每个切片的事件数量更容易设置的参数,请考虑通过设置n个时间箱或n个事件箱来固定帧数。这两种方法在切片如何在记录中分布方面略有不同。可以为pro       定义01之间的重叠
      方法:n个时间箱或n个事件箱来得到固定帧数,利用事件信息数量及事件阈值双限制的方式进行累计得到事件帧。这样产生的事件帧既可以保证高时间分辨率又可以使       事件中具有足够的信息进一步处理

    Parameters:
        sensor_size: a 3-tuple of x,y,p for sensor_size. If omitted, the sensor size is calculated for that sample. However,
                    do use this feature sparingly as when not all pixels fire in a sample, this might cause issues with batching/
                    stacking tensors further down the line.
                    帧的尺寸大小,p表示通道数量
                        
        time_window (float): time window length for one frame. Use the same time unit as timestamps in the event recordings.
                             Good if you want temporal consistency in your training, bad if you need some visual consistency
                             for every frame if the recording's activity is not consistent.
                             一帧的时间窗口长度。在事件记录中使用与时间戳相同的时间单位。如果你想在训练中保持时间一致性,这很好;如果你需要每一帧的视                              觉一致性,如果记录的活动不一致,那就不好了。
                             时间窗口 
                                 
        spike_count (int): number of events per frame. Good for training CNNs which do not care about temporal consistency.
                           每帧的事件数。适合训练不关心时间一致性的cnn
                                 
        n_time_bins (int): fixed number of frames, sliced along time axis. Good for generating a pre-determined number of
                           frames which might help with batching.
                           固定帧数,沿时间轴切片。用于生成预先确定的帧数,这可能有助于批处理。
                           时间箱---得到固定的帧数
                                 
        n_event_bins (int): fixed number of frames, sliced along number of events in the recording. Good for generating a
                            pre-determined number of frames which might help with batching.
                            固定帧数,沿着记录中的事件数切片。用于生成预先确定的帧数,这可能有助于批处理。
                            事件箱
                                 
        overlap (float): overlap between frames defined either in time units, number of events or number of bins between 0 and 1.
        include_incomplete (bool): if True, includes overhang slice when time_window or spike_count is specified.
                                   Not valid for bin_count methods.

    Example:
        >>> from tonic.transforms import ToFrame
        >>> transform1 = ToFrame(time_window=10000, overlap=300, include_incomplete=True)
        >>> transform2 = ToFrame(spike_count=3000, overlap=100, include_incomplete=True)
        >>> transform3 = ToFrame(n_time_bins=100, overlap=0.1)
    """

    sensor_size: Optional[Tuple[int, int, int]]
    time_window: Optional[float] = None
    event_count: Optional[int] = None
    n_time_bins: Optional[int] = None
    n_event_bins: Optional[int] = None
    overlap: float = 0
    include_incomplete: bool = False

    def __call__(self, events):

        return functional.to_frame_numpy(
            events=events,
            sensor_size=self.sensor_size,
            time_window=self.time_window,
            event_count=self.event_count,
            n_time_bins=self.n_time_bins,
            n_event_bins=self.n_event_bins,
            overlap=self.overlap,
            include_incomplete=self.include_incomplete,
        )

image-20230205115223331

猜你喜欢

转载自blog.csdn.net/A2000613/article/details/128924964