DeepLabCut / DeepLabCut

Official implementation of DeepLabCut: Markerless pose estimation of user-defined features with deep learning for all animals incl. humans
http://deeplabcut.org
GNU Lesser General Public License v3.0
4.53k stars 1.65k forks source link

Solution when one do create_new_project with copy_videos=True in Windows environment. #105

Closed timegate closed 5 years ago

timegate commented 5 years ago

Your Operating system and DeepLabCut version Windows 10, Anaconda Env & DeepLabCut2.0

Is your feature request related to a problem? Please describe. Issue99(https://github.com/AlexEMG/DeepLabCut/issues/99) Problem happened when 3.create_new_project with copy_videos=True.

Describe the solution you'd like Here is an email I sent to Mackenzie Mathis yesterday(But I haven't get no reply.. maybe she is busy?).

Hello,I wrote a issue(https://github.com/AlexEMG/DeepLabCut/issues/99) 3 days ago and now I find that below fixing can solve the problem 3.create_new_project with copy_videos=True.

I realized that it is the problem specified to windows. For windows users, we should add this code to new.py(Anaconda3\envs(your env name)\Lib\site-packages\deeplabcut\create_project\new.py)

Before explanation,

I want to make sure that I have run the code with two slashes(not one slash). It's not the problem caused by the fact that I didn't follow your instruction.

video=['C:\Users\user\Desktop\Video_files_Deeplabcut\LinearChamber\20180906\Trial1.mpg'] # Enter the paths of your videos you want to grab frames from.

deeplabcut.create_new_project(task,experimenter,video, working_directory='C:\Users\user\Desktop', copy_videos=False) #change the working directory to where you want the folders created.

But somehow, the path strings were changed to strings which have only one slashes even if some codes need the path with two slashes (I don't know why).

1) I made a simple func that change existing string() to new string which have double slashes(\)

def double_slash(str):

temp_list=str.split('\\')

result_str='\\\\'.join(temp_list)

print(result_str)

return result_str;

2) I changed (maybe line 103~?)

if copy_videos==True:

    print("Copying the videos")

    for src, dst in zip(videos, destinations):

        src=double_slash(str(src))

        dst=double_slash(str(dst))

        shutil.copy(src,dst)

3)Also, I changed (maybe line 125~?)

# adds the video list to the config.yaml file

video_sets = {}

for video in videos:

    print(video)

    video=double_slash(str(video))

Then it works. Could you please check this on windows 10 with conda environment?

Also, may I recieve a invitation message for deeplabcut slack group?

AlexEMG commented 5 years ago

Under the hood we are using https://docs.python.org/3/library/pathlib.html#module-pathlib which deals deal with linux/macos and windows paths. As far as I am aware, this works. I and others have tested DLC on Windows (and Linux) and it works fine. Your suggested fix is highly brittle, as it is hard coded.

Perhaps you could highlight cases, where what you are saying:"But somehow, the path strings were changed to strings which have only one slashes even if some codes need the path with two slashes (I don't know why)." happens? I was not able to find such problems. Those should be fixed.

zxy126 commented 5 years ago

Hello, maybe I have the same question.

Environment Win10 x64, DLC2, CUDA8.0, TF-GPU1.4.0, python3.5.5, Cython, Anaconda Env

In function create_new_project, if I set copy_videos=True. It shows "TypeError: _isdir: illegal type for path parameter". So I set copy_videos=False to escape from the problem. image

But when I try to create_training_dataset it happened again. I can't flight anymore. image

MMathisLab commented 5 years ago

When you run deeplabcut. create_new_project

Do this instead: config_path = deeplabcut. create_new_project(...

Then at least you have a variable you can easily pass instead of the string every time for the config path!

Here is a demo video of how I use the terminal to create a project: https://www.youtube.com/watch?v=7xwOhUcIGio

We will look into the copy=True part

FedeClaudi commented 5 years ago

I had similar issues, it seems that os on windows doesn't deal well with Path objects. The solution was to call str() on the path object within the os.path.isdir() or any other os or shutil call within the script [it's only handful of places where it is raises errors].

AlexEMG commented 5 years ago

I see: We should be using this: https://docs.python.org/3/library/os.html#os.fspath

AlexEMG commented 5 years ago

Ok, please check the latest push. Uses fspath at the spots where you had trouble.

sebo361 commented 5 years ago

Hi, i am using Ubuntu 16.04, DLC, deeplabcut=2.0.0, virtualenv, and have the same error when setting copy_videos=True:

create_new_project(project, experimenter, videos, working_directory, copy_videos, videotype) 111 print("Copying the videos") 112 for src, dst in zip(videos, destinations): --> 113 shutil.copy(os.fspath(src),os.fspath(dst)) #https://www.python.org/dev/peps/pep-0519/ 114 #https://github.com/AlexEMG/DeepLabCut/issues/105 (for windows) 115

AttributeError: module 'os' has no attribute 'fspath'

AlexEMG commented 5 years ago

fspath is part of the python3 os package: https://docs.python.org/3/library/os.html

Are you using Python2 https://docs.python.org/2/library/os.html ?

sebo361 commented 5 years ago

i am using Python 3.5.2 - should i upgrade to 3.6.3?

sebo361 commented 5 years ago

yeah it got solved with using python 3.6 within the virtualenv. thanks!

grego1979 commented 5 years ago

I have a related issue but when running deeplabcut.create_training_dataset(config_path,num_shuffles=1)

I'm using a Windows Server 2016 machine and I have trouble updating to python 3.6 (I have python 3.5)

`--------------------------------------------------------------------------- TypeError Traceback (most recent call last) c:\programdata\anaconda3\envs\tensorflow15\lib\site-packages\deeplabcut\utils\auxiliaryfunctions.py in attempttomakefolder(foldername, recursive) 57 try: ---> 58 os.path.isdir(foldername) 59 except TypeError: #https://www.python.org/dev/peps/pep-0519/

TypeError: _isdir: illegal type for path parameter

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last)

in () ----> 1 deeplabcut.create_training_dataset(config_path,num_shuffles=1) c:\programdata\anaconda3\envs\tensorflow15\lib\site-packages\deeplabcut\generate_training_dataset\trainingsetmanipulation.py in create_training_dataset(config, num_shuffles, Shuffles) 341 # Create path for training sets & store data there 342 trainingsetfolder = auxiliaryfunctions.GetTrainingSetFolder(cfg) #Path concatenation OS platform independent --> 343 auxiliaryfunctions.attempttomakefolder(Path(os.path.join(project_path,str(trainingsetfolder))),recursive=True) 344 Data = merge_annotateddatasets(cfg,project_path,Path(os.path.join(project_path,trainingsetfolder))) 345 Data = Data[scorer] #extract labeled data c:\programdata\anaconda3\envs\tensorflow15\lib\site-packages\deeplabcut\utils\auxiliaryfunctions.py in attempttomakefolder(foldername, recursive) 58 os.path.isdir(foldername) 59 except TypeError: #https://www.python.org/dev/peps/pep-0519/ ---> 60 foldername=os.fspath(foldername) #https://github.com/AlexEMG/DeepLabCut/issues/105 (windows) 61 62 if os.path.isdir(foldername): AttributeError: module 'os' has no attribute 'fspath'`
MMathisLab commented 5 years ago

Yep, unfortunately you’ll have to upgrade to 3.6