jiweibo / AU_Recognition

AU_Recognition based on CKPlus/CK database
GNU General Public License v3.0
23 stars 9 forks source link

NotADirectoryError: [WinError 267] The directory name is invalid #1

Closed sarmadm closed 4 years ago

sarmadm commented 5 years ago

Hi

Why is showing this error
NotADirectoryError: [WinError 267] The directory name is invalid: 'C:/Users/sarmad/Documents/CK/extended-cohn-kanade-images/FACS_labels\\S069_001_00000018_facs.txt'

jiweibo commented 5 years ago

Make sure that you have already downloaded the CK+ dataset in this directory 'C:/Users/sarmad/Documents/CK/extended-cohn-kanade-images/FACS_labels\S069_001_00000018_facs.txt'

sarmadm commented 5 years ago

I have downloaded all required data :

data_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/cohn-kanade-images' label_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/FACS_labels' landmark_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/Landmarks'

it shows this error :

NotADirectoryError: [WinError 267] The directory name is invalid: 'C:/Users/sarmad/Documents/deep_L_projects/AU/FACS_labels\\S068_005_00000021_facs.txt'

jiweibo commented 5 years ago

It seems that your directory has problem. try r'c:/users/sarmad/documents/deep_L_projects/AU/FACS_labels/S068_005_00000021_facs.txt' or 'c:\users\sarmad\documents\deep_L_projects\AU\FACS_labels\S068_005_00000021_facs.txt'

sarmadm commented 5 years ago

This is the command line :

python main.py C:/Users/sarmad/Documents/deep_L_projects/AU/cohn-kanade-images C:/Users/sarmad/Documents/deep_L_projects/AU/FACS_labels C:/Users/sarmad/Documents/deep_L_projects/AU/Landmarks --model alexnet --epochs 100 -b 16 --step 10

But showing same error ?

how can I resolve ? can I add the paths manually in main.py ?

jiweibo commented 5 years ago

I have found why you occur this error. The path is invalid. My CK+ directory structure is as follows:

CKPlus --cohn-kanade-images ----S005 ------001 --------S005_001_00000001.png --------... ----...

--Emotion_labels ----Emotion ------S005 --------001 ----------S005_001_00000011_emotion.txt ------...

--FACS_labels ----FACS ------S005 --------001 ----------S005_001_00000011_facs.txt

It seems that your valid path should be C:/Users/sarmad/Documents/deep_L_projects/AU/FACS_labels/FACS/S068/005\S068_005_00000021_facs.txt

But I didn't find why you occur this error. Maybe you should trace au_data_loader.py to determine the wrong location. It's a pleasure to solve this problem with you.

The environment I use is: Windows10 pro Python3.5 Pytorch0.4 etc.

Pytorch1.0 will be supported soon.

sarmadm commented 5 years ago

HI

Thanks for replying . I used checked folder structure and it is the same you sent . I tiried below command : (keras_v) C:\Users\sarmad\Documents\deep_L_projects\AU>python main.py C:/Users/sarmad/Documents/deep_L_projects/AU/cohn-kanade-images/ C:/Users/sarmad/Documents/deep_L_projects/AU/FACS_labels/FACS/ C:/Users/sarmad/Documents/deep_L_projects/AU/Landmarks/ --model alexnet --epochs 100 -b 16 --step 10

It shows this error which I don't know what it is m, I checked there is no thumbs.df file in the folders

C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\sklearn\externals\joblib\externals\cloudpickle\cloudpickle.py:47: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses import imp Traceback (most recent call last): File "main.py", line 341, in <module> main() File "main.py", line 157, in main au_image = load_au_image_from_path(data_path_dir) File "C:\Users\sarmad\Documents\deep_L_projects\AU\au_data_loader.py", line 94, in load_au_image_from_path Image.open(os.path.join(sequence, os.listdir(sequence)[-1])).convert('RGB')) File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\PIL\Image.py", line 2657, in open % (filename if filename else fp)) OSError: cannot identify image file 'C:/Users/sarmad/Documents/deep_L_projects/AU/cohn-kanade-images/S005\\001\\Thumbs.db'

jiweibo commented 5 years ago

The error occurs that Image.open(img_path), the input is not a image path but a strange Thumbs.db.

The CK+ dataset doesn't have the Thumbs.db. It's very strange.

