@@ -323,8 +323,19 @@ class BodyPartPosition(dj.Part):
323
323
likelihood : longblob # model evaluated likelihood
324
324
"""
325
325
326
+ class File (dj .Part ):
327
+ definition = """
328
+ -> master
329
+ file_name: varchar(255)
330
+ ---
331
+ file: filepath@facemap-processed
332
+ """
333
+
326
334
def make (self , key ):
327
- """.populate() method will launch training for each FacemapInferenceTask"""
335
+ """
336
+ Calls facemap.pose.Pose to run pose estimation on the video files using the specified model.
337
+ Video files and model are specified in the FacemapInferenceTask table.
338
+ """
328
339
# ID model and directories
329
340
task_mode , output_dir = (FacemapInferenceTask & key ).fetch1 (
330
341
"task_mode" , "facemap_inference_output_dir"
@@ -353,27 +364,9 @@ def make(self, key):
353
364
full_metadata_path = output_dir / f"{ vid_name } _FacemapPose_metadata.pkl"
354
365
355
366
# Load or Trigger Facemap Pose Estimation Inference
356
- if (
367
+ if task_mode == "trigger" and not (
357
368
facemap_result_path .exists () & full_metadata_path .exists ()
358
- ) or task_mode == "load" : # Load results and do not rerun processing
359
- (
360
- body_part_position_entry ,
361
- inference_duration ,
362
- total_frame_count ,
363
- creation_time ,
364
- ) = _load_facemap_results (key , facemap_result_path , full_metadata_path )
365
- self .insert1 (
366
- {
367
- ** key ,
368
- "inference_completion_time" : creation_time ,
369
- "inference_run_duration" : inference_duration ,
370
- "total_frame_count" : total_frame_count ,
371
- }
372
- )
373
- self .BodyPartPosition .insert (body_part_position_entry )
374
- return
375
-
376
- elif task_mode == "trigger" :
369
+ ):
377
370
from facemap .pose import pose as facemap_pose , model_loader
378
371
379
372
bbox = (FacemapInferenceTask & key ).fetch1 ("bbox" ) or []
@@ -382,9 +375,10 @@ def make(self, key):
382
375
facemap_model_name = (
383
376
FacemapModel .File & f'model_id="{ key ["model_id" ]} "'
384
377
).fetch1 ("model_file" )
385
-
386
378
facemap_model_path = Path .cwd () / facemap_model_name
379
+ # copy this model file to the facemap model root directory (~/.facemap/models/)
387
380
models_root_dir = model_loader .get_models_dir ()
381
+ shutil .copy (facemap_model_path , models_root_dir )
388
382
389
383
# Create Symbolic Links to raw video data files from outbox directory
390
384
video_symlinks = []
@@ -395,9 +389,6 @@ def make(self, key):
395
389
video_symlink .symlink_to (video_file )
396
390
video_symlinks .append (video_symlink .as_posix ())
397
391
398
- # copy this model file to the facemap model root directory (~/.facemap/models/)
399
- shutil .copy (facemap_model_path , models_root_dir )
400
-
401
392
# Instantiate Pose object, with filenames specified as video files, and bounding specified in params
402
393
# Assumes GUI to be none as we are running CLI implementation
403
394
pose = facemap_pose .Pose (
@@ -408,21 +399,32 @@ def make(self, key):
408
399
)
409
400
pose .run ()
410
401
411
- (
412
- body_part_position_entry ,
413
- inference_duration ,
414
- total_frame_count ,
415
- creation_time ,
416
- ) = _load_facemap_results (key , facemap_result_path , full_metadata_path )
417
- self .insert1 (
402
+ (
403
+ body_part_position_entry ,
404
+ inference_duration ,
405
+ total_frame_count ,
406
+ creation_time ,
407
+ ) = _load_facemap_results (key , facemap_result_path , full_metadata_path )
408
+ self .insert1 (
409
+ {
410
+ ** key ,
411
+ "inference_completion_time" : creation_time ,
412
+ "inference_run_duration" : inference_duration ,
413
+ "total_frame_count" : total_frame_count ,
414
+ }
415
+ )
416
+ self .BodyPartPosition .insert (body_part_position_entry )
417
+ # Insert result files
418
+ self .File .insert (
419
+ [
418
420
{
419
421
** key ,
420
- "inference_completion_time" : creation_time ,
421
- "inference_run_duration" : inference_duration ,
422
- "total_frame_count" : total_frame_count ,
422
+ "file_name" : f .relative_to (output_dir ).as_posix (),
423
+ "file" : f ,
423
424
}
424
- )
425
- self .BodyPartPosition .insert (body_part_position_entry )
425
+ for f in (facemap_result_path , full_metadata_path )
426
+ ]
427
+ )
426
428
427
429
@classmethod
428
430
def get_trajectory (cls , key : dict , body_parts : list = "all" ) -> pd .DataFrame :
@@ -468,7 +470,6 @@ def get_trajectory(cls, key: dict, body_parts: list = "all") -> pd.DataFrame:
468
470
469
471
def _load_facemap_results (key , facemap_result_path , full_metadata_path ):
470
472
"""Load facemap results from h5 and metadata files."""
471
-
472
473
from facemap import utils
473
474
474
475
with open (full_metadata_path , "rb" ) as f :
0 commit comments