Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
clip = VideoFileClip(video[0])
clip.reader.initialize()
def make_frame(t):
return clip.get_frame(1)
newclip = VideoClip(make_frame, duration=1)
newclip.write_videofile(newvideo,fps=30)
deeplabcut.analyze_videos(path_config_file,[newvideo],save_as_csv=True, destfolder=dfolder, dynamic=(True,.1,5))
print("analyze again...")
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,save_frames=True)
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,"CollectedData_" + scorer + ".csv"))
DF.to_hdf(os.path.join(cfg['project_path'],'labeled-data',vname,"CollectedData_" + scorer + '.h5'),'df_with_missing',format='table', mode='w')
for shuffle in [2,3]:
print("TRAIN NETWORK", shuffle)
deeplabcut.train_network(path_config_file, shuffle=shuffle,saveiters=10000,displayiters=200,maxiters=5,max_snapshots_to_keep=11)
print("EVALUATE")
deeplabcut.evaluate_network(path_config_file, Shuffles=[shuffle],plotting=True)
print("Analyze Video")
videofile_path = os.path.join(os.getcwd(),'openfield-Pranav-2018-10-30','videos','m3v1mp4.mp4')
deeplabcut.analyze_videos(path_config_file,[videofile_path], shuffle=shuffle)
print("Create Labeled Video and plot")
deeplabcut.create_labeled_video(path_config_file,[videofile_path], shuffle=shuffle)
deeplabcut.plot_trajectories(path_config_file,[videofile_path], shuffle=shuffle)
#this is much easier now: deeplabcut.train_network(path_config_file,gputouse=0,max_snapshots_to_keep=None,saveiters=1)
print("EVALUATE")
deeplabcut.evaluate_network(path_config_file,plotting=True)
print("CUT SHORT VIDEO AND ANALYZE")
# Make super short video (so the analysis is quick!)
vname='brief'
newvideo=os.path.join(cfg['project_path'],'videos',vname+'.avi')
subprocess.call(['ffmpeg','-i',video[0],'-ss','00:00:00','-to','00:00:00.4','-c','copy',newvideo])
deeplabcut.analyze_videos(path_config_file,[newvideo])
print("CREATE VIDEO")
deeplabcut.create_labeled_video(path_config_file,[newvideo])
print("EXTRACT OUTLIERS")
deeplabcut.extract_outlier_frames(path_config_file,[newvideo],outlieralgorithm='jump',epsilon=0,automatic=True)
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,"CollectedData_" + scorer + ".csv"))
DF.to_hdf(os.path.join(cfg['project_path'],'labeled-data',vname,"CollectedData_" + scorer + '.h5'),'df_with_missing',format='table', mode='w')
print("MERGING")
def make_frame(t):
return clip.get_frame(1)
newclip = VideoClip(make_frame, duration=1)
newclip.write_videofile(newvideo2,fps=30)
print("Inference with direct cropping")
deeplabcut.analyze_videos(path_config_file,[newvideo2],destfolder=dfolder,cropping=[0,50,0,50],save_as_csv=True)
print("Extracting skeleton distances, filter and plot filtered output")
deeplabcut.analyzeskeleton(path_config_file, [newvideo], save_as_csv=True, destfolder=dfolder)
deeplabcut.filterpredictions(path_config_file,[newvideo])
#deeplabcut.create_labeled_video(path_config_file,[newvideo], destfolder=dfolder,filtered=True)
deeplabcut.create_labeled_video(path_config_file,[newvideo2], destfolder=dfolder,displaycropped=True,filtered=True)
deeplabcut.plot_trajectories(path_config_file,[newvideo2], destfolder=dfolder,filtered=True)
print("CREATING TRAININGSET for shuffle 2")
print("will be used for 3D testscript...")
deeplabcut.create_training_dataset(path_config_file,Shuffles=[2],net_type=net_type,augmenter_type=augmenter_type3)
posefile=os.path.join(cfg['project_path'],'dlc-models/iteration-'+str(cfg['iteration'])+'/'+ cfg['Task'] + cfg['date'] + '-trainset' + str(int(cfg['TrainingFraction'][0] * 100)) + 'shuffle' + str(2),'train/pose_cfg.yaml')
DLC_config=deeplabcut.auxiliaryfunctions.read_plainconfig(posefile)
DLC_config['save_iters']=10
DLC_config['display_iters']=2
DLC_config['multi_step']=[[0.001,10]]
print("CHANGING training parameters to end quickly!")
deeplabcut.auxiliaryfunctions.write_plainconfig(posefile,DLC_config)
filter = None
else:
filter = True
# if self.draw_skeleton.GetStringSelection() == "Yes":
# self.draw = True
# else:
# self.draw = True
# print(self.config,self.filelist,self.videotype.GetValue(),shuffle,trainingsetindex,gputouse=None,save_as_csv=save_as_csv,destfolder=self.destfolder,cropping=cropping)
deeplabcut.analyze_videos(self.config,self.filelist,videotype=self.videotype.GetValue(),shuffle=shuffle,trainingsetindex=trainingsetindex,gputouse=None,save_as_csv=save_as_csv,destfolder=self.destfolder,cropping=cropping, dynamic=dynamic)
if self.filter.GetStringSelection() == "Yes":
deeplabcut.filterpredictions(self.config, self.filelist, videotype=self.videotype.GetValue(), shuffle=shuffle, trainingsetindex=trainingsetindex, filtertype='median', windowlength=5, p_bound=0.001, ARdegree=3, MAdegree=1, alpha=0.01, save_as_csv=True, destfolder=self.destfolder)
if self.create_labeled_videos.GetStringSelection() == "Yes":
deeplabcut.create_labeled_video(self.config,self.filelist,self.videotype.GetValue(),shuffle=shuffle, trainingsetindex=trainingsetindex, draw_skeleton= self.draw,trailpoints = self.trail_points.GetValue(), filtered=True)
if self.trajectory.GetStringSelection() == "Yes":
deeplabcut.plot_trajectories(self.config, self.filelist, videotype=self.videotype.GetValue(), shuffle=shuffle, trainingsetindex=trainingsetindex, filtered=True, showfigures=False, destfolder=self.destfolder)
"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