To fix your problem, you should add file type checking code. In this file au_data_loader.py, you can modify load_au_image_from_path function

def load_au_image_from_path(data_path_dir):
    # prepare au image
    au_image = []
    for names in os.listdir(data_path_dir):
        name = os.path.join(data_path_dir, names)
        for sequences in os.listdir(name):
            sequence = os.path.join(name, sequences)
            if os.path.isdir(sequence):
                if os.listdir(sequence):
                    if not os.listdir(sequence)[-1].endswith('.png'): # if the file is not image then skip
                        continue
                    au_image.append(
                        Image.open(os.path.join(sequence, os.listdir(sequence)[-1])).convert('RGB'))
    return au_image

Hope to help you!

sarmadm commented 5 years ago

Hi , Thanks very much for your help . now there is another error message :

import imp Traceback (most recent call last): File "main.py", line 341, in <module> main() File "main.py", line 161, in main au_image[i] = np.array(crop_au_img(au_image[i], au_landmark[i])) IndexError: list index out of range

jiweibo commented 5 years ago

Try this

def load_au_image_from_path(data_path_dir):
    # prepare au image
    au_image = []
    for names in os.listdir(data_path_dir):
        name = os.path.join(data_path_dir, names)
        for sequences in os.listdir(name):
            sequence = os.path.join(name, sequences)
            if os.path.isdir(sequence):
                if os.listdir(sequence):
                    idx = len(os.listdir(sequence))-1
                    while not os.listdir(sequence)[idx].endswith('.png'):
                        idx -= 1
                    au_image.append(
                        Image.open(os.path.join(sequence, os.listdir(sequence)[idx])).convert('RGB'))
    return au_image

It seems that in your directory 'C:/Users/sarmad/Documents/deep_L_projects/AU/cohn-kanade-images/S005\001', Thumbs.db or else none image file exists. We add a while statement to detect which is the last image file that we will use as our's dataset.

sarmadm commented 5 years ago

Hi , I really appreciate your help.

It seems to be reoslved , but now I got this error :

Traceback (most recent call last): File "main.py", line 340, in <module> main() File "main.py", line 165, in main model, criterion, optimizer = build_model() File "main.py", line 245, in build_model model = alexnet(pretrained=pretrained) File "C:\Users\sarmad\Documents\deep_L_projects\AU\Model\alexnet.py", line 379, in alexnet model_param = torch.load(model_path) File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\serialization.py", line 356, in load f = open(f, 'rb') FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\sarmad/.torch\\models\\alexnet-owt-4df8aa71.pth

jiweibo commented 5 years ago

Now building CK+ dataset finished.

You need to load DeepLearning architecture such as AlexNet model to implement transfer learning.

