I'm training Neural Network with ImageNet dataset and I noticed that images are in BGR color format when I read them using OpenCV function cv2.imread()
, so does is affect training accuracy?, if yes then how can I change it to RGB in pytorch?
It will not affect your NN's accuracy, in general. However, if you are using a pre-trained CNN, then it likely expects RGB images as input, and will not do as well on BGR images initially and will have to re-learn its weights for BGR.
You can convert BGR to RGB using cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
.
You can also consider the following alternatives for reading images:
torchvision.io.read_image(path)
(https://pytorch.org/vision/stable/io.html#image)torch.from_numpy(np.array(PIL.Image.open(path)))
torchvision.transforms.functional.pil_to_tensor(PIL.Image.open(path))
(https://pytorch.org/vision/stable/transforms.html#torchvision.transforms.functional.pil_to_tensor)