Skip to content
Snippets Groups Projects
Select Git revision
  • 84cf062a69f6c403b51f050673fc343ec52e9cf4
  • main default protected
  • dev protected
  • dev-doc
  • v0.20.2
  • v0.20.1
  • v0.20
  • v0.19.1
  • v0.19
  • v0.18.4
  • v0.18.3
  • v0.18.1
  • v0.18
  • v0.17.1
  • v0.17
  • v0.16.2
  • v0.16.1
  • v0.16
  • v0.15.2
  • v0.15.1
  • v0.15
  • v0.14.1
  • v0.14
  • v0.13.1
24 results

larvatagger

Blame
  • larvatagger 7.30 KiB
    #!/bin/bash
    
    # This script is written in Bash and replaces a Julia script whose name (and extension)
    # is kept for backward compatibility.
    
    # Former scripts/larvatagger.jl and src/cli.jl have been split in distinct scripts and
    # source files in an attempt to fix issue https://gitlab.pasteur.fr/nyx/larvatagger.jl/-/issues/61
    
    currentdir=$(dirname "$(realpath "${BASH_SOURCE[0]}")")
    
    if [ "${1:0:2}" = "-J" ]; then
    jlargs="$1 "
    shift
    else
    jlargs=
    fi
    cmd=$1
    
    case $cmd in
    open)
      shift
      datapath=$1
      shift
      ltargs=
      if [ -n "$BACKENDS_PATH" ]; then
        ltargs="--backends=\"$BACKENDS_PATH\" $args"
      fi
      if [ -n "$OPEN_BROWSER" ]; then
        ltargs="--browser $args"
      fi
      eval "\"$currentdir/larvatagger-gui.jl\" $jlargs\"$datapath\" $ltargs$@"
      ;;
    
    train|predict)
      if [ -n "$BACKENDS_PATH" -a -n "$2" -a -d "$BACKENDS_PATH/$2" ]; then
        cmd=$1
        shift
        backend=$1
        shift
        "$currentdir/larvatagger-toolkit.jl" $jlargs$cmd "$BACKENDS_PATH/$backend" $@
      else
        "$currentdir/larvatagger-toolkit.jl" $jlargs$@
      fi
      ;;
    
    import|merge|--version|-V)
      "$currentdir/larvatagger-toolkit.jl" $jlargs$@
      ;;
    
    *)
      cat << "EOT"
    LarvaTagger
    
    Usage:
      larvatagger open <file-path> [--backends=<path>] [--port=<number>] [--quiet] [--viewer] [--browser] [--view-factor=<real>] [--manual-label=<label>]
      larvatagger import <input-path> [<output-file>] [--id=<id>] [--framerate=<fps>] [--pixelsize=<μm>] [--overrides=<comma-separated-list>] [--default-label=<label>] [--manual-label=<label>] [--decode] [--copy-labels]
      larvatagger train <backend-path> <data-path> <model-instance> [--pretrained-model=<instance>] [--labels=<comma-separated-list>] [--sample-size=<N>] [--balancing-strategy=<strategy>] [--class-weights=<csv>] [--manual-label=<label>] [--layers=<N>] [--iterations=<N>] [--seed=<seed>] [--debug]
      larvatagger train <backend-path> <data-path> <model-instance> --fine-tune=<instance> [--balancing-strategy=<strategy>] [--manual-label=<label>] [--iterations=<N>] [--seed=<seed>] [--debug]
      larvatagger predict <backend-path> <model-instance> <data-path> [--output=<filename>] [--make-dataset] [--skip-make-dataset] [--data-isolation] [--debug]
      larvatagger predict <backend-path> <model-instance> <data-path> --embeddings [--data-isolation] [--debug]
      larvatagger merge <input-path> <input-file> [<output-file>] [--manual-label=<label>] [--decode]
      larvatagger -V | --version
      larvatagger -h | --help
    
    Options:
      -h --help             Show this screen.
      -V --version          Show version.
      -q --quiet            Do not show instructions.
      --id=<id>             Run or assay ID, e.g. `date_time`.
      --framerate=<fps>     Camera frame rate, in frames per second.
      --pixelsize=<μm>      Camera pixel size, in micrometers.
      --backends=<path>     Path to backend repository.
      --port=<number>       Port number the server listens to.
      --viewer              Disable editing capabilities.
      --browser             Automatically open a browser tab at the served location.
      --view-factor=<real>  Scaling factor for the larva views; default is 2 on macOS, 1 elsewhere.
      --make-dataset        Perform the make_dataset stage prior to proceeding to predict_model.
      --skip-make-dataset   Skip the make_dataset stage (default behavior since TaggingBackends==0.10).
      --data-isolation      Isolate the backend data directories for parallel tagging of multiple data files.
      --sample-size=<N>     Sample only N track segments from the data repository.
      --layers=<N>          (MaggotUBA) Number of layers of the classifier.
      --iterations=<N>      (MaggotUBA) Number of training iterations (can be two integers separated by a comma).
      --seed=<seed>         Seed for the backend's random number generators.
      --segment=<t0,t1>     Start and end times (included, comma-separated) for cropping and including tracks.
      --debug               Lower the logging level to DEBUG.
      --embeddings          (MaggotUBA) Call the backend to generate embeddings instead of labels.
      --decode              Do not encode the labels into integer indices.
      --copy-labels         Replicate discrete behavior data from the input file.
      --default-label=<label>             Label all untagged data as <label>.
      --manual-label=<label>              Secondary label for manually labelled data [default: edited].
      --labels=<comma-separated-list>     Comma-separated list of behavior tags/labels.
      --class-weights=<csv>               Comma-separated list of floats.
      --pretrained-model=<instance>       Name of the pretrained encoder (from `pretrained_models` registry).
      --balancing-strategy=<strategy>     Any of `auto`, `maggotuba`, `none` [default: auto].
      --fine-tune=<instance>              Load and fine-tune an already trained model.
      --overrides=<comma-separated-list>  Comma-separated list of key:value pairs.
      -o <filename> --output=<filename>   Predicted labels filename.
    
    
    Commands:
    
      open      Launch the server-based GUI.
    
        Backends defined in LarvaTagger project root directory are automatically found. Other
        backend locations can be specified with the --backends argument.
    
      import    Generate a label file and store metadata.
    
        This command is particularly useful to specify missing information such as the camera
        framerate for FIMTrack v2 table.csv files. A label file is created with a pointer to the
        original csv file, and a metadata section with the provided information.
        A second usage applies to label files specifically, and consists in extending the tracks
        and timesteps on basis of the associated data dependencies and assigning a default label
        to the data points that are not already defined in the label file.
        Note: label files should always come as siblings of their data dependencies (located in
        the same directory).
    
      merge     Combine the content of label files.
    
        <input-path> is the path to a manually edited label file whose content is to be augmented
        with manual editions from a second (sibling) label file <input-file>. If no output file
        is specified, the resulting content is dumped onto the standard output. All label files
        must be siblings, i.e. located in the same directory.
        If no editions are found in the second input file, all the defined labels are copied from
        the second to the first file.
    
      train     Train a tagger.
    
        <data-path> can be a path to a file or directory.
        --class-weights requires --labels to be defined and the specified comma-separated values
        should match those given by --labels.
    
      predict   Automatically label tracking data.
    
        <data-path> can be a path to a file or directory.
        <data-path> can also be a .txt file listing data files; one relative path per line.
    
    EOT
    
    esac
    
    exit 0
    
    # Equivalent Julia script (slower):
    
    #!/bin/bash
    #=
    if [ -z "$(which realpath)" ]; then
    macos_realpath=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
    PROJECT_DIR=$(dirname $macos_realpath)
    else
    PROJECT_DIR=$(dirname $(dirname $(realpath "${BASH_SOURCE[0]}")))
    fi
    FLAGS=
    if [ "$1" = "--sysimage" -o "$1" = "-J" ]; then FLAGS="--sysimage $2 "; shift 2; fi
    if [ "${1:0:2}" = "-J" ]; then FLAGS="$1"; shift; fi
    if [ "$1" = "open" -a -n "$2" -a -f "$2" ]; then FLAGS="$FLAGS -iq "; fi
    if [ -z "$JULIA" ]; then JULIA=julia; fi
    exec $JULIA --project="$PROJECT_DIR" --color=yes --startup-file=no $FLAGS\
        "${BASH_SOURCE[0]}" "$@"
    =#
    
    projectdir = dirname(Base.active_project())
    include(joinpath(projectdir, "src/cli.jl")) # defines `main`
    
    main();