Now you should download alexnet model (https://download.pytorch.org/models/alexnet-owt-4df8aa71.pth) in C:\Users\sarmad.torch\models\alexnet-owt-4df8aa71.pth or ~/.torch/models/....

You can read ../Model/alexnet.py for more details.

The same as other models

sarmadm commented 5 years ago

Hi

I didn't find these folders : C:\Users\sarmad.torch\models\alexnet-owt-4df8aa71.pth or
~/.torch/models/....

How did you install torch ? im using anaconda , win10

jiweibo commented 5 years ago

You need to install pytorch 0.4, you can visit pytorch offical website for more details. After that, you should download the deep learning model in ~/.torch/models directory.

sarmadm commented 5 years ago

HI

I think the problem is here :

torch_home = os.path.expanduser(os.getenv('TORCH_HOME', '~/.torch')) model_dir = os.getenv('TORCH_MODEL_ZOO', os.path.join(torch_home, 'models'))

Do I need to change home folder to C:\Users\sarmad\Anaconda3\envs\keras_v\Lib\site-packages\torchvision\models

and download the .pth file and put it in this folder with alexnet.py ?

sarmadm commented 5 years ago

I put the .pth file in that folder above and it showed this error :

Traceback (most recent call last): File "main.py", line 340, in <module> main() File "main.py", line 165, in main model, criterion, optimizer = build_model() File "main.py", line 262, in build_model model.cuda() File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\nn\modules\module.py", line 216, in cuda return self._apply(lambda t: t.cuda(device)) File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\nn\modules\module.py", line 146, in _apply module._apply(fn) File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\nn\modules\module.py", line 146, in _apply module._apply(fn) File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\nn\modules\module.py", line 152, in _apply param.data = fn(param.data) File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\nn\modules\module.py", line 216, in <lambda> return self._apply(lambda t: t.cuda(device)) File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\_utils.py", line 69, in _cuda return new_type(self.size()).copy_(self, async) File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\cuda\__init__.py", line 403, in _lazy_new _lazy_init() File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\cuda\__init__.py", line 160, in _lazy_init _check_driver() File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\cuda\__init__.py", line 74, in _check_driver raise AssertionError("Torch not compiled with CUDA enabled") AssertionError: Torch not compiled with CUDA enabled

jiweibo commented 5 years ago

HI

I think the problem is here :

torch_home = os.path.expanduser(os.getenv('TORCH_HOME', '~/.torch')) model_dir = os.getenv('TORCH_MODEL_ZOO', os.path.join(torch_home, 'models'))

Do I need to change home folder to C:\Users\sarmad\Anaconda3\envs\keras_v\Lib\site-packages\torchvision\models

and download the .pth file and put it in this folder with alexnet.py ?

Of course. You are right!

jiweibo commented 5 years ago

I put the .pth file in that folder above and it showed this error :

Traceback (most recent call last): File "main.py", line 340, in <module> main() File "main.py", line 165, in main model, criterion, optimizer = build_model() File "main.py", line 262, in build_model model.cuda() File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\nn\modules\module.py", line 216, in cuda return self._apply(lambda t: t.cuda(device)) File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\nn\modules\module.py", line 146, in _apply module._apply(fn) File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\nn\modules\module.py", line 146, in _apply module._apply(fn) File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\nn\modules\module.py", line 152, in _apply param.data = fn(param.data) File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\nn\modules\module.py", line 216, in <lambda> return self._apply(lambda t: t.cuda(device)) File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\_utils.py", line 69, in _cuda return new_type(self.size()).copy_(self, async) File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\cuda\__init__.py", line 403, in _lazy_new _lazy_init() File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\cuda\__init__.py", line 160, in _lazy_init _check_driver() File "C:\Users\sarmad\Anaconda3\envs\keras_v\lib\site-packages\torch\cuda\__init__.py", line 74, in _check_driver raise AssertionError("Torch not compiled with CUDA enabled") AssertionError: Torch not compiled with CUDA enabled

Emmm....  I use CUDA (GPU) to accelerate the training process, unfortunately I don't give a None-CUDA (CPU) version. Maybe you can modify this project a little to run in CPU Version.

But run this project on CPU is very slow, maybe 10 hours more time

sarmadm commented 5 years ago

Thanks for replying , but what should be changed for cpu version ?

jiweibo commented 5 years ago

Maybe try remove all the tensor.cuda() such as input.cuda() target.cuda() etc. But I am not sure whether It works or not

vaishnavi-2901 commented 5 years ago

hey, I wrote the code for saving the cropped images, on executing the code, the camera is opened and it is showing some unknown errors and not responding thing is appearing. how to remove this error?

creating the dataset

import cv2, sys, os size= 4 fn_haar='C:\opencv\build\etc\haarcascades\haarcascade_frontalface_default.xml' fn_dir= 'C:\Users\hp\face_data' #all the faces data will be present in the data fn_name= sys.argv[0] path = os.path.join(fn_dir, fn_name)

images of pixels 112X929

(im_width, im_height)= (112, 92) haar_cascade= cv2.CascadeClassifier(fn_haar) webcam = cv2.VideoCapture(0)

The program loops until it has 30 images of the face.

count = 0 while count < 30: (rval, im) = webcam.read() im = cv2.flip(im, 1, 0) gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) mini = cv2.resize(im, (int(im.shape[1]/size), int(im.shape[0]/size))) faces = haar_cascade.detectMultiScale(mini) faces = sorted(faces, key=lambda x: x[3]) if faces: face_i = faces[0] (x, y, w, h) = [v * size for v in face_i] face = gray[y:y + h, x:x + w] face_resize = cv2.resize(face, (im_width, im_height)) pin=sorted([int(n[:n.find('.')]) for n in os.listdir(path) if n[0]!='.' ]+[0])[-1] + 1 cv2.imwrite('%s/%s.jpg' % (path, pin), face_resize) cv2.rectangle(im, (x, y), (x + w, y + h), (0, 255, 0), 3)

