deeplabcut.analyze_videos(path_config_file, [newvideo],
                          save_as_csv=True,
                          destfolder=dfolder)

print("CREATE VIDEO")
deeplabcut.create_labeled_video(path_config_file, [newvideo],
                                destfolder=dfolder)

print("Making plots")
deeplabcut.plot_trajectories(path_config_file, [newvideo], destfolder=dfolder)

print("EXTRACT OUTLIERS")
deeplabcut.extract_outlier_frames(path_config_file, [newvideo],
                                  outlieralgorithm='jump',
                                  epsilon=0,
                                  automatic=True,
                                  destfolder=dfolder)

file = os.path.join(cfg['project_path'], 'labeled-data', vname,
                    "machinelabels-iter" + str(cfg['iteration']) + '.h5')

print("RELABELING")
DF = pd.read_hdf(file, 'df_with_missing')
DLCscorer = np.unique(DF.columns.get_level_values(0))[0]
DF.columns.set_levels([scorer.replace(DLCscorer, scorer)],
                      level=0,
                      inplace=True)
DF = DF.drop('likelihood', axis=1, level=2)
DF.to_csv(
    os.path.join(cfg['project_path'], 'labeled-data', vname,
        "mp4",
        save_frames=False,
        color_by="individual",
        track_method="transformer",
    )
    print("Labeled video created.")

    print("Filtering predictions...")
    deeplabcut.filterpredictions(
        config_path, [new_video_path], "mp4", track_method=TESTTRACKER
    )
    print("Predictions filtered.")

    print("Extracting outlier frames...")
    deeplabcut.extract_outlier_frames(
        config_path, [new_video_path], "mp4", automatic=True, track_method=TESTTRACKER
    )
    print("Outlier frames extracted.")

    vname = Path(new_video_path).stem

    file = os.path.join(
        cfg["project_path"],
        "labeled-data",
        vname,
        "machinelabels-iter" + str(cfg["iteration"]) + ".h5",
    )

    """
    print("RELABELING")
    DF = pd.read_hdf(file, "df_with_missing")
示例#3
0
# evaluate the trained network
#dlc.evaluate_network(config_path, plotting=True)

full_path_to_videos = []
root = 'add your path'
for path in videos:
    full_path_to_videos.append(root + '/' + path)

# video analysis and plotting results
dlc.analyze_videos(config_path,
                   full_path_to_videos,
                   shuffle=1,
                   save_as_csv=False,
                   videotype='.mp4')
dlc.filterpredictions(config_path,
                      full_path_to_videos,
                      shuffle=1,
                      save_as_csv=True,
                      videotype='.mp4')

videoCreate = ["add your videos"]
dlc.create_labeled_video(config_path, videoCreate, filtered=True)

# refine videos
refineVideos = ["add your videos"]
dlc.extract_outlier_frames(config_path, refineVideos, outlieralgorithm='jump')
dlc.refine_labels(config_path)
dlc.merge_datasets(config_path)
# then, back to "create_training_dataset()"
 also be due to occlusions rather than errors);
 ● Select frames in which a particular body part or all body parts jumped more than epsilon pixels
 from the last frame;
 ● Select frames if the predicted body part location deviates from a state-space model
 fit to the time series of individual body parts. Specifically, this method fits an AutoRegressive Integrated
 Moving Average (ARIMA) model to the time series for each body part. Thereby, each body part
 detection with a likelihood smaller than p bound is treated as missing data. An example fit for one
 body part can be found in Fig. 6a. Putative outlier frames are then identified as time points, at
 which the average body part estimates are at least epsilon pixels away from the fits. The
 parameters of this method are epsilon, p bound , the ARIMA parameters, and the list of body parts
 to consider (can also be ‘all’).
 """
 if "step_14" in stages_to_run or "extract_outlier_frames" in stages_to_run:
     deeplabcut.extract_outlier_frames(config_path, videos_to_extract_outlier_frames, videotype='avi',
                                       shuffle=1, trainingsetindex=0, outlieralgorithm='jump',
                                       comparisonbodyparts='all', epsilon=50, p_bound=.01, ARdegree=3,
                                       MAdegree=1, alpha=.01, extractionalgorithm='kmeans' ,automatic=False,
                                       cluster_resizewidth=30, cluster_color=False, opencv=True, savelabeled=True,
                                       destfolder=None)
 """
 This step has many parameters that can be set.
 
 In general, depending on the parameters, these methods might return many more frames than the
 user wants to extract (numframes2pick). Thus, this list is then used to select outlier frames
 either by randomly sampling from this list (‘uniform’) or by performing ‘k-means’ clustering on the
 corresponding frames (same methodology and parameters as in Step 4). Furthermore, before this
 second selection happens, you are informed about the number of frames satisfying the criteria and
 asked if the selection should proceed. This step allows you to perhaps change the parameters of the
 frame-selection heuristics first. The extract_outlier_frames command can be run
 iteratively and can (even) extract additional frames from the same video. Once enough outlier
 frames are extracted, use the refinement GUI to adjust the labels based on any user feedback.
 
示例#5
0
import deeplabcut
import tensorflow as tf

'''deeplabcut.create_new_project('1_2_4_chamber','MC',['C:\\Users\\analysis\\Desktop\\Mingran\\analysed_trimmed_data\\BRAC3477.2b\\05_08_2019\\BRAC34772b top_left 05_08_2019 12_40_54 1_trimmed.mp4'],
working_directory='C:\\Users\\analysis\\Desktop')'''

videopath =['C:\\Users\\analysis\\Desktop\\Mingran\\analysed_trimmed_data\\BRAC3477.2b\\13_08_2019\\BRAC34772b top_right 13_08_2019 14_39_52 2_trimmed.mp4',
'C:\\Users\\analysis\\Desktop\\Mingran\\analysed_trimmed_data\\BRAC3583.3e\\23_07_2019\\BRAC35833e 23_07_2019 13_35_06 4_trimmed.mp4',
'C:\\Users\\analysis\\Desktop\\Mingran\\analysed_trimmed_data\\BRAC3616.3c\\23_07_2019\\BRAC36163c 23_07_2019 12_41_11 3_trimmed.mp4']
config = 'C:\\Users\\analysis\\Desktop\\1_2_4_chamber-MC-2019-08-23\\config.yaml'


'''deeplabcut.add_new_videos(config,videopath)
deeplabcut.extract_frames(config,'automatic','kmeans')'''
deeplabcut.label_frames(config)

deeplabcut.check_labels(config)
deeplabcut.create_training_dataset(config)
deeplabcut.train_network(config)


deeplabcut.extract_outlier_frames(config,videopath)
deeplabcut.refine_labels(config)
deeplabcut.merge_datasets(config)
deeplabcut.create_training_dataset(config)
deeplabcut.train_network(config)
示例#6
0
        print("Making plots")
        deeplabcut.plot_trajectories(
            path_config_file,
            [newvideo],
            shuffle=shuffle,
            destfolder=dfolder,
            videotype="avi",
        )

        print("EXTRACT OUTLIERS")
        deeplabcut.extract_outlier_frames(
            path_config_file,
            [newvideo],
            shuffle=shuffle,
            outlieralgorithm="jump",
            epsilon=0,
            automatic=True,
            destfolder=dfolder,
            videotype="avi",
        )
        file = os.path.join(
            cfg["project_path"],
            "labeled-data",
            vname,
            "machinelabels-iter" + str(cfg["iteration"]) + ".h5",
        )

        print("RELABELING")
        DF = pd.read_hdf(file, "df_with_missing")
        DLCscorer = np.unique(DF.columns.get_level_values(0))[0]
        DF.columns.set_levels([scorer.replace(DLCscorer, scorer)],
示例#7
0
print("Creating labeled video...")
deeplabcut.create_labeled_video(
    config_path,
    [new_video_path],
    "mov",
    save_frames=False,
    color_by="individual",
    track_method="box",
)
deeplabcut.create_labeled_video(
    config_path,
    [new_video_path],
    "mov",
    save_frames=False,
    color_by="bodypart",
    track_method="skeleton",
)
print("Labeled video created.")

print("Filtering predictions...")
deeplabcut.filterpredictions(config_path, [new_video_path], "mov", track_method="box")
print("Predictions filtered.")

print("Extracting outlier frames...")
deeplabcut.extract_outlier_frames(
    config_path, [new_video_path], "mov", automatic=True, track_method="box"
)
print("Outlier frames extracted.")

print("ALL DONE!!! - default multianimal cases are functional.")
示例#8
0
                              destfolder=DESTFOLDER)

    print("CREATE VIDEO")
    deeplabcut.create_labeled_video(path_config_file, [newvideo],
                                    destfolder=DESTFOLDER,
                                    save_frames=True)

    print("Making plots")
    deeplabcut.plot_trajectories(path_config_file, [newvideo],
                                 destfolder=DESTFOLDER)

    print("EXTRACT OUTLIERS")
    deeplabcut.extract_outlier_frames(
        path_config_file,
        [newvideo],
        outlieralgorithm="jump",
        epsilon=0,
        automatic=True,
        destfolder=DESTFOLDER,
    )

    deeplabcut.extract_outlier_frames(
        path_config_file,
        [newvideo],
        outlieralgorithm="fitting",
        automatic=True,
        destfolder=DESTFOLDER,
    )

    file = os.path.join(
        cfg["project_path"],
        "labeled-data",
示例#9
0
def dlc2nems(siteid=None,
             vids=None,
             suffix=".lick.avi",
             site_path="/auto/data/daq/Clathrus/CLT011/",
             path_config='/auto/data/dlc/multivid-CLL-2022-01-14/config.yaml'):

    #change path_config if using a different DLC model
    if siteid is not None:
        dfiles = db.pd_query(
            f"SELECT * FROM gDataRaw WHERE not(bad) AND cellid='{siteid}'")
        site_path = dfiles.at[0, 'resppath']
    elif site_path is None:
        raise ValueError("siteid or site_path required.")

    if vids is None:
        vids = []
        # get list of all videos in site folder if no vids given as input
        for f in os.listdir(site_path):
            if f.endswith(
                    suffix):  #non-compressed vids end in lick.original.avi
                vids.append(f)

    path_sorted = os.path.join(site_path, 'sorted')

    if not os.path.exists(path_sorted):
        os.makedirs(path_sorted)
        print('Created sorted directory in', site_path)

    print('Number of videos to be analyzed:', len(vids))
    print('Results will be saved in:', path_sorted)

    vid_paths = [os.path.join(site_path, v) for v in vids]
    output_aliased = [
        os.path.join(path_sorted, v.replace(".avi", ".dlc.h5")) for v in vids
    ]
    if 1:
        dlc.analyze_videos(path_config,
                           vid_paths,
                           videotype='avi',
                           destfolder=path_sorted)

        for v, a in zip(vids, output_aliased):
            # Get list of all files only in the given directory
            list_of_files = filter(
                os.path.isfile,
                glob.glob(
                    os.path.join(path_sorted, v.replace(".avi", "")) + '*.h5'))
            # Sort list of files based on last modification time in ascending order
            list_of_files = sorted(list_of_files, key=os.path.getmtime)
            if not os.path.exists(a):
                os.system(f"ln -s {list_of_files[-1]} {a}")

    if 0:
        dlc.create_labeled_video(path_config,
                                 vid_paths,
                                 videotype='avi',
                                 destfolder=path_sorted)

    if 0:
        # identify "bad" frames and save in training set
        dlc.extract_outlier_frames(path_config,
                                   vid_paths,
                                   destfolder=path_sorted,
                                   automatic=True)

        # gui to relabel the bad frames
        dlc.refine_labels(path_config)

    if 0:
        dlc.merge_datasets(path_config)
        dlc.create_training_dataset(path_config,
                                    net_type='resnet_50',
                                    augmenter_type='imgaug')

    if 0:
        # before running, update pose_cfg.yaml to use last snapshot from previous iteration as initial condition
        # (rather than starting over from visnet)
        dlc.train_network(path_config, shuffle=1, displayiters=100)
示例#10
0
            # Sort list of files based on last modification time in ascending order
            list_of_files = sorted( list_of_files,
                                    key = os.path.getmtime)

            os.system(f"ln -s {list_of_files[-1]} {a}")

    if 'video' in action_list:
        log.info('Creating labeled video')
        dlc.create_labeled_video(path_config, vid_paths, videotype='avi', destfolder=path_sorted)

    if 'summary' in action_list:
        face_tools.summary_plot(vid_paths)

    if 'refine' in action_list:
        # identify "bad" frames and save in training set
        dlc.extract_outlier_frames(path_config, vid_paths, destfolder=path_sorted, automatic=True)

        # gui to relabel the bad frames
        dlc.refine_labels(path_config)

    if 0:
        dlc.merge_datasets(path_config)
        dlc.create_training_dataset(path_config, net_type='resnet_50', augmenter_type='imgaug')

    if 0:
        # before running, update pose_cfg.yaml to use last snapshot from previous iteration as initial condition
        # (rather than starting over from visnet)
        dlc.train_network(path_config, shuffle=1, displayiters=100)

    log.info("face_fit_script complete")
示例#11
0
print("'dlc.__version__' is:'", dlc.__version__)
print("\n")
print("This is the name of the program:", sys.argv[0])
print("str(sys.argv):", str(sys.argv), "\n")
print("\n")
print("\n")

edits = {'snapshotindex': snapshotindex, 'numframestopick': nframes}
print('\nediting the config file... ')
for item in edits.items():
    print(item)
dlc.auxiliaryfunctions.edit_config(config_path, edits)
print('edit completed!')

dlc.extract_outlier_frames(config=config_path,
                           videos=videos_path_list,
                           videotype='.mp4',
                           shuffle=shuffleindex,
                           trainingsetindex=0,
                           outlieralgorithm=outlieralgorithm,
                           epsilon=epsilon,
                           automatic='True',
                           extractionalgorithm=extractionalgorithm)

print("dlc_extract_outlier_frames with the call", str(sys.argv), "is done!")

print("returning snapshotindex back to 'all'...!")
edits = {'snapshotindex': 'all'}
dlc.auxiliaryfunctions.edit_config(config_path, edits)
print("snapshotindex is set back to 'all'")