kristinbranson / APT

Animal Part Tracker
GNU General Public License v3.0
71 stars 16 forks source link

command line tracking #336

Closed BenHabermeyer closed 3 years ago

BenHabermeyer commented 4 years ago

Hello, I am trying to use the command line to track movie(s) after loading a .lbl project into the APT GUI following https://github.com/kristinbranson/APT/wiki/Tracking-Movies-(DL-algorithms). I am using a pretrained CPR model (though the docs says non-CPR...?)

in MATLAB, after running lObj = StartAPT; and loading in the .lbl file from file->load project, I run lObj.tracker.track({video_path}, 'trkfiles', {trk_path}, 'trxfiles', {trx_path}); with paths to the video, trk outfile, and trx.mat file I would like to use. I receive warnings that 'trkfiles' and 'trxfiles' are unknown parameter names which are ignored, and get the following error:

useParFor = 1
maxNumCompThreads = 4
usetrxOrientation = 1
Dot indexing is not supported for variables of this type.

Error in tblfldscontainsassert (line 3)
assert(all(ismember(flds(:),t.Properties.VariableNames(:))),...

Error in CPRLabelTracker/track (line 1794)
      tblfldscontainsassert(tblMFT,MFTable.FLDSID);

Is command-line tracking not allowed with a CPR model or is there an error I am making? If CPR is not allowed what do you suggest going forwards for deploying a tracker using the command line?

allenleetc commented 4 years ago

Hey Ben,

Yes that wiki applies only to Deep-Learning trackers. I will update the wiki to clarify, apologies for the confusion.

Command-line tracking is available for CPR but the syntax is different for historical reasons. There are a couple ways to go; are you wanting to track movies that are not contained within your project? Are you looking to track a very large number of movies?

Backing up, does a commandline or graphical interface work better for you for tracking? We recently reorganized the tracking menu in the GUI; it's not hooked up for CPR yet, but we can prioritize that if it is useful. Other users are doing production CPR tracking as well.

BenHabermeyer commented 4 years ago

Hello Allen,

I am looking to use a pre-trained tracker .lbl project to track new videos (so not videos the project was trained with). Ideally would like to use the command line to accomplish this (similar to JAABADetect, where .jab classifier can be called from command line given paths to required files). It is part of a larger classification pipeline for many behavior videos produced over several years. If you have any guidance on the syntax for CPR tracking from command line that would be helpful.

Thanks Ben

allenleetc commented 4 years ago

OK, cool. Here is something to try:

APTCluster /path/to/project.lbl track /path/to/movie.avi /path/to/trx.mat rawtrkname /path/to/output.trk

% functional form
APTCluster('/path/to/project.lbl','track','/path/to/movie.avi','/path/to/trx.mat','rawtrkname','/path/to/output.trk')

% startframe/endframe spec
APTCluster /path/to/project.lbl track /path/to/movie.avi /path/to/trx.mat rawtrkname /path/to/output.trk startFrame 1 endFrame 100 

A few notes:

Let me know if this gets you going and maybe I can add this for the wiki as it may evolve.

BenHabermeyer commented 4 years ago

APTCluster call seemed to work just fine with a test video, our .lbl file, and a trx.mat file. Generated .trk file at least. I'll integrate it into our pipeline for more testing but seems promising for our application (generating trx, generating trk, and using JAABA classifier for many individual videos one at a time). Just requires StartAPT command before running. Thanks for the help

allenleetc commented 4 years ago

Great! Let us know how it goes. I'll circle back in a bit for some API cleanup, wiki/doc etc.

allenleetc commented 3 years ago

@BenHabermeyer pushed a new syntax with a more reasonable name. Also, in your previous comment you mention needing to run StartAPT initially -- I am guessing this was only necessary to set up your APT paths (see below). Otherwise it shouldn't be necessary (?).

Example of new syntax below. You can specify multiple movies/trx via cell arrays (movies will be tracked serially); otherwise it's just a more reasonably-named wrapper for the APTCluster call. We have other batch-tracking modalities (for deep-learning etc) that we are consolidating under the new syntax.

% this sets up your APT path
APT.setpath 

movs = {'/path/to/mov1.avi' '/path/to/mov2.avi'}; % cellstr or string array OK
trxs = {'/path/to/trx1.mat' '/path/to/trx2.mat'};
trkfiles = {'/path/to/out1.trk' '/path/to/out2.trk'};
trackBatch('lblfile','/path/to/proj.lbl','net','cpr','movfiles',movs,'trxfiles',trxs,'trkfiles',trkfiles);

% Note the 'net', 'cpr' specification is required and other/DL nets are not yet supported

% With start/end frame specification
trackBatch('lblfile','/path/to/proj.lbl','net','cpr','movfiles',movs,'trxfiles',trxs,'trkfiles',trkfiles,'startFrame',1,'endFrame',100);
BenHabermeyer commented 3 years ago

Ok yes was likely that startAPT was only needed to set up the required paths. Thanks for the update on the new syntax! Will pass this along. And again thanks for your help.