cv2.putText(im, fn_name, (x - 10, y - 10), cv2.FONT_HERSHEY_PLAIN,

    #    1,(0, 255, 0))
   font= cv2.FONT_HERSHEY_PLAIN
   cv2.putText(im, fn_name,(x+w,y), font, 1, (0,0,255), 2)
   count += 1

cv2.imshow('OpenCV', im)
key = cv2.waitKey(10)
if key == 27:
  break
selfcontrol7 commented 4 years ago

I have downloaded all required data :

data_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/cohn-kanade-images' label_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/FACS_labels' landmark_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/Landmarks'

it shows this error :

NotADirectoryError: [WinError 267] The directory name is invalid: 'C:/Users/sarmad/Documents/deep_L_projects/AU/FACS_labels\\S068_005_00000021_facs.txt'

Hello,

here we are in 2019 and I am trying to test this code. Please where can I download the required folders data_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/cohn-kanade-images' label_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/FACS_labels' landmark_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/Landmarks'

Thank you.

jiweibo commented 4 years ago

I have downloaded all required data : data_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/cohn-kanade-images' label_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/FACS_labels' landmark_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/Landmarks' it shows this error : NotADirectoryError: [WinError 267] The directory name is invalid: 'C:/Users/sarmad/Documents/deep_L_projects/AU/FACS_labels\\S068_005_00000021_facs.txt'

Hello,

here we are in 2019 and I am trying to test this code. Please where can I download the required folders data_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/cohn-kanade-images' label_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/FACS_labels' landmark_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/Landmarks'

Thank you.

google search ck and ck+ database (Cohn-Kanade AU-Coded Expression Database)

http://www.pitt.edu/~emotion/ck-spread.htm

selfcontrol7 commented 4 years ago

I have downloaded all required data : data_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/cohn-kanade-images' label_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/FACS_labels' landmark_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/Landmarks' it shows this error : NotADirectoryError: [WinError 267] The directory name is invalid: 'C:/Users/sarmad/Documents/deep_L_projects/AU/FACS_labels\\S068_005_00000021_facs.txt'

Hello, here we are in 2019 and I am trying to test this code. Please where can I download the required folders data_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/cohn-kanade-images' label_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/FACS_labels' landmark_path_dir = 'C:/Users/sarmad/Documents/deep_L_projects/AU/Landmarks' Thank you.

google search ck and ck+ database (Cohn-Kanade AU-Coded Expression Database)

http://www.pitt.edu/~emotion/ck-spread.htm

Thank You for replying. I was able to download the CK+ dataset, FACS_labels, and Landmarks.

Regards

selfcontrol7 commented 4 years ago

Hello,

Thank you for this awesome work. During the training part, I encounter this error in the values returned by the function valid in the file main.py :

TypeError: mean() missing 3 required positional argument: "dim", "keepdim", "dtype"

This is the original code at ligne 130 return return_tar, return_pred, np.mean(losses.avg)

But had to be changed to return return_tar, return_pred, torch.mean(losses.avg) After this, the training will work perfectly. Just in case someone gets the same error.

Also, please do the code can predict or return the Action Units detected from any image we give as input? I would like to use this model to predict emotion from any given image. Can you help me, please?

Best regard.

Eason-zz commented 3 years ago

It seems that your directory has problem. try r'c:/users/sarmad/documents/deep_L_projects/AU/FACS_labels/S068_005_00000021_facs.txt' or 'c:\users\sarmad\documents\deep_L_projects\AU\FACS_labels\S068_005_00000021_facs.txt'

Maybe r'c:/users/sarmad/documents/deep_L_projects/AU/FACS_labels/S068_005_00000021_facs.txt' or 'c:\users\sarmad\documents\deep_L_projects\AU\FACS_labels\S068_005_00000021_facs.txt'

Fahad113 commented 3 years ago

I also faced this error but now my code working fine. the problem is the listdir method. the (os.listdir(path)) method cannot support dot ( . ) in file name. change file name and remove any dot in file path/name.

Snitis commented 2 years ago

i faced this error ,[INFO] Loading images ... [INFO] Processing 0022d6b7-d47c-4ee2-ae9a-392a53f48647_JR_B.Spot 8964.JPG ... Error : [WinError 267] The directory name is invalid: 'E:\PlantVillage/Pepperbell_Bacterialspot/0022d6b7-d47c-4ee2-ae9a-392a53f48647JR_B.Spot 8964.JPG/'