Skip to content

Commit 8082ee2

Browse files
Shaokai/multi video (#39)
* updates * fixed get acceleration * several updates * updates * WIP * replaced hardcoded identifier with identifier class * lots of improvements * fixed one more conflict * some fixes to web app * Fixed typos * Added yaml dependency * Added init in behavior analysis folder * Added pycocotools into dependency * reformatted test functions * black and isort * Added demo data test and added back video files * added test demo test * Added tables into dependency * try adjusting the paths * removed pycocotools dependency to see whether it helps * see if pining numpy and table version in workflow helps * edited the pytest.yml instead * tables 3.8 in test * Separated installation from readme * Added some useful prints * no need to print meta info again * added self debug into code execution as default * cleaned output * Fixed a bug for keypoint_info being none * Update README.md * Update README.md * Delete INSTALL.md - this is redundant with information in main docs now * Update README.md * Update and rename amadesuGPT-cpu.yml to amadesuGPT.yml (#40) * Update and rename amadesuGPT-cpu.yml to amadesuGPT.yml * Delete conda/amadesuGPT-gpu.yml * Delete conda/amadesuGPT-minimal.yml * Update amadesuGPT.yml - amadeusgpt should be a dependency --------- Co-authored-by: Mackenzie Mathis <[email protected]>
1 parent 1a4ed8b commit 8082ee2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1365
-3834
lines changed

.github/workflows/pytest.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
- name: Install dependencies
3636
run: |
3737
python -m pip install --upgrade pip
38+
pip install pytest numpy==1.23.5 tables==3.8.0
3839
pip install pytest
3940
pip install pytest-timeout
4041
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

.github/workflows/test_and_deploy.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ jobs:
6565
python-version: "3.10"
6666
- name: Install dependencies
6767
run: |
68-
python -m pip install --upgrade pip
68+
python -m pip install --upgrade pip
6969
pip install -U setuptools setuptools_scm wheel twine build
70+
7071
- name: Build package
7172
run: |
7273
python -m build .

README.md

Lines changed: 56 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -22,102 +22,88 @@
2222
- We use large language models (LLMs) to bridge natural language and behavior analysis.
2323
- This work is published at **NeurIPS2023!** Read the paper, [AmadeusGPT: a natural language interface for interactive animal behavioral analysis]([https://www.google.com/search?q=amadeusgpt+openreview&sca_esv=590699485&rlz=1C5CHFA_enCH1059CH1060&ei=K1N6ZaHdKvmrur8PosOOkAo&ved=0ahUKEwjhnta83I2DAxX5le4BHaKhA6IQ4dUDCBE&uact=5&oq=amadeusgpt+openreview&gs_lp=Egxnd3Mtd2l6LXNlcnAiFWFtYWRldXNncHQgb3BlbnJldmlldzIHECEYoAEYCjIHECEYoAEYCki2HVDfAliOHHACeACQAQGYAYMDoAHaGaoBCDEuMTEuMS40uAEDyAEA-AEBwgIFECEYqwLCAggQABiABBiiBMICCBAAGIkFGKIE4gMEGAEgQYgGAQ&sclient=gws-wiz-serp#:~:text=AmadeusGPT%3A%20a%20natural,net%20%E2%80%BA%20pdf](https://proceedings.neurips.cc/paper_files/paper/2023/file/1456560769bbc38e4f8c5055048ea712-Paper-Conference.pdf)) by [Shaokai Ye](https://github.com/yeshaokai), [Jessy Lauer](https://github.com/jeylau), [Mu Zhou](https://github.com/zhoumu53), [Alexander Mathis](https://github.com/AlexEMG) & [Mackenzie W. Mathis](https://github.com/MMathisLab).
2424
- Like this project? Please consider giving us a star ⭐️!
25-
26-
## Install & Run AmadeusGPT🎻
27-
28-
### Install with `pypi`
2925

30-
- AmadeusGPT is a Python package hosted on `pypi`. You can create a virtual env (conda, etc, see below*) and run:
31-
```python
32-
pip install 'amadeusgpt[streamlit]'
33-
```
34-
Note that in order to access our demo video and keypoint files, we recommend to install from the source.
26+
## What is AmadeusGPT?
3527

36-
### Install from the source
28+
**Developed by part of the same team that brought you [DeepLabCut](https://www.mackenziemathislab.org/deeplabcut), AmadeusGPT is a natural language interface that turns natural language descriptions of behaviors into machine-executable code.** The process of quantifying and analyzing animal behavior involves translating the naturally occurring descriptive language of their actions into machine-readable code. Yet, codifying behavior analysis is often challenging without deep understanding of animal behavior and technical machine learning knowledge, so we wanted to ease this jump.
29+
In short, we provide a "code-free" interface for you to analysis video data of animals. If you are a [DeepLabCut](https://www.mackenziemathislab.org/deeplabcut) user, this means you could upload your videos and .h5 keypoint files and then ask questions, such as "How much time does the mouse spend in the middle of the open field?".
30+
In our original work (NeurIPS 2023) we used GPT3.5 and GPT4 as part of our agent. We continue to support the latest OpenAI models, and are continuing to actively develop this project.
31+
32+
## Get started: install AmadeusGPT🎻
3733

38-
**Make sure you edit those installation scripts to point to your own conda path before you run them**
34+
### [1] Set up a conda environment:
3935

40-
#### Minimal installation
41-
**Recommended for:** Running AmadeusGPT without GPUs. This setup is lightweight and is limited to processing movie files and keypoint outputs (.h5) from DeepLabCut.
36+
Conda is an easy-to-use Python interface that supports launching [Jupyter Notebooks](https://jupyter.org/). If you are completely new to this, we recommend checking out the [docs here for getting conda installed](https://deeplabcut.github.io/DeepLabCut/docs/beginner-guides/beginners-guide.html#beginner-user-guide). Otherwise, proceed to use one of [our supplied conda files](https://github.com/AdaptiveMotorControlLab/AmadeusGPT/tree/main/conda). As you will see we have minimal dependencies to get started, and [here is a simple step-by-step guide](https://deeplabcut.github.io/DeepLabCut/docs/installation.html#step-2-build-an-env-using-our-conda-file) you can reference for setting it up (or see [BONUS](README.md#bonus---customized-your-conda-env) below). Here is the quick start command:
4237

4338
```bash
44-
# Install the minimal environment
45-
bash install_minimal.sh
46-
47-
# Activate the conda environment
48-
conda activate amadeusgpt-minimal
39+
conda env create -f amadeusGPT.yml
4940
```
41+
To note, some modules AmadeusGPT can use benefit from GPU support, therefore we recommend also having an NVIDIA GPU available and installing CUDA.
5042

51-
#### GPU installation
52-
**Recommended for:** Users on Linux with GPUs. Support for Windows and MacOS will be added in the future.
43+
### [2] You will need an openAI key:
5344

54-
```bash
55-
# Install the gpu environment
56-
bash install_gpu.sh
45+
**Why OpenAI API Key is needed** AmadeusGPT relies on API calls of OpenAI (we will add more LLM options in the future) for language understanding and code writing. Sign up for a [openAI API key](https://platform.openai.com/account/api-keys) [here](https://platform.openai.com/account/api-keys).
46+
47+
Then, you can add this into your environment by passing the following in the terminal after you launched your conda env:
5748

58-
# Activate the conda environment
59-
conda activate amadeusgpt-gpu
49+
```bash
50+
export OPENAI_API_KEY='your API key'
6051
```
6152

62-
#### CPU installation
63-
**Recommended for:** MacOS / Linux users working with very small video files.
53+
Or inside a python script or Jupyter Notebook, add this if you did not pass at the terminal stage:
6454

65-
```bash
66-
# Install the cpu environment
67-
bash install_cpu.sh
6855

69-
# Activate the conda environment
70-
conda activate amadeusgpt-cpu
56+
```python
57+
import os
58+
os.environ["OPENAI_API_KEY"] = 'your api key'
7159
```
7260

61+
### [3] 🪄 That's it! Now you have AmadeusGPT installed!
7362

74-
### Setup OpenAI API Key to use AmadeusGPT
75-
76-
**Why OpenAI API Key is needed** AmadeusGPT relies on API calls of OpenAI (we will add more options in the future) for language understanding and code writing.
63+
See below on how to get started!
7764

78-
You can either add this into your environment by following:
7965

80-
```bash
81-
export OPENAI_API_KEY='your API key'
82-
```
66+
## Get started: run AmadeusGPT🎻
8367

84-
Or inside your python script or jupyter notebook, add this line in the beginning of the file
68+
We provide a StreamLit App, or you can use AmadeusGPT in any python interface, such as Jupyter notebooks. For this we suggest getting started from our demos:
8569

70+
### Try AmadeusGPT with an example Jupyter Notebook
71+
You can git clone (or download) this repo to grab a copy and go. We provide example notebooks [here](notebook)!
8672

87-
```python
88-
import os
89-
os.environ["OPENAI_API_KEY"] = 'your api key'
90-
```
73+
### Here are a few demos that could fuel your own work, so please check them out!
9174

92-
- Please note that you need an [openAI API key](https://platform.openai.com/account/api-keys), which you can easily create [here](https://platform.openai.com/account/api-keys).
75+
1) [Draw a region of interest (ROI) and ask, "when is the animal in the ROI?"](notebook/EPM_demo.ipynb)
76+
2) [Use a DeepLabCut SuperAnimal pose model to do video inference](notebook/custom_mouse_demo.ipynb) - (make sure you use a GPU if you don't have corresponding DeepLabCut keypoint files already!
77+
3) [Write you own integration modules and use them](notebook/Horse_demo.ipynb). Bonus: [source code](amadeusgpt/integration_modules). Make sure you delete the cached modules_embedding.pickle if you add new modules!
78+
4) [Multi-Animal social interactions](notebook/MABe_demo.ipynb)
79+
5) [Reuse the task program generated by LLM and run it on different videos](notebook/MABe_demo.ipynb)
80+
7) You can ask one query across multiple videos. Put your keypoint files and video files (pairs) in the same folder and specify the `data_folder` as shown in this [Demo](notebook/custom_mouse_video.ipynb). Make sure your video file and keypoint file follows the normal DeepLabCut convention, i.e., `prefix.mp4` `prefix*.h5`.
9381

9482

9583

96-
### Try AmadeusGPT with local web app
84+
### Try AmadeusGPT with a local WebApp
85+
- You will need to git clone this repo and have a copy locally. Then in your env run `pip install 'amadeusGPT[streamlit]'`
86+
- Then you can open the terminal and within the directory run:
9787
```python
9888
make app
9989
```
10090

101-
### Do I need to provide keypoint files?
102-
- If you only provide the raw video file, we use SuperAnimal models [SuperAnimal models](https://www.nature.com/articles/s41467-024-48792-2) to predict your video. This is only supported with cpu or gpu installation. While we highly recommend gpu installation, we are working on faster, light-weight superanimal models to work on your CPU.
103-
- If you already have keypoint file corresponding to the video file, look up how we set-up the config file in the notebooks. Right now we only support keypoint output from DeepLabCut. Other keypoint formats can be added upon feature requests.
104-
10591

106-
### Try AmadeusGPT with our example notebooks
107-
We provide example notebooks at [Notebooks](notebook)
108-
109-
### Notebook as use-case demo
110-
111-
1) Draw ROI and ask when is the animal in the ROI. [Demo](notebook/EPM_demo.ipynb)
112-
2) Obtain the binary mask for retrieved masks (for further sampling such as neural data pairing) [Demo](notebook/EPM_demo.ipynb)
113-
3) Use SuperAnimal video inference (make sure you use gpu or cpu installation) if you don't have corresponding DeepLabCut keypoint file [Demo](notebook/custom_mouse_demo.ipynb)
114-
4) Write you own integration modules and use them [Demo](notebook/Horse_demo.ipynb) [Source code](amadeusgpt/integration_modules). Make sure you delete the cached modules_embedding.pickle if you add new modules
115-
5) Multi-Animal social interaction. [Demo](notebook/MABe_demo.ipynb)
116-
6) Reuse the task program generated by LLM and run it on different videos [Demo](notebook/MABe_demo.ipynb)
92+
## [BONUS - customized your conda env]
93+
If you want to set up your own env,
11794

