If you want to transform your images using torchvision.transforms, they should be read by using PIL and not opencv.
However Opencv is faster, so you need to create your own functions to transform your images if you want to use opencv.
Hi, There exist a drop-in library https://github.com/uploadcare/pillow-simd which speeds up Pillow 4-6 times. I would recommend to use it instead of rewriting torchvision for opencv.
Anyway, as comment for the OP, Compose works with any function, if during the transformation chain you cast your data to numpy you may use whatever you want.
i did read images using opencv, then i had to make my own transform functions. Then i used transforms.ToTensor() It worked pretty well for me. thanks again !!!