yolov5 icon indicating copy to clipboard operation
yolov5 copied to clipboard

A minor query about the image channel number check using `im.shape[0] < 5`

Open Le0v1n opened this issue 9 months ago • 1 comments

Search before asking

  • [X] I have searched the YOLOv5 issues and discussions and found no similar questions.

Question

Today, I attempted to observe the operation process of YOLOv5 step by step. While reviewing the check_amp(model) function, I had some minor doubts. The specific code is in the AutoShape class within the forward method of the models/common.py file:

for i, im in enumerate(ims):
	f = f"image{i}"  # filename
	if isinstance(im, (str, Path)):  # filename or uri
		im, f = Image.open(requests.get(im, stream=True).raw if str(im).startswith("http") else im), im
		im = np.asarray(exif_transpose(im))  
	elif isinstance(im, Image.Image):  # PIL Image
		im, f = np.asarray(exif_transpose(im)), getattr(im, "filename", f) or f
	files.append(Path(f).with_suffix(".jpg").name)
	if im.shape[0] < 5:  # 💡💡💡  image in CHW
		im = im.transpose((1, 2, 0))  # reverse dataloader .transpose(2, 0, 1)

I reviewed the code using debug mode, with the IDE being VSCode, and the DEBUG command as follows:

        {
            "name": "Debug train.py",
            "type": "debugpy",
            "request": "launch",
            "program": "train.py",
            "console": "integratedTerminal",
            "python": "/root/anaconda3/envs/yolo/bin/python",
            "args": [
                "--data", "data/coco128.yaml",
                "--cfg", "models/yolov5s.yaml",
                "--hyp", "data/hyps/hyp.scratch-low.yaml",
                "--weights", "yolov5s.pt",
                "--batch-size", "2",
                "--epochs", "200",
            ]
        }

In this process, the image used is '../yolov5/data/images/bus.jpg' (which is the default), and I'm not sure about the purpose of the code annotated with 💡. The shape of the image im at this time is (1080, 810, 3), so the result of im.shape[0] < 5 is False. I'm not sure if your team members wanted to check the number of channels when writing the code, but I would still be very confused even if it was changed to im.shape[-1] < 5. In my opinion, the code should be im.shape[0] <= 3.

I'm a bit unsure about your original intention here. If you have time, could you please answer my question? Thank you very much! 🤗

Additional

This is not urgent; I hope it doesn't interrupt your regular work. 🥰

Le0v1n avatar May 20 '24 12:05 Le0v1n