Пример #1
0
def main():

    plt.close('all')
    exit = False
    while exit == False:
        choice = print_usage("start")

        if choice == "exit":
            exit = True
            sys.exit(0)
        elif choice == "1":
            command = create_dict_list("/data/11012579/projects/", 0)
        elif choice == "2":
            command = print_usage("program")
            command = command.split(" ")
            map_with_videos = create_dict_list("/data/11012579/videos/", 0)[0]
            command.append("/data/11012579/videos/" + map_with_videos + "/" +
                           create_dict_list(
                               "/data/11012579/videos/" + map_with_videos +
                               "/", 1)[0])

        if len(command) == 1:
            exit = usingDeep(
                '/data/11012579/projects/' + command[0] + '/config.yaml',
                command[0])
        elif len(command) == 3:
            print("Check project name: \nName of project:" + command[0] +
                  "\nYour name:" + command[1] + "\nPath to video:" +
                  command[2] +
                  "\nto contineu type: check \nTo change type: redo")
            input_2 = "redo/check"
            while input_2 not in ["check", "redo"]:
                print("Type check or redo!")
                input_2 = str(input())
                if input_2 == "check":
                    deeplabcut.create_new_project(
                        command[0],
                        command[1], [command[2]],
                        working_directory='/data/11012579/projects',
                        copy_videos=False)
                    path_config = '/data/11012579/projects/' + command[
                        0] + '-' + command[1] + '-' + str(
                            date.today()) + '/config.yaml'
                    print("\nGo to projects -> your project -> config.yaml\
                            \nEdit: numframes2pick to select how manny frames you want to add \
                            \nEdit: bodyparts and type the bodyparts you want to keep track of\
                            \nEdit: Skeleton to draw lines between the tracked bodyparts\
                            \nRun ipython home.py to continue")
                    exit = usingDeep(path_config, command[0])

        else:
            print_usage("error")
Пример #2
0
    def create_project(self):
        # Get project directory
        project_dir = self.project_dir
        # Check if project exists
        if project_dir.exists():
            print("The project directory already exists.")
        else:
            # Creates new project then renames according to task and subject
            print("The project directory does not exist.")
            #  Create file name as is created in deeplabcut.create_new_project
            from datetime import datetime as dt
            # Deeplabcut uses the creation name in the date. We want to change this to the study date
            date = dt.today().strftime('%Y-%m-%d')
            old_project_dir = Path("-".join([self.task, self.subject, date]))
            # Create new project
            deeplabcut.create_new_project(
                self.task,
                self.subject,
                self.video,
                working_directory=self.project_dir.resolve().parent,
                copy_videos=True)
            # Rename project to have project date not current date
            old_project_dir.rename(project_dir)

            from deeplabcut.utils import auxiliaryfunctions

            # Get config file path
            main_config_file = Path(self.project_dir).resolve() / self.config

            #  load config.yaml
            main_config = auxiliaryfunctions.read_config(main_config_file)

            #  Update values in config file:
            main_config['bodyparts'] = self.bodyparts
            main_config['date'] = self.date
            main_config['numframes2pick'] = self.numframes2pick

            # Write dictionary to yaml  config file
            auxiliaryfunctions.write_config(main_config_file, main_config)

            # Update project paths
            self.update_project_paths()
        return
Пример #3
0
def create():
    name = request.json['project_name']
    experimenter = request.json['experimenter']
    config_path = deeplabcut.create_new_project(name, experimenter, [])
    projectId = projectRepository.insert_one({
        'project_name': name,
        'experimenter': experimenter,
        'config_path': config_path
    }).inserted_id
    return "Project " + str(
        projectId) + " created."  #TODO: Return real response
Пример #4
0
def create_dlc_project(name, author, files, props):
    config_path = deeplabcut.create_new_project(name, author, files)
    update_dlc_config(config_path, props)
    deeplabcut.extract_frames(config_path,
                              'automatic',
                              'kmeans',
                              userfeedback=False)
    deeplabcut.label_frames(config_path)
    deeplabcut.check_labels(config_path)

    return config_path.replace('/config.yaml', '')
        def clicked_create():
            self.select_working_directory(window)
            window.destroy()
            self.get_window_for_project_name()
            self.path_config_file = deeplabcut.create_new_project(self.name_of_project, self.experimenter, self.video_list,
                                                             working_directory=self.working_directory,
                                                             copy_videos=True)
            self.select_body_parts()
            self.add_new_videos()
            print(self.video_list)
            if len(self.video_list) > 0:
                deeplabcut.add_new_videos(self.path_config_file, self.video_list, copy_videos=True)
                deeplabcut.extract_frames(self.path_config_file, 'automatic', 'kmeans', checkcropping=False, crop=True)

            self.working_window_for_deeplabcut()
Пример #6
0
def setup():
    # Check if having admin privilege if running Windows
    if helpers.platform() == "Windows" and helpers.has_admin() == False:
        print("Run with Administrative privilege for Windows")
        # todo output something so that the batch script would terminate immediately
        return

    pre_config_handler = YAML(typ='safe')
    with open("../pre_config.yaml", 'r') as stream:
        pre_config = pre_config_handler.load(stream)

    none_handler = helpers.ConfigReader(pre_config)
    task = none_handler.read("task")
    researchers = none_handler.read("researchers")
    relative_path_to_working_directory = none_handler.read("relative_path_to_working_directory")
    # Get full path here
    video_full_paths = helpers.get_video_full_paths(pre_config["relative_path_to_videos"])
    # Create project
    path_config_file = dlc.create_new_project(task, researchers, video_full_paths, working_directory=relative_path_to_working_directory, copy_videos=False)

    # Store the project path for future processes
    path_config = {"path_config_file" : path_config_file}
    with open('./config.json', 'w+') as fp:
        json.dump(path_config, fp, indent=4)

    # Change the auto generated config file
    bodyparts = none_handler.read("bodyparts")
    numframes2pick = none_handler.read("numframes2pick")

    config_handler = YAML()
    config_handler.preserve_quotes = True
    with open(path_config_file, 'r') as stream:
        config = config_handler.load(stream)

    config["bodyparts"] = bodyparts
    config["numframes2pick"] = numframes2pick

    with open(path_config_file, 'w') as fp:
        config_handler.dump(config, fp)

    frame_extraction_mode = none_handler.read("frame_extraction_mode")
    frame_extraction_algorithm = none_handler.read("frame_extraction_algorithm")
    extract.extract(path_config_file, mode=frame_extraction_mode, algo=frame_extraction_algorithm)
Пример #7
0
def export_dlc(expdir,
               dlcdir,
               *,
               session=None,
               movlist: parse_movlist = None,
               antlist=None,
               nimages=100,
               video=False,
               username='******'):
    """Export trainset for DeepLabCut"""

    import deeplabcut as dlc
    from antrax.dlc import create_trainset

    ex = axExperiment(expdir, session)

    if isdir(dlcdir) and not isfile(dlcdir + '/config.yaml'):
        report(
            'E',
            'directory exists, but does contain a deeplabcut configuration file! check your parameters'
        )
        return

    if not isdir(dlcdir):

        report('I', 'DLC project does not exists, creating')
        pathlist = os.path.normpath(dlcdir).split(os.path.sep)
        wd = os.path.sep.join(pathlist[:-1])
        projname = pathlist[-1]
        dlcdir = dlc.create_new_project(projname,
                                        username, [],
                                        working_directory=wd)

    create_trainset(ex,
                    dlcdir,
                    n=nimages,
                    antlist=antlist,
                    movlist=movlist,
                    vid=video)
Пример #8
0
def DLCPrep(project_name,
            your_name,
            img_path,
            output_dir_base,
            copy_videos_bool=True):
    img_array = []
    filenames = glob.glob(os.path.join(img_path, "*.png"))
    filenames.sort(key=natural_sort_key)
    size = (512, 512)
    for filename in filenames:
        img = cv2.imread(filename)
        height, width, layers = img.shape
        size = (width, height)
        img_array.append(img)

    if len(img_array) > 0:
        if not os.path.isdir(os.path.join(output_dir_base, "img_for_label")):
            os.mkdir(os.path.join(output_dir_base, "img_for_label"))
        video_output_path = os.path.join(output_dir_base, "img_for_label")
        video_name = os.path.join(video_output_path, "video_for_label.mp4")

        if not os.path.isdir(video_output_path):
            os.mkdir(video_output_path)
        out = cv2.VideoWriter(video_name, cv2.VideoWriter_fourcc(*"MP4V"), 30,
                              size)
        for i in range(len(img_array)):
            out.write(img_array[i])
        out.release()

        config_path = deeplabcut.create_new_project(
            project_name,
            your_name,
            [video_name],
            copy_videos=copy_videos_bool,
            working_directory=output_dir_base,
        )
        return config_path
Пример #9
0
task = 'gaitdatatestv2'  # use the videos of dlc examples
experimenter = 'Jordan'

if prjexist:
    # project already exist
    print("Use exist project!!!")
    path_prj = os.path.join(os.getcwd(), 'OurPrj',
                            task + '-' + experimenter + '-2019-04-16')
    path_config_file = os.path.join(path_prj, 'config.yaml')
else:
    video = os.path.join(os.getcwd(), 'OurPrj',
                         task + '-' + experimenter + '-2019-04-16', 'videos',
                         'Az_Neural.avi')
    path_config_file = deeplabcut.create_new_project(
        task,
        experimenter,
        video,
        working_directory=working_dir,
        copy_videos=True)
    path_prj, config_file_name = os.path.split(path_config_file)

if not framesextracted:
    print("Extracting frame from videos")
    deeplabcut.extract_frames(path_config_file,
                              'automatic',
                              'uniform',
                              crop=False)
else:
    print("frames have been extracted already!!")

if not frameslabeled:
    print("Need labeled frames")
    # "filterpredictions" (set videos_to_filter_predictions variable)
    # "step_12" or "plot_trajectories" (set videos_to_plot_trajectories variable)
    # 'step_12_bis" or "analyzeskeleton"
    # "step_13" or "create_labeled_video" (set videos_to_create_with_labels variable)
    # "step_14" or "extract_outlier_frames" (set videos_to_extract_outlier_frames variable)
    # "step_15" or "refine_labels"
    # "step_16" or "merge_datasets"
    stages_to_run = ["analyzeskeleton"]

    # ------------------------------------------------------------------
    # STAGE I: Stage I: opening DeepLabCut and creation of a new project
    # Steps 1, 2
    # ------------------------------------------------------------------
    if "step_2" in stages_to_run or "create_new_project" in stages_to_run:
        config_path = deeplabcut.create_new_project(project="test_valentin", experimenter="Robin", videos=[movie_file],
                                      copy_videos=True,
                                      videotype='.avi',
                                      working_directory=working_dir)

    if "step_2_bis" in stages_to_run or "add_new_videos" in stages_to_run:
        deeplabcut.add_new_videos(config=config_path, videos=new_videos_to_add, copy_videos=True)


    # ------------------------------------------------------------------
    # STAGE II: configuration of the project, open the config.yaml file
    # Step 3
    # ------------------------------------------------------------------
    # start stop indicate which portion of the movie to extract the frames from, ex 0 & 0.5 means first 50%
    """
    Exemple of config:
    bodyparts:
    - forepaw
Пример #11
0
    def create_new_project(self, event):
        """
        Finally create the new project
        """
        if self.sel_config.IsShown():
            self.cfg = self.sel_config.GetPath()
            if self.cfg == "":
                wx.MessageBox(
                    "Please choose the config.yaml file to load the project",
                    "Error",
                    wx.OK | wx.ICON_ERROR,
                )
                self.loaded = False
            else:
                wx.MessageBox("Project Loaded!", "Info",
                              wx.OK | wx.ICON_INFORMATION)
                self.loaded = True
                self.sel_vids_new.Enable(True)
                self.addvid.Enable(True)
                self.edit_config_file.Enable(True)
        else:
            self.task = self.proj_name_txt_box.GetValue()
            self.scorer = self.exp_txt_box.GetValue()

            if self.task != "" and self.scorer != "" and self.filelist != []:
                self.cfg = deeplabcut.create_new_project(
                    self.task,
                    self.scorer,
                    self.filelist,
                    self.dir,
                    copy_videos=self.copy,
                    multianimal=self.multi_choice.IsChecked(),
                )
            else:
                wx.MessageBox(
                    "Some of the enteries are missing.\n\nMake sure that the task and experimenter name are specified and videos are selected!",
                    "Error",
                    wx.OK | wx.ICON_ERROR,
                )
                self.cfg = False
            if self.cfg:
                wx.MessageBox("New Project Created", "Info",
                              wx.OK | wx.ICON_INFORMATION)
                self.loaded = True
                self.edit_config_file.Enable(True)

        # Remove the pages in case the user goes back to the create new project and creates/load a new project
        if self.parent.GetPageCount() > 3:
            for i in range(2, self.parent.GetPageCount()):
                self.parent.RemovePage(2)
                self.parent.Layout()

        # Add all the other pages
        if self.loaded:
            self.edit_config_file.Enable(True)
            cfg = auxiliaryfunctions.read_config(self.cfg)
            if self.parent.GetPageCount() < 3:
                page3 = Extract_frames(self.parent, self.gui_size, self.cfg)
                self.parent.AddPage(page3, "Extract frames")

                page4 = Label_frames(self.parent, self.gui_size, self.cfg)
                self.parent.AddPage(page4, "Label frames")

                page5 = Create_training_dataset(self.parent, self.gui_size,
                                                self.cfg)
                self.parent.AddPage(page5, "Create training dataset")

                page6 = Train_network(self.parent, self.gui_size, self.cfg)
                self.parent.AddPage(page6, "Train network")

                page7 = Evaluate_network(self.parent, self.gui_size, self.cfg)
                self.parent.AddPage(page7, "Evaluate network")

                page12 = Video_Editing(self.parent, self.gui_size, self.cfg)
                self.parent.AddPage(page12, "Video editor")

                page8 = Analyze_videos(self.parent, self.gui_size, self.cfg)
                self.parent.AddPage(page8, "Analyze videos")

                if cfg.get("multianimalproject", False):
                    page = Refine_tracklets(self.parent, self.gui_size,
                                            self.cfg)
                    self.parent.AddPage(page, "Refine tracklets")
                page11 = Create_Labeled_Videos(self.parent, self.gui_size,
                                               self.cfg)
                self.parent.AddPage(page11, "Create videos")
                page9 = Extract_outlier_frames(self.parent, self.gui_size,
                                               self.cfg)
                self.parent.AddPage(page9, "Extract outlier frames")
                page10 = Refine_labels(self.parent, self.gui_size, self.cfg,
                                       page5)
                self.parent.AddPage(page10, "Refine labels")
                self.edit_config_file.Enable(True)
Пример #12
0
# check GPU (optional)
from tensorflow.python.client import device_lib

device_lib.list_local_devices()

# start projects
import glob
import os

os.chdir('chage to your path')
videos = glob.glob('*.mp4')
learningVideo = ["add video name for learning"]

config_path = dlc.create_new_project('PJ name',
                                     'my name',
                                     learningVideo,
                                     working_directory='add your directory',
                                     copy_videos=False)

# if the project was already created, run this
config_path = 'path to yaml file'

# extract frame
dlc.extract_frames(config_path, 'automatic', 'kmeans')

# label the data
dlc.label_frames(config_path)

# check labels
#dlc.check_labels(config_path)
Пример #13
0
# In[4]:


pwd


# In[5]:


ls


# In[6]:


deeplabcut.create_new_project('Mouse', 'Amr', ['/home/amr/Trial_DeepLabCut/mouse.avi'])


# # <font color=red>Now, You open the config.yaml file to modify the body part you want to track and if you want, you can modify the number of frames to pick</font>

# In[3]:


path_config = '/home/amr/Trial_DeepLabCut/Mouse-Amr-2018-12-03/config.yaml'


# In[4]:


deeplabcut.extract_frames(path_config, 'automatic', 'kmeans')
    NET = "dlcrnet_ms5"

    # Always test a different model from list above
    NET = random.choice(MODELS)

    basepath = os.path.dirname(os.path.realpath(__file__))
    DESTFOLDER = basepath

    video = "m3v1mp4"
    video_path = os.path.join(
        basepath, "openfield-Pranav-2018-10-30", "videos", video + ".mp4"
    )

    print("Creating project...")
    config_path = deeplabcut.create_new_project(
        TASK, SCORER, [video_path], copy_videos=True, multianimal=True
    )

    print("Project created.")

    print("Editing config...")
    cfg = auxiliaryfunctions.edit_config(
        config_path,
        {
            "numframes2pick": NUM_FRAMES,
            "TrainingFraction": [TRAIN_SIZE],
            "identity": True,
            "uniquebodyparts": ["corner1", "corner2"],
        },
    )
    print("Config edited.")
import os

experimenter = 'Theresa'
project = 'Armina_model_1'

videos = glob.glob(
    '/home/weertman/Documents/Theresa_FHL/Armina_DeepLabCut/random_train_images/*.png'
)

path_config = '/home/weertman/Documents/Theresa_FHL/Armina_DeepLabCut/Arimina_model_1/'
if os.path.exists(path_config) != True:
    os.mkdir(path_config)

path_config = deeplabcut.create_new_project(project,
                                            experimenter,
                                            videos,
                                            copy_videos=True,
                                            working_directory=path_config)

path_config = '/home/weertman/Documents/Theresa_FHL/Armina_DeepLabCut/Arimina_model_1/Armina_model_1-Theresa-2020-07-01/config.yaml'
'''
deeplabcut.extract_frames(path_config,
                          mode = 'automatic',   
                          algo = 'uniform',
                          userfeedback = False,
                          crop = False)
'''
deeplabcut.label_frames(path_config)

deeplabcut.create_training_dataset(path_config)
deeplabcut.train_network(path_config, maxiters=200000, displayiters=10)
Пример #16
0
dfolder = None
net_type = 'resnet_50'  #'mobilenet_v2_0.35' #'resnet_50'
augmenter_type = 'default'
augmenter_type2 = 'imgaug'

if platform.system() == 'Darwin' or platform.system() == 'Windows':
    print("On Windows/OSX tensorpack is not tested by default.")
    augmenter_type3 = 'imgaug'
else:
    augmenter_type3 = 'tensorpack'  #Does not work on WINDOWS

numiter = 3

print("CREATING PROJECT")
path_config_file = dlc.create_new_project(task,
                                          scorer,
                                          video,
                                          copy_videos=True)

cfg = dlc.auxiliaryfunctions.read_config(path_config_file)
cfg['numframes2pick'] = 5
cfg['pcutoff'] = 0.01
cfg['TrainingFraction'] = [.8]
cfg['skeleton'] = [['bodypart1', 'bodypart2'], ['bodypart1', 'bodypart3']]

dlc.auxiliaryfunctions.write_config(path_config_file, cfg)

print("EXTRACTING FRAMES")
dlc.extract_frames(path_config_file, mode='automatic', userfeedback=False)

print("CREATING SOME LABELS FOR THE FRAMES")
frames = os.listdir(
class tutorial():
    def __init__(self, algo, crop, userfeedback, shuffle, saveiters, displayiters, angle, center, scale, filenames):
        self.algo = "automatic"
        self.crop = False
        self.userfeedback = False
        self.shuffle = 1
        self.saveiters = 200
        self.displayiters = 100
        self.angle = -4.5
        self.center = None
        self.scale = 1.0
        #Generate all rotating videos
        self.filenames = glob.glob('*.mp4') #Return the file name with .mp4 extention

    def rotate(self, image, angle, center=None, scale=1):
        #scale = 1: original size
        rows,cols,ch = image.shape
        if center == None:
            center = (cols / 2, rows / 2)
        M = cv2.getRotationMatrix2D(center, angle, scale)
        #Matrix: Rotate with center by angles
        dst = cv2.warpAffine(image,M,(cols,rows))
        #After rotation
    return dst


    def videorotate(self, filenames, output_name, display_video = False):
        # capture video
        cap = cv2.VideoCapture(filename)

        #read video frame by frame
        #extract original video frame features
        sz = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
                int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))

        fourcc = int(cap.get(cv2.CAP_PROP_FOURCC))

        fps = int(cap.get(cv2.CAP_PROP_FPS))

        #Make a directory to store the rotated videos
        path = "./rotated"
        try:
            os.mkdir(path)
        except OSError:
            pass
        else:
            print ("Successfully created the directory %s " % path)

        #Automatically name the rotated videos
        file = "./rotated/" + output_name
        out = cv2.VideoWriter(file, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'), fps, sz)
        #Integrate all frames to video


        #Read videos and rotate by certain degrees
        while(cap.isOpened()):
            #flip for truning(fliping) frames of video
            ret,img = cap.read()
            try:
                img2 = rotate(img, -4.5)
                #Flipped Vertically
                out.write(img2)
                if display_video == True:
                    cv2.imshow('rotated video',img2)

                k=cv2.waitKey(30) & 0xff
                #once you inter Esc capturing will stop
                if k==27:
                    break
            except:
                print (filename, 'successfully rotated!!!' )
                break
        cap.release()
        out.release()
        cv2.destroyAllWindows()

    for i in filenames:
        output_name = os.path.splitext(i)[0] + " rotated.mp4"


    cwd = os.chdir("./rotated")
    #we are using rotated videos
    cwd = os.getcwd()
    mp4files = [f for f in listdir(cwd) if isfile(join(cwd, f)) and os.path.splitext(f)[1] == ".mp4"]
    #Get all mp4 files

    task='Reaching' # Enter the name of your experiment Task
    experimenter='Donghan' # Enter the name of the experimenter
    video=mp4files # Enter the paths of your videos you want to grab frames from.
    now = datetime.datetime.now()

    try:
        path_config_file=deeplabcut.create_new_project(task,experimenter,video, working_directory='/home/donghan/DeepLabCut/data/rotated',copy_videos=True)
    #change the working directory to where you want the folders created.
    except:
        overwrite = input("Do you want to overwrite the folder since it already exists? y/n:")
        if overwrite == 'y':
            os.rmdir(task + '-' + experimenter + '-' + str(now.year) + '-' + str(now.month) + '-' + str(now.day))
            path_config_file=deeplabcut.create_new_project(task,experimenter,video, working_directory='/home/donghan/DeepLabCut/data/rotated',copy_videos=True)
        else:
            continue

# The function returns the path, where your project is.
# You could also enter this manually (e.g. if the project is already created and you want to pick up, where you stopped...)
#path_config_file = '/home/Mackenzie/Reaching/config.yaml' # Enter the path of the config file that was just created from the above step (check the folder)

    %matplotlib inline
    deeplabcut.extract_frames(path_config_file,'automatic',crop=False, userfeedback=False) #there are other ways to grab frames, such as by clustering 'kmeans'; please see the paper.
    #You can change the cropping to false, then delete the checkcropping part!
    #userfeedback: ask if users would like to continue or stop

    %gui wx
    deeplabcut.label_frames(path_config_file)

    deeplabcut.check_labels(path_config_file) #this creates a subdirectory with the frames + your labels

    deeplabcut.create_training_dataset(path_config_file)

    deeplabcut.train_network(path_config_file, shuffle=1, saveiters=200, displayiters=10)
#Other parameters include trainingsetindex=0,gputouse=None,max_snapshots_to_keep=5,autotune=False,maxiters=None
#Detailed function explanation can be found here https://github.com/AlexEMG/DeepLabCut/blob/efa95129061b1ba1535f7361fe76e9267568a156/deeplabcut/pose_estimation_tensorflow/training.py

    deeplabcut.evaluate_network(path_config_file)

    videofile_path = ['1035 SI_A, Aug 15, 13 17 7 rotated.mp4'] #Enter the list of videos to analyze.
    deeplabcut.analyze_videos(path_config_file,videofile_path)

    deeplabcut.create_labeled_video(path_config_file,videofile_path)
Пример #18
0
    for cs in camera_config['serials']:
        tv = os.path.join(session_config['session_path'],
                          session_config['cam_dicts'][cs]['ud_video'])
        tv2 = os.path.join(videos_collection_dir,
                           '{}_{}'.format(session_id,
                                          os.path.split(tv)[-1]))
        #shutil.copyfile(tv, tv2)
        training_videos.append(tv2)

# %% 2a Make a new DLC project (this or 2b)
dlc_prj_name = '2019.12.20_8camsNoMarkers'
scorer = 'AS'
prj_date = '2019-12-23'
config_path = deeplabcut.create_new_project(dlc_prj_name,
                                            scorer,
                                            training_videos,
                                            working_directory=BASE_DIR,
                                            copy_videos=False)
dlc_proj_name = '-'.join([dlc_prj_name, scorer, prj_date])

proj_path = os.path.join(BASE_DIR, dlc_proj_name)
if config_path is None:
    config_path = os.path.join(proj_path, 'config.yaml')
labeled_csv_path = os.path.join(proj_path, 'labeled_videos')
if not os.path.isdir(labeled_csv_path):
    os.mkdir(labeled_csv_path)

print('New config_path: "{}"'.format(config_path))

# Edit the config file to represent your tracking
Пример #19
0
import deeplabcut as dlc
import os
import json
import helpers

config = {}
task = 'whiskers'  # Enter the name of your experiment Task
experimenter = 'sail'  # Enter the name of the experimenter

# get full path here
video_full_paths = helpers.get_video_full_paths()
# create project
path_config_file = dlc.create_new_project(
    task,
    experimenter,
    video_full_paths,
    working_directory=os.getcwd(),
    copy_videos=False
)  #change the working directory to where you want the folders created.
config["path_config_file"] = path_config_file

with open('config.json', 'w') as fp:
    json.dump(config, fp, indent=4)
Пример #20
0
def setupProject(projectName, videos):
    return deeplabcut.create_new_project(projectName, 'joshua', videos)
Пример #21
0
from os.path import join
from ExperimentSpecificCode._2018_Chronic_Neuroseeker_TouchingLight._2019_06_25_AK_47p2 import constants as const
import deeplabcut


# ----------------------------------------------------------------------------------------------------------------------
# FOLDERS NAMES
date = 8
base_dlc_folder = join(const.base_save_folder, const.rat_folder, const.date_folders[date],
                       'Analysis', 'Deeplabcut')
base_projects_folder = join(base_dlc_folder, 'projects')

cropped_video_filename = join(base_dlc_folder, 'BonsaiCroping', 'Croped_video.avi')

# ----------------------------------------------------------------------------------------------------------------------
config_path = deeplabcut.create_new_project(project='V1', experimenter='', videos=[cropped_video_filename],
                                            working_directory=base_projects_folder, copy_videos=True)

# Use the line below to 'reload the existing project
config_path = join(base_projects_folder, 'V1--2019-06-30', 'config.yaml')

# Edit the config.yaml file
deeplabcut.extract_frames(config_path, 'manual')

deeplabcut.label_frames(config_path)

deeplabcut.check_labels(config_path)

deeplabcut.create_training_dataset(config_path)

deeplabcut.train_network(config_path, gputouse=1)
Пример #22
0
    def create_new_project(self, event):
        """
        Finally create the new project
        """
        if self.sel_config.IsShown():
            self.cfg = self.sel_config.GetPath()
            if self.cfg == "":
                wx.MessageBox(
                    'Please choose the config.yaml file to load the project',
                    'Error', wx.OK | wx.ICON_ERROR)
                self.loaded = False
            else:
                wx.MessageBox('Project Loaded!', 'Info',
                              wx.OK | wx.ICON_INFORMATION)
                self.loaded = True
                self.edit_config_file.Enable(True)
        else:
            self.task = self.proj_name_txt_box.GetValue()
            self.scorer = self.exp_txt_box.GetValue()
            if self.task and self.scorer and len(self.filelist):
                self.cfg = deeplabcut.create_new_project(
                    self.task, self.scorer, self.filelist, self.dir,
                    self.copy_choice.IsChecked())
            else:
                wx.MessageBox(
                    'Some of the entries are missing.\n\nMake sure that the task and experimenter name are specified and videos are selected!',
                    'Error', wx.OK | wx.ICON_ERROR)
                self.cfg = False
                self.loaded = False
            if self.cfg:
                wx.MessageBox('New Project Created', 'Info',
                              wx.OK | wx.ICON_INFORMATION)
                self.loaded = True
                self.edit_config_file.Enable(True)

        # Remove the pages in case the user goes back to the create new project and creates/load a new project
        if self.parent.GetPageCount() > 3:
            for i in range(2, self.parent.GetPageCount()):
                self.parent.RemovePage(2)
                self.parent.Layout()

        # Add all the other pages
        if self.loaded:
            self.edit_config_file.Enable(True)
            if self.parent.GetPageCount() < 3:
                page3 = Extract_frames(self.parent, self.gui_size, self.cfg)
                self.parent.AddPage(page3, "Extract frames")
                page4 = Label_frames(self.parent, self.gui_size, self.cfg)
                self.parent.AddPage(page4, "Label frames")
                page5 = Create_training_dataset(self.parent, self.gui_size,
                                                self.cfg)
                self.parent.AddPage(page5, "Create training dataset")
                page6 = Train_network(self.parent, self.gui_size, self.cfg)
                self.parent.AddPage(page6, "Train network")
                page7 = Evaluate_network(self.parent, self.gui_size, self.cfg)
                self.parent.AddPage(page7, "Evaluate network")
                page8 = Analyze_videos(self.parent, self.gui_size, self.cfg)
                self.parent.AddPage(page8, "Analyze videos")
                page11 = Create_Labeled_Videos(self.parent, self.gui_size,
                                               self.cfg)
                self.parent.AddPage(page11, "Create Videos")
                page9 = Extract_outlier_frames(self.parent, self.gui_size,
                                               self.cfg)
                self.parent.AddPage(page9, "Extract outlier frames")
                page10 = Refine_labels(self.parent, self.gui_size, self.cfg,
                                       page5)
                self.parent.AddPage(page10, "Refine labels")
                self.edit_config_file.Enable(True)
Пример #23
0
def get_video(exp_path):
    for file in os.listdir(exp_path):
        if "eye.mp4" in file:
            return os.path.join(exp_path, file)
    raise ValueError(f"No eye.mp4 found in {exp_path}")


def get_ls_of_all_videos(drive):
    ls = []
    add2ls = lambda path: ls.append(get_video(path))
    apply_to_all_one_plane_recordings(drive, add2ls)
    return ls


if __name__ == "__main__":
    project_name = "mousepupils"
    creator = "viviani"
    vids = get_ls_of_all_videos("H:\\")
    dlc.create_new_project(project_name, creator, vids, copy_vids=True)
    root = "C:/Users/viviani/Desktop/micepupils-viviani-2020-07-09/"
    config_path = root + "config.yaml"
    vid_dir = root + "videos/"
    vids = [vid_dir + file for file in os.listdir(vid_dir) if ".mp4" in file]
    with open(config_path, "w") as file:
        with open("config.yaml", "r") as source:
            for line in source:
                file.write(line)
    dlc.label_frames(config_path, vids)
    #Once frames are labelled, call dlc.create_training_dataset
    #and then dlc.train_network
Пример #24
0
import pandas as pd
import numpy as np

print("Imported DLC!")
basepath=os.path.dirname(os.path.abspath('DLC_Helper.py'))
# videoname='reachingvideo1'
# video=[os.path.join(basepath,'Reaching-Mackenzie-2018-08-30','videos',videoname+'.avi')]
videoname = input("What is the name of the video? *No need for file type like .mpg or .avi\n")
video = input("What is the full path of the video? *Include file type like .mpg or .avi\n")

#to test destination folder:
#dfolder=basepath
dfolder= input('What is the working directory?\n')

print("CREATING PROJECT")
path_config_file=deeplabcut.create_new_project(task,scorer,video,dfolder,copy_videos=True)

cfg=deeplabcut.auxiliaryfunctions.read_config(path_config_file)
cfg['numframes2pick']=5
cfg['pcutoff']=0.01
cfg['TrainingFraction']=[.8]
cfg['skeleton']=[['bodypart1','bodypart2'],['bodypart1','bodypart3']]

deeplabcut.auxiliaryfunctions.write_config(path_config_file,cfg)

print("EXTRACTING FRAMES")
deeplabcut.extract_frames(path_config_file,mode='automatic',userfeedback=False)

print("CREATING-SOME LABELS FOR THE FRAMES")
frames=os.listdir(os.path.join(cfg['project_path'],'labeled-data',videoname))
#As this next step is manual, we update the labels by putting them on the diagonal (fixed for all frames)
Пример #25
0
def create_pretrained_human_project(project,
                                    experimenter,
                                    videos,
                                    working_directory=None,
                                    copy_videos=False,
                                    videotype='.avi',
                                    createlabeledvideo=True,
                                    analyzevideo=True):
    """
    Creates a demo human project and analyzes a video with ResNet 101 weights pretrained on MPII Human Pose. This is from the DeeperCut paper by Insafutdinov et al. https://arxiv.org/abs/1605.03170 Please make sure to cite it too if you use this code!

    Parameters
    ----------
    project : string
        String containing the name of the project.

    experimenter : string
        String containing the name of the experimenter.

    videos : list
        A list of string containing the full paths of the videos to include in the project.

    working_directory : string, optional
        The directory where the project will be created. The default is the ``current working directory``; if provided, it must be a string.

    copy_videos : bool, optional
        If this is set to True, the videos are copied to the ``videos`` directory. If it is False,symlink of the videos are copied to the project/videos directory. The default is ``False``; if provided it must be either
        ``True`` or ``False``.
    analyzevideo " bool, optional
        If true, then the video is analzyed and a labeled video is created. If false, then only the project will be created and the weights downloaded. You can then access them

    Example
    --------
    Linux/MacOs
    >>> deeplabcut.create_pretrained_human_project('human','Linus',['/data/videos/mouse1.avi'],'/analysis/project/',copy_videos=False)

    Windows:
    >>> deeplabcut.create_pretrained_human_project('human','Bill',[r'C:\yourusername\rig-95\Videos\reachingvideo1.avi'],r'C:\yourusername\analysis\project' copy_videos=False)
    Users must format paths with either:  r'C:\ OR 'C:\\ <- i.e. a double backslash \ \ )
    --------
    """

    cfg = deeplabcut.create_new_project(project, experimenter, videos,
                                        working_directory, copy_videos,
                                        videotype)

    config = auxiliaryfunctions.read_config(cfg)
    config['bodyparts'] = [
        'ankle1', 'knee1', 'hip1', 'hip2', 'knee2', 'ankle2', 'wrist1',
        'elbow1', 'shoulder1', 'shoulder2', 'elbow2', 'wrist2', 'chin',
        'forehead'
    ]
    config['skeleton'] = [['ankle1', 'knee1'], ['ankle2', 'knee2'],
                          ['knee1', 'hip1'], ['knee2', 'hip2'],
                          ['hip1', 'hip2'], ['shoulder1', 'shoulder2'],
                          ['shoulder1', 'hip1'], ['shoulder2', 'hip2'],
                          ['shoulder1', 'elbow1'], ['shoulder2', 'elbow2'],
                          ['chin', 'forehead'], ['elbow1', 'wrist1'],
                          ['elbow2', 'wrist2']]
    config['default_net_type'] = 'resnet_101'
    auxiliaryfunctions.write_config(cfg, config)
    config = auxiliaryfunctions.read_config(cfg)

    train_dir = Path(
        os.path.join(
            config['project_path'],
            str(
                auxiliaryfunctions.GetModelFolder(
                    trainFraction=config['TrainingFraction'][0],
                    shuffle=1,
                    cfg=config)), 'train'))
    test_dir = Path(
        os.path.join(
            config['project_path'],
            str(
                auxiliaryfunctions.GetModelFolder(
                    trainFraction=config['TrainingFraction'][0],
                    shuffle=1,
                    cfg=config)), 'test'))

    # Create the model directory
    train_dir.mkdir(parents=True, exist_ok=True)
    test_dir.mkdir(parents=True, exist_ok=True)

    modelfoldername = auxiliaryfunctions.GetModelFolder(
        trainFraction=config['TrainingFraction'][0], shuffle=1, cfg=config)

    path_train_config = str(
        os.path.join(config['project_path'], Path(modelfoldername), 'train',
                     'pose_cfg.yaml'))
    path_test_config = str(
        os.path.join(config['project_path'], Path(modelfoldername), 'test',
                     'pose_cfg.yaml'))

    # Download the weights and put then in appropriate directory
    cwd = os.getcwd()
    os.chdir(train_dir)
    print(
        "Checking if the weights are already available, otherwise I will download them!"
    )
    weightfilename = auxfun_models.download_mpii_weigths(train_dir)
    os.chdir(cwd)

    # Create the pose_config.yaml files
    parent_path = Path(os.path.dirname(deeplabcut.__file__))
    defaultconfigfile = str(parent_path / 'pose_cfg.yaml')
    trainingsetfolder = auxiliaryfunctions.GetTrainingSetFolder(config)
    datafilename, metadatafilename = auxiliaryfunctions.GetDataandMetaDataFilenames(
        trainingsetfolder,
        trainFraction=config['TrainingFraction'][0],
        shuffle=1,
        cfg=config)
    bodyparts = config['bodyparts']
    net_type = 'resnet_101'
    num_shuffles = 1
    model_path, num_shuffles = auxfun_models.Check4weights(
        net_type, parent_path, num_shuffles)
    items2change = {
        "dataset": 'dataset-test.mat',  #datafilename,
        "metadataset": metadatafilename,
        "num_joints": len(bodyparts),
        "all_joints": [[i] for i in range(len(bodyparts))],
        "all_joints_names": [str(bpt) for bpt in bodyparts],
        "init_weights":
        weightfilename.split('.index')[0],  #'models/mpii/snapshot-1030000',
        "project_path": str(config['project_path']),
        "net_type": net_type,
        "dataset_type": "default"
    }
    trainingdata = MakeTrain_pose_yaml(items2change, path_train_config,
                                       defaultconfigfile)

    keys2save = [
        "dataset", "dataset_type", "num_joints", "all_joints",
        "all_joints_names", "net_type", 'init_weights', 'global_scale',
        'location_refinement', 'locref_stdev'
    ]
    MakeTest_pose_yaml(trainingdata, keys2save, path_test_config)

    video_dir = os.path.join(config['project_path'], 'videos')

    if analyzevideo == True:
        # Analyze the videos
        deeplabcut.analyze_videos(cfg, [video_dir],
                                  videotype,
                                  save_as_csv=True)
    if createlabeledvideo == True:
        deeplabcut.create_labeled_video(cfg, [video_dir],
                                        videotype,
                                        draw_skeleton=True)
        deeplabcut.plot_trajectories(cfg, [video_dir], videotype)
    return cfg, path_train_config
Пример #26
0
# NOTE: all MATLAB generated videos in this library have been recorded at ~500fps, but 
# were generated at ~150fps by MATLAB due to ffmpeg issues. This doesn't affect the outputs
# simply the generation of a time series vector later on.

training_videos = ['videos/2018_03_08_animal_1_video_1b.mp4',
                   'videos/2018_03_09_animal_3_video_2.mp4',
                   'videos/2019_01_07_animal_2.mp4',
                   'videos/2019_01_07_animal_3.mp4',
                   'videos/2019_01_07_animal_5.mp4'
                   ]

# Defining the working directory within the current directory. This will open a new folder for the project.
# All new training models, videos, and analyses will be carried out here.
# This also changes the current working directory (supposed to, not sure if happens in practice)

deeplabcut.create_new_project(task, sides, training_videos, working_directory='dlc-blinking',copy_videos=True)
path_config_file = '/dlc-blinking/blinking-lr-2019-02-07/config.yaml' # Enter the path of the config file that was just created from the above step (check the folder)

# if we plan on adding new videos to the project, we should use the following option:
#deeplabcut.add_new_videos(config_path,[‘full path of video X’, ‘full path of video X+1’],copy_videos=True/False)
#deeplabcut.add_new_videos(path_config_file,['videos/2019_01_07_animal_5.mp4'],copy_videos=True)

# Config file is now written.
# Go to config file for changing the bodyparts.
# As default we are monitoring both left-right eyes inner and outer points
# In addition, make sure the cropped frames for each video are correct indeed


# extracting frames, uniformly from the videos provided during setup. 
# Note, in versions 2.0.4 and earlier, please set opencv to False in case the extraction is not from 0 to 100
# but something in between.
import matplotlib
import tensorflow as tf

task='eyes_only' # Enter the name of your experiment Task
sides='lr-gpu' # Enter the name of the experimenter

training_videos = ['dlc-blinking/blinking-lr-2019-02-06/videos/2018_03_08_animal_1_video_1b.mp4',
                   'dlc-blinking/blinking-lr-2019-02-06/videos/2018_03_09_animal_3_video_2.mp4',
                   'dlc-blinking/blinking-lr-2019-02-06/videos/2019_01_07_animal_2.mp4',
                   'dlc-blinking/blinking-lr-2019-02-06/videos/2019_01_07_animal_3.mp4',
                   'dlc-blinking/blinking-lr-2019-02-06/videos/2019_01_07_animal_5.mp4'
                   ]

# video=['videos/animal_3_video_2_150fps_correct.mp4', 'videos/march_8_animal_1_video_150fps_correct.mp4'] # Enter the paths of your videos you want to grab frames from.

deeplabcut.create_new_project(task,sides,training_videos, working_directory='dlc-blinking',copy_videos=True) #change the working directory to where you want the folders created.

%matplotlib inline
path_config_file = '/dlc-blinking/an3_vid2_full/eyes_only-Guy-gpu-2019-01-29/config.yaml' # Enter the path of the config file that was just created from the above step (check the folder)
path_config_file = '/dlc-blinking/blinking-lr-2019-02-07/config.yaml' # Enter the path of the config file that was just created from the above step (check the folder)

deeplabcut.extract_frames(path_config_file,'automatic','uniform'),crop=True, checkcropping=True) #there are other ways to grab frames, such as by clustering 'kmeans'; please see the paper. 

# changed the cropping dimensions in the config.yaml file
%gui wx
deeplabcut.label_frames(path_config_file)

# Lables have now been created

deeplabcut.check_labels(path_config_file) #this creates a subdirectory with the frames + your labels
# Reviewed the labels, the seem to be ok
def cli_create_project(project_path,
                       video_paths,
                       name='eye_video_demo',
                       experimenter='experimenter',
                       recursive=False,
                       format_='mp4',
                       exclude=[],
                       num_frames=20,
                       train=False,
                       analyze=False,
                       create_videos=False):
    """run all steps to create a DLC project"""

    if len(video_paths) == 0:
        # use provided example
        video_files = [op.join(op.split(op.realpath(__file__))[0], 'data', 'example_eye_camera_video.mp4')]
    else:
        # get video files
        video_files = []
        for vp in list(video_paths):
            video_files.extend(get_video_files(vp, recursive, exclude,
                                               file_format=format_.lower()))

    # list all video files (and convert to mp4 if required)
    for i, vf in enumerate(video_files):
        print("found video file: %s" % vf)

        if op.splitext(vf)[1] == '.h264':
            vide_files[i] = convert_h264_to_mp4(vf)

    # create a new project
    config_path = deeplabcut.create_new_project(name, experimenter, video_files,
                                                working_directory=project_path,
                                                copy_videos=False)

    config = deeplabcut.utils.read_config(config_path)
    config['bodyparts'] = ['pupil_center', 'nasal_corner', 'temporal_corner']
    config['numframes2pick'] = num_frames
    deeplabcut.utils.write_config(config_path, config)

    # extract and label frames
    deeplabcut.extract_frames(config_path,
                              mode='automatic',
                              algo='kmeans',
                              crop=True)
    deeplabcut.label_frames(config_path)
    deeplabcut.check_labels(config_path)

    # create training dataset
    deeplabcut.create_training_dataset(config_path)

    if train:
        # train and evaluate the network
        deeplabcut.train_network(config_path)
        deeplabcut.evaluate_network(config_path)

        if analyze:
            deeplabcut.analyze_videos(config_path, video_files)

            if create_videos:
                # create a video
                deeplabcut.create_labeled_video(config_path, video_files)
Пример #29
0
Created on Mon Feb  4 16:26:09 2019

@author: gtsror
"""