95+
```bash
96+
conda create -n amadesuGPT python=3.10
97+
```
98+
the key dependencies that need installed are:
99+
```python
100+
pip install notebook
101+
conda install hdf5
102+
pip install amadeusgpt
103+
```
118104
## Citation
119105

120-
If you use ideas or code from this project in your work, please cite us using the following BibTeX entry. 🙏
106+
If you use ideas or code from this project in your work, please cite us using the following BibTeX entry. 🙏
121107

122108
```
123109
@article{ye2023amadeusGPT,
@@ -133,10 +119,17 @@ We provide example notebooks at [Notebooks](notebook)
133119
## License
134120

135121
AmadeusGPT is license under the Apache-2.0 license.
136-
- 🚨 Please note several key dependencies have their own licensing. Please carefully check the license information for [DeepLabCut](https://github.com/DeepLabCut/DeepLabCut) (LGPL-3.0 license), [SAM](https://github.com/facebookresearch/segment-anything) (Apache-2.0 license), [CEBRA](https://github.com/AdaptiveMotorControlLab/CEBRA) (Non-Commercial), etc.
122+
- 🚨 Please note several key dependencies have their own licensing. Please carefully check the license information for [DeepLabCut](https://github.com/DeepLabCut/DeepLabCut) (LGPL-3.0 license), [SAM](https://github.com/facebookresearch/segment-anything) (Apache-2.0 license), etc.
123+
124+
## FAQ:
137125

126+
### Do I need to provide keypoint files or is video-only enough to get starte?
127+
- If you only provide a video file, we use SuperAnimal models [SuperAnimal models](https://www.nature.com/articles/s41467-024-48792-2) to predict which animal is in your video. While we highly recommend GPU installation, we are working on faster, light-weight SuperAnimal models to work on your CPU.
128+
- If you already have keypoint file corresponding to the video file, look how we set-up the config file in the Notebooks. Right now we only support keypoint output from DeepLabCut.
138129

139130
## News
131+
- July 2024 0.1.0 is released! This is a major code update ...
132+
- June 2024 as part of the CZI EOSS, The Kavli Foundation now supports this work! ✨
140133
- 🤩 Dec 2023, code released!
141134
- 🔥 Our work was accepted to NeuRIPS2023
142135
- 🧙‍♀️ Open-source code coming in the fall of 2023

amadeusgpt/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from matplotlib import pyplot as plt
99

10-
from amadeusgpt.implementation import AnimalBehaviorAnalysis
1110
from amadeusgpt.integration_modules import *
1211
from amadeusgpt.main import AMADEUS
1312
from amadeusgpt.version import VERSION, __version__

amadeusgpt/analysis_objects/analysis_factory.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

amadeusgpt/analysis_objects/animal.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
from amadeusgpt.analysis_objects.object import Object
2-
from numpy import ndarray
3-
from scipy.spatial import ConvexHull
4-
from typing import List, Dict, Any
1+
from typing import Any, Dict, List
2+
53
import matplotlib.path as mpath
64
import numpy as np
5+
from numpy import ndarray
6+
from scipy.spatial import ConvexHull
7+
8+
from amadeusgpt.analysis_objects.object import Object
79

810

911
class Animal(Object):
@@ -92,11 +94,16 @@ def get_path(self, ind):
9294
codes, verts = zip(*path_data)
9395
return mpath.Path(verts, codes)
9496

95-
def get_keypoints(self) -> ndarray:
97+
def get_keypoints(self, average_keypoints=False) -> ndarray:
9698
# the shape should be (n_frames, n_keypoints, 2)
9799
# extending to 3D?
98-
assert len(self.keypoints.shape) == 3, f"keypoints shape is {self.keypoints.shape}"
99-
return self.keypoints
100+
assert (
101+
len(self.keypoints.shape) == 3
102+
), f"keypoints shape is {self.keypoints.shape}"
103+
if not average_keypoints:
104+
return self.keypoints
105+
else:
106+
return np.nanmean(self.keypoints, axis=1)
100107

101108
def get_center(self):
102109
"""
@@ -166,13 +173,13 @@ def get_acceleration(self) -> ndarray:
166173
)
167174
assert len(accelerations.shape) == 3
168175
return accelerations
169-
176+
170177
def get_acceleration_mag(self) -> ndarray:
171178
"""
172-
Returns the magnitude of the acceleration vector
179+
Returns the magnitude of the acceleration vector
173180
"""
174181
accelerations = self.get_acceleration()
175-
acceleration_mag = np.linalg.norm(accelerations, axis=-1)
182+
acceleration_mag = np.linalg.norm(accelerations, axis=-1)
176183
acceleration_mag = np.expand_dims(acceleration_mag, axis=-1)
177184
assert len(acceleration_mag.shape) == 3
178185
return acceleration_mag
@@ -226,23 +233,24 @@ def calc_head_cs(self):
226233
return mouse_cs
227234

228235

229-
230236
if __name__ == "__main__":
231237
# unit testing the shape of kinematics data
232238
# acceleration, acceleration_mag, velocity, speed, and keypoints
233239

234240
from amadeusgpt.config import Config
235241
from amadeusgpt.main import AMADEUS
236-
config = Config("/Users/shaokaiye/AmadeusGPT-dev/amadeusgpt/configs/MausHaus_template.yaml")
242+
243+
config = Config(
244+
"/Users/shaokaiye/AmadeusGPT-dev/amadeusgpt/configs/MausHaus_template.yaml"
245+
)
237246
amadeus = AMADEUS(config)
238247
analysis = amadeus.get_analysis()
239248
# get an instance of animal
240249
animal = analysis.animal_manager.get_animals()[0]
241250

242-
print ("velocity shape", animal.get_velocity().shape)
243-
print ("speed shape", animal.get_speed().shape)
244-
print ("acceleration shape", animal.get_acceleration().shape)
245-
print ("acceleration_mag shape", animal.get_acceleration_mag().shape)
251+
print("velocity shape", animal.get_velocity().shape)
252+
print("speed shape", animal.get_speed().shape)
253+
print("acceleration shape", animal.get_acceleration().shape)
254+
print("acceleration_mag shape", animal.get_acceleration_mag().shape)
246255

247256
print(animal.query_states("acceleration_mag").shape)
248-

0 commit comments

Comments
 (0)