Skip to content

Question about temporal dimension reversal in "Format._format_img" for Gen1 4D ".npy" inputs #80

Description

@aaddaamm12

Hi SpikeYOLO authors,

First, thank you for releasing the SpikeYOLO code and the Gen1-specific implementation. I am currently fine-tuning the Gen1 checkpoint on my own Prophesee neuromorphic dataset and I have a question about the image formatting pipeline for temporal ".npy" inputs.

In "SpikeYOLO_for_Gen1/ultralytics/data/augment.py", inside "Format._format_img", the current code is:

if len(img.shape) == 4:
     img = np.ascontiguousarray(img.transpose(0, 3, 1, 2)[::-1]) # 改为Tchw模式
else:
     img = np.ascontiguousarray(img.transpose(2, 0, 1)[::-1]) # 改为chw模式

For a standard OpenCV image in "HWC" format, I understand that: img.transpose(2, 0, 1)[::-1] converts "HWC -> CHW" and reverses the channel order, typically "BGR -> RGB".
However, for a temporal ".npy" input with shape:

[T, H, W, C]

the operation:

img.transpose(0, 3, 1, 2)[::-1]

first converts the image to:

[T, C, H, W]

but then "[::-1]" seems to reverse the first axis, which is now the temporal axis "T", not the
channel axis "C".

So, for example, with "T=2", this changes the temporal order from:

frame_0, frame_1

to:

frame_1, frame_0

Is what I am describing true or I am wrong?

If I'm right, my question is: Is this reversal of the temporal dimension intentional for the Gen1 model/checkpoint, or is it an inherited BGR-to-RGB operation from the original YOLO image pipeline?

I noticed this because my dataset is stored as ".npy" files with shape:

[T, W, H, C]

which is then converted by the loader BaseDataset.load_image to:

[T, H, W, C]

and then in Format._format_img, it is converted to

[T, C, H, W]

and I annotate the last temporal frame. When visualizing "train_batch0.png" during training, the displayed frame seemed to correspond to the first original frame rather than the last one. This raised a question for me. First, is the frame displayed in train_batch0.png only a debug visualization choice made by plot_images, or does it reflect the exact temporal order of the tensor that is also fed to the model during training and validation? In other words, if train_batch0.png shows the labels on the first original frame instead of the last annotated frame, should I interpret this as only a visualization issue, or as evidence that the model is also receiving the temporal frames in that reversed order?

After removing "[::-1]" from if len(img.shape) == 4:;img = np.ascontiguousarray(img.transpose(0, 3, 1, 2)[::-1]) # 改为Tchw模式 the visualization matched the expected annotated frame.

However, when fine-tuning from the released Gen1 checkpoint, I am not sure whether the checkpoint itself was trained with the original temporal reversal behavior. So I would like to know which behavior should be considered correct for fine-tuning the official Gen1 checkpoint:

  1. Keep the current code because the Gen1 checkpoint was trained with this temporal
    reversal.
  2. Remove "[::-1]" for temporal ".npy" inputs because reversing "T" is unintended.

Could you please clarify the intended behavior?

Thank you very much for your help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions