Beispiel #1
0
def generatetempyaml(yamlfile,videolist):
    try:
        #copy yaml and rename
        tempyaml = os.path.dirname(yamlfile) +'\\temp.yaml'
        shutil.copy(yamlfile,tempyaml)

        #adding new videos to tempyaml
        deeplabcut.add_new_videos(tempyaml,[videolist],copy_videos=True)

        with open(tempyaml) as f:
            read_yaml = yaml.load(f, Loader=yaml.FullLoader)

        original_videosets = read_yaml['video_sets'].keys()

        keys=[]
        for i in original_videosets:
            keys.append(i)
        #remove the original video to get only newly added videos
        read_yaml['video_sets'].pop(keys[0],None)

        with open(tempyaml, 'w') as outfile:
            yaml.dump(read_yaml, outfile, default_flow_style=False)

        print('temp.yaml generated.')
    except FileNotFoundError:
        print('Please select a video file.')
 def add_videos(self, event):
     print("adding new videos to be able to label ...")
     self.cfg = self.sel_config.GetPath()
     if len(self.filelistnew) > 0:
         self.filelistnew = self.filelistnew + self.addvids
         deeplabcut.add_new_videos(self.cfg, self.filelistnew)
     else:
         print(
             "Please select videos to add first. Click 'Load New Videos'..."
         )
Beispiel #3
0
def video_upload(projectId):
    config_path = projectRepository.find_one({'_id': ObjectId(projectId)
                                              })['config_path']
    if 'file' not in request.files:
        return "No file was sent"
    project_path = projectRepository.find_one(
        {'_id': ObjectId(projectId)})['config_path'][0:-11] + 'videos/'
    file = request.files['file']
    filename = secure_filename(file.filename)
    video_path = os.path.join(project_path, filename)
    file.save(video_path)
    deeplabcut.add_new_videos(config_path, [video_path])
    return "Video uploaded"  #TODO: Return real response
        def clicked_add():

            self.load_an_exsiting_project(window)
            window.destroy()
            self.select_body_parts()
            self.add_new_videos()
            # for item in self.video_list:
            #     if len(item) < 2:
            #         self.video_list.remove(item)
            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()
        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()
Beispiel #6
0
def generatetempyaml_multi(yamlfile, videolist):

    #copy yaml and rename
    tempyaml = os.path.dirname(yamlfile) + '\\temp.yaml'
    shutil.copy(yamlfile, tempyaml)

    deeplabcut.add_new_videos(tempyaml, videolist, copy_videos=True)

    with open(tempyaml) as f:
        read_yaml = yaml.load(f, Loader=yaml.FullLoader)

    original_videosets = read_yaml['video_sets'].keys()

    keys = []
    for i in original_videosets:
        keys.append(i)

    read_yaml['video_sets'].pop(keys[0], None)

    with open(tempyaml, 'w') as outfile:
        yaml.dump(read_yaml, outfile, default_flow_style=False)
Beispiel #7
0
import deeplabcut as dlc
import json
import helpers

with open('config.json', 'r') as fp:
    config = json.load(fp)

path_config_file = config["path_config_file"]

# get full path here
video_full_paths = helpers.get_video_full_paths()

