From 6ae18d707544ef893cc1343f43db0586d4798869 Mon Sep 17 00:00:00 2001 From: Carsen Stringer Date: Wed, 8 Feb 2023 22:16:34 -0500 Subject: [PATCH 1/5] bug in prediction utils -- tbin is not None needed in code --- facemap/neural_prediction/prediction_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/facemap/neural_prediction/prediction_utils.py b/facemap/neural_prediction/prediction_utils.py index a350356..e0daac0 100644 --- a/facemap/neural_prediction/prediction_utils.py +++ b/facemap/neural_prediction/prediction_utils.py @@ -200,7 +200,7 @@ def rrr_prediction( itest: 1D int array (optional, default None) times in test set - tbin: int (optional, default 0) + tbin: int (optional, default None) also compute variance explained in bins of tbin Returns @@ -254,7 +254,7 @@ def rrr_prediction( residual = ((Y[itest] - Y_pred_test) ** 2).mean(axis=0) varexpf[r] = (1 - residual / Y_test_var).cpu().numpy() varexp[r, 0] = (1 - residual.mean() / Y_test_var.mean()).cpu().numpy() - if tbin != 0 and tbin > 1: + if tbin is not None and tbin > 1: varexp[r, 1] = ( compute_varexp( bin1d(Y[itest], tbin).flatten(), bin1d(Y_pred_test, tbin).flatten() From 67f3358e3cfb02dca9c7bbb07922539a8258392b Mon Sep 17 00:00:00 2001 From: Carsen Stringer Date: Thu, 9 Feb 2023 13:59:38 -0500 Subject: [PATCH 2/5] switching from svd => svd_lowrank from torch to accelerate reduced rank regression --- facemap/neural_prediction/prediction_utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/facemap/neural_prediction/prediction_utils.py b/facemap/neural_prediction/prediction_utils.py index e0daac0..c3610c7 100644 --- a/facemap/neural_prediction/prediction_utils.py +++ b/facemap/neural_prediction/prediction_utils.py @@ -147,7 +147,7 @@ def reduced_rank_regression(X, Y, rank=None, lam=0, device=torch.device("cuda")) # compute inverse square root of matrix # s, u = eigh(CXX.cpu().numpy()) - u, s = torch.svd(CXX)[:2] + u, s = torch.svd_lowrank(CXX, q=rank)[:2] CXXMH = (u * (s + lam) ** -0.5) @ u.T # project into prediction space @@ -156,7 +156,7 @@ def reduced_rank_regression(X, Y, rank=None, lam=0, device=torch.device("cuda")) # model = PCA(n_components=rank).fit(M) # c = model.components_.T # s = model.singular_values_ - s, c = torch.svd(M)[1:] + s, c = torch.svd_lowrank(M, q=rank)[1:] A = M @ c B = CXXMH @ c return A, B @@ -226,8 +226,8 @@ def rrr_prediction( if itrain is None and itest is None: itrain, itest = split_traintest(n_t) itrain, itest = itrain.flatten(), itest.flatten() - X = torch.from_numpy(X).to(device, dtype=torch.float64) - Y = torch.from_numpy(Y).to(device, dtype=torch.float64) + X = torch.from_numpy(X).to(device) + Y = torch.from_numpy(Y).to(device) A, B = reduced_rank_regression( X[itrain], Y[itrain], rank=rank, lam=lam, device=device ) From a3c2e887aebdab2bb635d38baa1b2dfb755fd7c7 Mon Sep 17 00:00:00 2001 From: carsen-stringer Date: Sat, 11 Feb 2023 12:55:26 -0500 Subject: [PATCH 3/5] Update installation.rst --- docs/installation.rst | 47 ++----------------------------------------- 1 file changed, 2 insertions(+), 45 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index d784f38..b485000 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -1,50 +1,7 @@ Installation =================================== -This package only supports python 3. We recommend installing python 3 with `Anaconda `_. - - -Pose tracker and SVD processing -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -For using tracker and svd processing, follow the instructions below: - -1. ``git clone https://github.com/MouseLand/facemap.git`` -2. Change directory to facemap folder containing ``environment.yml`` file -3. ``conda env create -f environment.yml`` -4. ``conda activate facemap`` -5. ``python -m facemap`` - -This will install and run the latest development version on github. - -SVD processing only -~~~~~~~~~~~~~~~~~~~~ - -Run the following for command line interface (CLI) i.e. headless version: -:: - - pip install facemap - -or the following for using GUI: -:: - - pip install facemap[gui] - - -To upgrade Facemap package (https://pypi.org/project/facemap/), within the environment run: -:: - - pip install facemap --upgrade - - -Using the environment.yml file (recommended installation method): - -1. Download the ``environment.yml`` file from the repository or clone the github repository: ``git clone https://www.github.com/mouseland/facemap.git`` -2. Open an anaconda prompt / command prompt with ``conda`` for **python 3** in the path -3. Change directory to facemap folder ``cd facemap`` -4. Run ``conda env create -f environment.yml`` -5. To activate this new environment, run ``conda activate facemap`` -6. You should see ``(facemap)`` on the left side of the terminal line. Now run ``python -m facemap`` and you're all set. - +Please see the github readme for full install instructions. Common installation issues ~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -96,4 +53,4 @@ Facemap python relies on these awesome packages: MATLAB package installation ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The matlab version supports SVD processing only and does not include face tracker. The package can be downloaded/cloned from github (no install required). It works in Matlab 2014b and above - please submit issues if it's not working. The Image Processing Toolbox is necessary to use the GUI. For GPU functionality, the Parallel Processing Toolbox is required. If you don't have the Parallel Processing Toolbox, uncheck the box next to "use GPU" in the GUI before processing. +The matlab version supports SVD processing only and does not include face tracker. The package can be downloaded/cloned from github (no install required). It works in Matlab 2014b and above. The Image Processing Toolbox is necessary to use the GUI. For GPU functionality, the Parallel Processing Toolbox is required. If you don't have the Parallel Processing Toolbox, uncheck the box next to "use GPU" in the GUI before processing. Note this version is no longer supported. From a0b53e5a0e628a668bc2867705d94dd5b73614f0 Mon Sep 17 00:00:00 2001 From: carsen-stringer Date: Sat, 11 Feb 2023 12:55:38 -0500 Subject: [PATCH 4/5] Update installation.rst --- docs/installation.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/installation.rst b/docs/installation.rst index b485000..6bbbc64 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -2,6 +2,8 @@ Installation =================================== Please see the github readme for full install instructions. + + Common installation issues ~~~~~~~~~~~~~~~~~~~~~~~~~~ From be616c55dfaa6ac9df5192753c5da27a46eb9330 Mon Sep 17 00:00:00 2001 From: carsen-stringer Date: Thu, 16 Feb 2023 09:33:13 -0500 Subject: [PATCH 5/5] Update README.md --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d473a4b..fc2347f 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ Facemap is a framework for predicting neural activity from mouse orofacial movements. It includes a pose estimation model for tracking distinct keypoints on the mouse face, a neural network model for predicting neural activity using the pose estimates, and also can be used compute the singular value decomposition (SVD) of behavioral videos. +Please find the detailed documentation at **[facemap.readthedocs.io](https://facemap.readthedocs.io/en/latest/index.html)**. + To learn about Facemap, read the [paper](https://www.biorxiv.org/content/10.1101/2022.11.03.515121v1) or check out the tweet [thread](https://twitter.com/Atika_Ibrahim/status/1588885329951367168?s=20&t=AhE3vBTnCvW36QiTyhu0qQ). For support, please open an [issue](https://github.com/MouseLand/facemap/issues). - For latest released version (from PyPI) including svd processing only, run `pip install facemap` for headless version or `pip install facemap[gui]` for using GUI. Note: `pip install facemap` not yet available for latest tracker and neural model, instead install with `pip install git+https://github.com/mouseland/facemap.git` @@ -113,19 +115,7 @@ For more details on using the tracker, please refer to the [GUI Instructions](do Facemap aims to provide a simple and easy-to-use tool for tracking mouse orofacial movements. The tracker's performance for new datasets could be further improved by expand our training set. You can contribute to the model by sharing videos/frames on the following email address(es): `asyeda1[at]jh.edu` or `stringerc[at]janelia.hhmi.org`. -# II. Neural activity prediction - -Facemap includes a deep neural network encoding model for predicting neural activity or principal components of neural activity from mouse orofacial pose estimates extracted using the tracker or SVDs. - -The encoding model used for prediction is described as follows: -

-view1 -

- -Please see neural activity prediction [tutorial](docs/neural_activity_prediction_tutorial.md) for more details. - - -# III. SVD processing +# II. SVD processing Facemap provides options for singular value decomposition (SVD) of single and multi-camera videos. SVD analysis can be performed across static frames called movie SVD (`movSVD`) to extract the spatial components or over the difference between consecutive frames called motion SVD (`motSVD`) to extract the temporal components of the video. The first 500 principal components from SVD analysis are saved as output along with other variables. For more details, see [python tutorial](docs/svd_python_tutorial.md). The process for SVD analysis is as follows: 1. Load video. (Optional) Use the file menu to set output folder. @@ -144,6 +134,16 @@ python -m facemap ``` Default starting folder is set to wherever you run `python -m FaceMap` +# III. Neural activity prediction + +Facemap includes a deep neural network encoding model for predicting neural activity or principal components of neural activity from mouse orofacial pose estimates extracted using the tracker or SVDs. + +The encoding model used for prediction is described as follows: +

+view1 +

+ +Please see neural activity prediction [tutorial](docs/neural_activity_prediction_tutorial.md) for more details. ### [*HOW TO GUI* (MATLAB)](docs/svd_matlab_tutorial.md)