# DLC Set up on blinking

import deeplabcut
import matplotlib

task='whisk_only' # Enter the name of your experiment Task
experimenter='Guy' # Enter the name of the experimenter
video=['videos/animal_3_video_2_150fps_correct.mp4', 'videos/crush_19_01_07_animal_3.mp4'] # Enter the paths of your videos you want to grab frames from.

deeplabcut.create_new_project(task,experimenter,video, working_directory='dlc-blinking/whisk',copy_videos=True) #change the working directory to where you want the folders created.

%matplotlib inline
path_config_file = '/dlc-blinking/whisk/whisk_only-Guy-2019-02-01/config.yaml' # Enter the path of the config file that was just created from the above step (check the folder)
deeplabcut.extract_frames(path_config_file,'automatic','uniform',crop=True, checkcropping=True, opencv=False) #there are other ways to grab frames, such as by clustering 'kmeans'; please see the paper. 


# changed the cropping dimensions in the config.yaml file
%gui wx
deeplabcut.label_frames(path_config_file)

# Lables have now been created

deeplabcut.check_labels(path_config_file) #this creates a subdirectory with the frames + your labels
# Reviewed the labels, the seem to be ok
Пример #30
0
def create_pretrained_project(
    project,
    experimenter,
    videos,
    model="full_human",
    working_directory=None,
    copy_videos=False,
    videotype=None,
    analyzevideo=True,
    filtered=True,
    createlabeledvideo=True,
    trainFraction=None,
):
    """
    Creates a new project directory, sub-directories and a basic configuration file.
    Change its parameters to your projects need.

    The project will also be initialized with a pre-trained model from the DeepLabCut model zoo!

    http://www.mousemotorlab.org/dlc-modelzoo

    Parameters
    ----------
    project : string
        String containing the name of the project.

    experimenter : string
        String containing the name of the experimenter.

    model: string, options see  http://www.mousemotorlab.org/dlc-modelzoo
        Current option and default: 'full_human'  Creates a demo human project and analyzes a video with ResNet 101 weights pretrained on MPII Human Pose. This is from the DeeperCut paper
        by Insafutdinov et al. https://arxiv.org/abs/1605.03170 Please make sure to cite it too if you use this code!

    videos : list
        A list of string containing the full paths of the videos to include in the project.

    working_directory : string, optional
        The directory where the project will be created. The default is the ``current working directory``; if provided, it must be a string.

    copy_videos : bool, optional  ON WINDOWS: TRUE is often necessary!
        If this is set to True, the videos are copied to the ``videos`` directory. If it is False,symlink of the videos are copied to the project/videos directory. The default is ``False``; if provided it must be either
        ``True`` or ``False``.

    analyzevideo " bool, optional
        If true, then the video is analzyed and a labeled video is created. If false, then only the project will be created and the weights downloaded. You can then access them

    filtered: bool, default false
        Boolean variable indicating if filtered pose data output should be plotted rather than frame-by-frame predictions.
        Filtered version can be calculated with deeplabcut.filterpredictions

    trainFraction: By default value from *new* projects. (0.95)
            Fraction that will be used in dlc-model/trainingset folder name.

    Example
    --------
    Linux/MacOs loading full_human model and analzying video /homosapiens1.avi
    >>> deeplabcut.create_pretrained_project('humanstrokestudy','Linus',['/data/videos/homosapiens1.avi'], copy_videos=False)

    Loading full_cat model and analzying video "felixfeliscatus3.avi"
    >>> deeplabcut.create_pretrained_project('humanstrokestudy','Linus',['/data/videos/felixfeliscatus3.avi'], model='full_cat')

    Windows:
    >>> deeplabcut.create_pretrained_project('humanstrokestudy','Bill',[r'C:\yourusername\rig-95\Videos\reachingvideo1.avi'],r'C:\yourusername\analysis\project' copy_videos=True)
    Users must format paths with either:  r'C:\ OR 'C:\\ <- i.e. a double backslash \ \ )

    """
    if model in globals()["Modeloptions"]:
        cwd = os.getcwd()

        cfg = deeplabcut.create_new_project(project, experimenter, videos,
                                            working_directory, copy_videos,
                                            videotype)
        if trainFraction is not None:
            auxiliaryfunctions.edit_config(
                cfg, {"TrainingFraction": [tranFraction]})

        config = auxiliaryfunctions.read_config(cfg)
        if model == "full_human":
            config["bodyparts"] = [
                "ankle1",
                "knee1",
                "hip1",
                "hip2",
                "knee2",
                "ankle2",
                "wrist1",
                "elbow1",
                "shoulder1",
                "shoulder2",
                "elbow2",
                "wrist2",
                "chin",
                "forehead",
            ]
            config["skeleton"] = [
                ["ankle1", "knee1"],
                ["ankle2", "knee2"],
                ["knee1", "hip1"],
                ["knee2", "hip2"],
                ["hip1", "hip2"],
                ["shoulder1", "shoulder2"],
                ["shoulder1", "hip1"],
                ["shoulder2", "hip2"],
                ["shoulder1", "elbow1"],
                ["shoulder2", "elbow2"],
                ["chin", "forehead"],
                ["elbow1", "wrist1"],
                ["elbow2", "wrist2"],
            ]
            config["default_net_type"] = "resnet_101"
        else:  # just make a case and put the stuff you want.
            # TBD: 'partaffinityfield_graph' >> use to set skeleton!
            pass

        auxiliaryfunctions.write_config(cfg, config)
        config = auxiliaryfunctions.read_config(cfg)

        train_dir = Path(
            os.path.join(
                config["project_path"],
                str(
                    auxiliaryfunctions.GetModelFolder(
                        trainFraction=config["TrainingFraction"][0],
                        shuffle=1,
                        cfg=config,
                    )),
                "train",
            ))
        test_dir = Path(
            os.path.join(
                config["project_path"],
                str(
                    auxiliaryfunctions.GetModelFolder(
                        trainFraction=config["TrainingFraction"][0],
                        shuffle=1,
                        cfg=config,
                    )),
                "test",
            ))

        # Create the model directory
        train_dir.mkdir(parents=True, exist_ok=True)
        test_dir.mkdir(parents=True, exist_ok=True)

        modelfoldername = auxiliaryfunctions.GetModelFolder(
            trainFraction=config["TrainingFraction"][0], shuffle=1, cfg=config)
        path_train_config = str(
            os.path.join(config["project_path"], Path(modelfoldername),
                         "train", "pose_cfg.yaml"))
        path_test_config = str(
            os.path.join(config["project_path"], Path(modelfoldername), "test",
                         "pose_cfg.yaml"))

        # Download the weights and put then in appropriate directory
        print("Dowloading weights...")
        auxfun_models.DownloadModel(model, train_dir)

        pose_cfg = deeplabcut.auxiliaryfunctions.read_plainconfig(
            path_train_config)
        print(path_train_config)
        # Updating config file:
        dict = {
            "default_net_type": pose_cfg["net_type"],
            "default_augmenter": pose_cfg["dataset_type"],
            "bodyparts": pose_cfg["all_joints_names"],
            "skeleton": [],  # TODO: update with paf_graph
            "dotsize": 6,
        }
        auxiliaryfunctions.edit_config(cfg, dict)

        # Create the pose_config.yaml files
        parent_path = Path(os.path.dirname(deeplabcut.__file__))
        defaultconfigfile = str(parent_path / "pose_cfg.yaml")
        trainingsetfolder = auxiliaryfunctions.GetTrainingSetFolder(config)
        datafilename, metadatafilename = auxiliaryfunctions.GetDataandMetaDataFilenames(
            trainingsetfolder,
            trainFraction=config["TrainingFraction"][0],
            shuffle=1,
            cfg=config,
        )

        # downloading base encoder / not required unless on re-trains (but when a training set is created this happens anyway)
        # model_path, num_shuffles=auxfun_models.Check4weights(pose_cfg['net_type'], parent_path, num_shuffles= 1)

        # Updating training and test pose_cfg:
        snapshotname = [fn for fn in os.listdir(train_dir)
                        if ".meta" in fn][0].split(".meta")[0]
        dict2change = {
            "init_weights": str(os.path.join(train_dir, snapshotname)),
            "project_path": str(config["project_path"]),
        }

        UpdateTrain_pose_yaml(pose_cfg, dict2change, path_train_config)
        keys2save = [
            "dataset",
            "dataset_type",
            "num_joints",
            "all_joints",
            "all_joints_names",
            "net_type",
            "init_weights",
            "global_scale",
            "location_refinement",
            "locref_stdev",
        ]

        MakeTest_pose_yaml(pose_cfg, keys2save, path_test_config)

        video_dir = os.path.join(config["project_path"], "videos")
        if analyzevideo == True:
            print("Analyzing video...")
            deeplabcut.analyze_videos(cfg, [video_dir],
                                      videotype,
                                      save_as_csv=True)

        if createlabeledvideo == True:
            if filtered:
                deeplabcut.filterpredictions(cfg, [video_dir], videotype)

            print("Plotting results...")
            deeplabcut.create_labeled_video(cfg, [video_dir],
                                            videotype,
                                            draw_skeleton=True,
                                            filtered=filtered)
            deeplabcut.plot_trajectories(cfg, [video_dir],
                                         videotype,
                                         filtered=filtered)

        os.chdir(cwd)
        return cfg, path_train_config

    else:
        return "N/A", "N/A"