dlc.add_new_videos(path_config_file, video_full_paths)
Beispiel #8
0
def usingDeep(path_config, project):
    exit = False
    while exit == False:
        video_path = path_config.split("/")
        video_path = '/' + video_path[1] + '/' + video_path[
            2] + '/' + video_path[3] + '/' + video_path[4] + '/videos/'
        print_usage("project")
        action = input()
        while action not in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]:
            try:
                action = int(action)
                if action not in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]:
                    print("please type number between 0 and 12")
                    action = input()
            except ValueError:
                print("Please enter number")
                action = input()
            print("been here")
        if action == 0:
            return False
        elif action == 1:
            print("do you want to crop the video? yes/no")
            if input() == "yes" or "y":
                print(
                    "how many videos you you want to crop? (use number: 1,2,3 etc)"
                )
                crops = int(input())
                print("only crop all the video's and than exit")
                for loop in range(0, crops):
                    deeplabcut.extract_frames(path_config,
                                              'manual',
                                              'kmeans',
                                              crop=True)
            deeplabcut.extract_frames(path_config,
                                      'automatic',
                                      'kmeans',
                                      crop=True)
        elif action == 2:
            deeplabcut.label_frames(path_config)
        elif action == 3:
            deeplabcut.check_labels(path_config)
        elif action == 4:
            deeplabcut.create_training_dataset(path_config)
        elif action == 5:
            with open("training_network.py") as fp:
                lines = fp.readlines()
                lines[3] = lines[3].split("=")
                lines[3] = lines[3][0] + "= '" + path_config + "'\n"

            with open("training_network.py", "w") as fp:
                for line in lines:
                    fp.writelines(line)

            print("run: sbatch slurm.sh")
            return True
        elif action == 6:
            try:
                deeplabcut.evaluate_network(path_config,
                                            Shuffles=[1],
                                            trainingsetindex=0,
                                            plotting=None,
                                            show_errors=True,
                                            comparisonbodyparts='all',
                                            gputouse=None,
                                            rescale=False)
            except OSError as e:
                print("file does not exist")
        elif action == 7:
            print("\nType video name in project/videos you want to analyze")
            video_path = video_path + create_dict_list(
                path_config[:-11] + "videos/", 1)[0]
            with open("training_network.py") as fp:
                lines = fp.readlines()
                lines[3] = lines[3].split("=")
                lines[3] = lines[3][0] + "= '" + path_config + "'\n"
                lines[4] = lines[4].split("=")
                lines[4] = lines[4][0] + "= '" + video_path + "'\n"

            with open("training_network.py", "w") as fp:
                for line in lines:
                    fp.writelines(line)
            print(
                "run: sbatch slurm.sh after changing the command in training_network.py"
            )
            return True
        elif action == 8:
            print(
                "\nChoose the video in project/videos you want to plot trajectories from"
            )
            video_path = video_path + create_dict_list(
                path_config[:-11] + "videos/", 1)[0]
            print(video_path)
            deeplabcut.plot_trajectories(path_config, [video_path],
                                         filtered=True)
        elif action == 9:
            print(
                "\nChoose the video in project/videos you want to make a labeled video from"
            )
            video_path = video_path + create_dict_list(
                path_config[:-11] + "videos/", 1)[0]
            deeplabcut.create_labeled_video(path_config, [video_path],
                                            videotype='.mp4',
                                            draw_skeleton=True)
        elif action == 10:
            print("\nChoose where to upload the video from")
            video_path = '/data/11012579/videos/' + create_dict_list(
                '/data/11012579/videos/', 0)[0]
            print("\nChoose which video to upload")
            video_path_list = [
                video_path + "/" + create_dict_list(video_path, 1)[0]
            ]
            while True:
                print("\nDo you want to add more videos?\nType yes or no")
                if input() == 'yes':
                    video_path_list.append(video_path + "/" +
                                           create_dict_list(video_path, 1)[0])
                else:
                    deeplabcut.add_new_videos(path_config,
                                              video_path_list,
                                              copy_videos=False)
                    break
        elif action == 11:
            print("also here")
            Dlc_results2 = pd.read_hdf(
                '/data/11012579/videos/vidDLC_resnet50_demo_project_grab2Feb7shuffle1_11500.h5'
            )
            Dlc_results2.plot()
        else:
            print_usage("error")

        print("klaar")
    # "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
    - foreleg_joint
    - foreleg_body_jonction
    - hindlepaw
    - hindleleg_joint
Beispiel #10
0
##basic code to run deeplabcut##
#https://github.com/AlexEMG/DeepLabCut/blob/master/docs/functionDetails.md#g-train-the-network#

import deeplabcut
import os, yaml
from pathlib import Path

##once#create the project, set working directory for videos, and find videos
deeplabcut.create_new_project('name_of_project','author', ['path_to_video.avi' ], working_directory='path_to_folder', copy_videos=False) 

#specify path to config.yaml
####change yaml for the project
config_path = 'copy the path to the created yaml file here.yaml'

##opt# add more videos
deeplabcut.add_new_videos(config_path, [video_directory], copy_videos=False)

#data selection (auto)
deeplabcut.extract_frames(config_path,'automatic','uniform', crop=False, checkcropping=False)

##opt#extract data frames by hand
deeplabcut.extract_frames(config_path,'manual')

#label frames
deeplabcut.label_frames(config_path)

##opt#check annotated frames
deeplabcut.check_labels(config_path)

#create training dataset
deeplabcut.create_training_dataset(config_path,num_shuffles=1)
Beispiel #11
0
# %%

import os
import deeplabcut as dlc

# %%
dlc_config_file = "D:\\Dropbox (UCL - SWC)\\Project_vgatPAG\\code\\DLC\\vgatPAG-federico-2020-02-25\\config.yaml"
dlc_fld = "D:\\Dropbox (UCL - SWC)\\Project_vgatPAG\\code\\DLC"

# %%
clips = [
    os.path.join(dlc_fld, v) for v in os.listdir(dlc_fld)
    if 'clip' in v and 'cam' not in v
]
dlc.add_new_videos(dlc_config_file, clips, copy_videos=True)