The code below only sees photos with jpg extension. How should I change the syntax to include photos in png,jpg,jpeg format
image_df_train_f = pd.DataFrame({'path': list(Path(input_path).glob('**/*.jp*g'))})
you can simply add more addition to the DF
image_df_train_f = pd.DataFrame({'path': list(Path(input_path).glob('**/*.jpg'))+list(Path(input_path).glob('**/*.png'))+list(Path(input_path).glob('**/*.jpeg'))})
This will solve your problem
or ====================
shpfiles = []
for dirpath, subdirs, files in os.walk(path):
for x in files:
if x.split('.')[-1] in ["shp","pdf","txt"]:
shpfiles.append(os.path.join(dirpath, x))
To list files with different extensions, you can use glob like this:
EXTENSIONS = (".png", ".jpg", ".jpeg")
path = [p.resolve()
for p in Path(input_path).glob("**/*")
if p.suffix in EXTENSIONS]
image_df_train_f = pd.DataFrame({'path': path})
Be aware that the solution you provided in the comments, while concise, may list unnecessary files, so you should not use it.
image_df_train_f = pd.DataFrame({'path': list(Path(input_path).glob("*.[jp][pn]g"))})
While it does list files with .jpg
and .png
(without .jpeg
, by the way) extensions, it also includes .jng
and .ppg
files it locates in the directory.