I wrote the following code:
import os import cv2 import random from pathlib import Path path = Path(__file__).parent path = \"../img_folder\" for f in path.iter
It is because of a hidden file in your directory. If you are sure your directory contains only images, you can ignore hidden files/folders like below.
use
for f in path.iterdir(): if not f.startswith('.'): f = str(f) img=cv2.imread(f) im_height = img.shape[0] im_width = img.shape[1]