Beispiel #1
0
 def cross_validate(self, event):
     trainingsetindex = self.trainingset.GetValue()
     shuffle = [self.shuffles.GetValue()]
     cfg = auxiliaryfunctions.read_config(self.config)
     trainFraction = cfg["TrainingFraction"][trainingsetindex]
     self.inf_cfg_path = os.path.join(
         cfg["project_path"],
         auxiliaryfunctions.GetModelFolder(trainFraction,
                                           self.shuffles.GetValue(), cfg),
         "test",
         "inference_cfg.yaml",
     )
     # Read from edited inf. file first ...
     print(self.inf_cfg_path)
     print("optimizing parameters using " + self.targettypes.GetValue() +
           " as a target...")
     deeplabcut.evaluate_multianimal_crossvalidate(
         self.config,
         Shuffles=shuffle,
         trainingsetindex=trainingsetindex,
         edgewisecondition=self.edgeWise.GetStringSelection(),
         leastbpts=self.infg.GetValue(),
         init_points=self.inpts.GetValue(),
         n_iter=self.n_iter.GetValue(),
         target=self.targettypes.GetValue(),
     )
        "global_scale": 0.5,
        "batch_size": 1,
        "save_iters": N_ITER,
        "display_iters": N_ITER // 2,
        # "multi_step": [[0.001, N_ITER]],
    }
    deeplabcut.auxiliaryfunctions.edit_config(pose_config_path, edits)
    print("Pose config edited.")

    print("Training network...")
    deeplabcut.train_network(config_path, maxiters=N_ITER)
    print("Network trained.")

    print("Evaluating network...")
    deeplabcut.evaluate_network(config_path, plotting=True)
    deeplabcut.evaluate_multianimal_crossvalidate(
        config_path, n_iter=8, init_points=3)  # parameters so it is fast

    print("Network evaluated....")

    new_video_path = deeplabcut.ShortenVideo(
        video_path,
        start="00:00:00",
        stop="00:00:01",
        outsuffix="short",
        outpath=os.path.join(cfg["project_path"], "videos"),
    )

    print("Analyzing video...")
    deeplabcut.analyze_videos(config_path, [new_video_path],
                              "mp4",
                              robust_nframes=True)