Reputation: 1
I'm trying to build a model for plant disease detection using Keras, but I seem to have this error when I tried load my datasets and convert it to an array. The image appears in the error doesn't exist in my datasets, I have no idea why.
EPOCHS = 25
INIT_LR = 1e-3
BS = 32
default_image_size = tuple((256, 256))
image_size = 0
directory_root = "C:\\Users\\vipek\\Desktop\\PlantVillage-Dataset\\raw\\color"
width=256
height=256
depth=3
image_list, label_list = [], []
try:
print("[INFO] Loading images ...")
root_dir = listdir(directory_root)
for directory in root_dir :
# remove .DS_Store from list
if directory == ".DS_Store" :
root_dir.remove(directory)
for plant_folder in root_dir :
plant_disease_folder_list = listdir(f"{directory_root}/{plant_folder}")
for disease_folder in plant_disease_folder_list :
# remove .DS_Store from list
if disease_folder == ".DS_Store" :
plant_disease_folder_list.remove(disease_folder)
for plant_disease_folder in plant_disease_folder_list:
print(f"[INFO] Processing {plant_disease_folder} ...")
plant_disease_image_list = listdir(f"{directory_root}/{plant_folder}/{plant_disease_folder}/")
for single_plant_disease_image in plant_disease_image_list :
if single_plant_disease_image == ".DS_Store" :
plant_disease_image_list.remove(single_plant_disease_image)
for image in plant_disease_image_list[:500]:
image_directory = f"{directory_root}/{plant_folder}/{plant_disease_folder}/{image}"
if image_directory.endswith(".jpg") == True or image_directory.endswith(".JPG") == True:
image_list.append(convert_image_to_array(image_directory))
label_list.append(plant_disease_folder)
print("[INFO] Image loading completed")
except Exception as e:
print(f"Error : {e}")
This is the output i got:
[INFO] Loading images ...
[INFO] Processing 00416648-be6e-4bd4-bc8d-82f43f8a7240___GCREC_Bact.Sp 3110.JPG ...
Error : [WinError 267] The directory name is invalid: 'C:\Users\vipek\Desktop\PlantVillage-Dataset\raw\color/Tomato___Bacterial_spot/00416648-be6e-4bd4-bc8d-82f43f8a7240___GCREC_Bact.Sp 3110.JPG/'
Upvotes: 0
Views: 1134
Reputation: 7591
I suggest you to use the Path
Python 3 library to deal with paths. My guess is that the path is not being recognized correctly. Based on the Path
library I would change a couple of lines in your code, qhere paths are being defined:
# header
from pathlib import Path
# ...
directory_root = Path("C:\\Users\\vipek\\Desktop\\PlantVillage-Dataset\\raw\\color")
# ...
plant_disease_folder_list = listdir(directory_root / plant_folder)
# ...
plant_disease_image_list = listdir(directory_root / plant_folder / plant_disease_folder)
And make sure you avoid the last '/' in the plant_disease_image_list
path!
Upvotes: 0
Reputation: 600
Were you able to load any images at all? I think you get the error because your directory is invalid, meaning your root is defined C:\something\something
and then at some point you switch to folder/folder/folder
. You need to use backslashes only. Also I'm pretty sure your code adds /
after specifying the file type (JPG). That shouldn't be there.
Hope that helps.
Upvotes: 2
Reputation: 1290
I would say that the space in 00416648-be6e-4bd4-bc8d-82f43f8a7240___GCREC_Bact.Sp 3110.JPG
is causing this error
Upvotes: 0