2

hello I am trying to train this model that is used to detect if a person's eye is open or closed. I want to read .jpg images from dataset folder using opencv library in python. The code is

    def load_images(self,dataframe):
    output = np.zeros((len(dataframe),self.image_shape[0],self.image_shape[1]))
    for index,row in dataframe.iterrows():
        img = cv2.imread(row["file_location"].replace(row["file_location"],"home/samuel/Desktop/eye-closed/dataset_B_FacialImages"))
        if img is None:
            print ("Cv2 error: Unable to read from '"+row["file_location"].replace(row["file_location"],"home/samuel/dataset/eye-closed/dataset_B_Eye_Images/closedLeftEyes/*.jpg")+"'")
            continue
        img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
        output[index] = img 
    return output

I is giving me the error

Cv2 error: Unable to read from 'home/samuel/dataset/eye-closed/dataset_B_Eye_Images/closedLeftEyes/*.jpg'

I don't know what is wrong. Can anyone help me with this?

Samuel Mideksa
  • 423
  • 8
  • 19
  • 1
    Well that isn't a valid file path, if you're intending to load all jpgs then you should look at `glob`: see related https://stackoverflow.com/questions/3964681/find-all-files-in-a-directory-with-extension-txt-in-python – EdChum May 01 '18 at 08:51
  • thank you I fixed it by changing the giving the correct directory for the dataset thank you – Samuel Mideksa May 01 '18 at 09:26

1 Answers1

0

There is a pickle file in the dataset i.e a dictionary containing the url for the dataset images. I am able to view it using pandas by using this code.

import pickle as pkl
import pandas as pd
if __name__ == '__main__':
    pkl.HIGHEST_PROTOCOL = 2
    df = pd.read_pickle(r"/home/samuel/dataset/eye-closed/dataset_B_FacialImages/train.pkl")
    print(df)

Which gives the following output

1896  /home/mtk/dataset/eye-closed/dataset_B_FacialI...       0
1897  /home/mtk/dataset/eye-closed/dataset_B_FacialI...       1
1898  /home/mtk/dataset/eye-closed/dataset_B_FacialI...       0
1899  /home/mtk/dataset/eye-closed/dataset_B_FacialI...       1
1900  /home/mtk/dataset/eye-closed/dataset_B_FacialI...       0
1901  /home/mtk/dataset/eye-closed/dataset_B_FacialI...       0
1902  /home/mtk/dataset/eye-closed/dataset_B_FacialI...       0
1903  /home/mtk/dataset/eye-closed/dataset_B_FacialI...       0
1904  /home/mtk/dataset/eye-closed/dataset_B_FacialI...       1
1905  /home/mtk/dataset/eye-closed/dataset_B_FacialI...       1
1906  /home/mtk/dataset/eye-closed/dataset_B_FacialI...       0
1907  /home/mtk/dataset/eye-closed/dataset_B_FacialI...       0
1908  /home/mtk/dataset/eye-closed/dataset_B_FacialI...       0
[1909 rows x 2 columns]

i want to change this pickle file so that the name /home/mtk/... is changed to /home/samuel/... What should I do?

Samuel Mideksa
  • 423
  • 8
  • 19