Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,28 @@

## Install & Run AmadeusGPT🎻

- AmadeusGPT is a Python package hosted on `pypi`. You can create a virtual env (conda, etc, see below*) or Docker and run:
```python
pip install 'amadeusgpt[streamlit]'
- We prepare installation script install.sh. Make sure you modify the bash script to fit your own.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you deleting the pypi package? it is on pypi ;)

Copy link
Collaborator Author

@yeshaokai yeshaokai Jun 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I realize that, at least when I was working on it, one can't install deeplabcut with pip install alone. It needs to use the conda yaml to first install hdf5 and many users don't understand why that's the case. So inside the installation script, I force users to create a conda env via conda yaml and then pip install.

The installation script

source /Users/shaokaiye/miniforge3/bin/activate

conda env create -f conda/amadesuGPT.yml

conda activate amadeusgpt

pip install -e .[streamlit]

In colab, because hdf5 is pre-installed, then they will run into slightly different problem such as pytable vs. tables from deeplabcut. I overheard you guys might have solved it. Let me know if there is better way to solve it.

```bash
#!/bin/bash
# replace this with your own conda path
source /Users/shaokaiye/miniforge3/bin/activate
conda env create -f conda/amadesuGPT.yml
conda activate amadeusgpt
pip install -e .[streamlit]
```
- After the installation, you can do

```bash
conda activate amadeusgpt
```

- 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).
- If you want the **Streamlit Demo on your computer**, you will also need demo files that are supplied in our repo (see below**), so please git clone the repo and navigate into the `AmadeusGPT` directory. Then in your conda env/terminal run `pip install 'amadeusgpt[streamlit]'` as described above. Then, to launch the Demo App execute in the terminal:
```python
```bash
make app
```
- You can use AmadeusGPT directly in python: iPython, Jupyter Notebooks, Google Colab, etc. For a quick start, see our `\examples` directory that hosts demo data and a Jupyter Notebook! Enjoy!
- You can use AmadeusGPT directly in python: iPython, Jupyter Notebooks etc. For a quick start, see our `\examples` directory that hosts demo data and a Jupyter Notebook! Enjoy!
- Note if you use Google Colab, you still need to clone the repo (to access the demo data and installation script) and run installation script (after modifying the conda path)

## Citation

Expand All @@ -51,12 +63,10 @@ make app
- arXiv preprint version **[AmadeusGPT: a natural language interface for interactive animal behavioral analysis](https://arxiv.org/abs/2307.04858)** 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).

### Install tips
- *Make a new conda env: `conda create --name amadeusGPT python=3.9` then run `conda activate amadeusGPT` or you can also use our supplied conda if you git cloned the repo (navigate into the conda directory): `conda env create -f amadesuGPT.yml` then pip install amadeusGPT once created/launched.
- **Git clone this repo: so please open a terminal, we recommend to download into Documents (so type `cd Documents`) and run `git clone https://github.com/AdaptiveMotorControlLab/AmadeusGPT.git` Then go into the dir (`cd AmadeusGPT`)
- If you want to use SAM, you need to download the weights. Otherwise you will see the following message in the app: `Cannot find SAM checkpoints. Skipping SAM`. Download them and add to "static" directory: wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth

### Install trouble shooting:
- If you hit an error during installing on an M1/M2 Macbook with installing HDF5, run `conda install h5py` in your conda env.
- If you launch the app and get an ffmpeg error, `RuntimeError: No ffmpeg exe could be found. Install ffmpeg on your system, or set the IMAGEIO_FFMPEG_EXE environment variable.` try running `conda install ffmpeg`.
- If you have an M1/M2 chip and use CEBRA within AmadeusGPT, and you get this error: `RuntimeError: Device type MPS is not supported for torch.Generator() api` run `pip install --upgrade torch`.

Expand Down
45 changes: 6 additions & 39 deletions amadeusgpt/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import cv2
import matplotlib.path as mpath
import msgpack
from moviepy.video.io.ffmpeg_writer import FFMPEG_VideoWriter
from moviepy.video.io.VideoFileClip import VideoFileClip
from PIL import Image
from pycocotools import mask as mask_decoder
from scipy.signal import savgol_filter
Expand Down Expand Up @@ -1404,26 +1402,21 @@ def get_kinematics(self, bodyparts: List[str], kin_type: str):
"""
assert kin_type in ["location", "velocity", "acceleration", "speed"]
ret = None
import dlc2kinematics


df = Database.get(type(self).__name__, "df")
n_kpts = Database.get(type(self).__name__, "n_kpts")
n_individuals = Database.get(type(self).__name__, "n_individuals")

if kin_type == "velocity":
ret = dlc2kinematics.compute_velocity(df, bodyparts=bodyparts)
ret = AnimalBehaviorAnalysis.get_velocity()

elif kin_type == "acceleration":
ret = dlc2kinematics.compute_acceleration(df, bodyparts=bodyparts)
ret = AnimalBehaviorAnalysis.get_acceleration()

elif kin_type == "speed":
ret = dlc2kinematics.compute_speed(df, bodyparts=bodyparts)
elif kin_type == "location":
if bodyparts[0] == "all":
mask = np.ones(df.shape[1], dtype=bool)
else:
mask = df.columns.get_level_values("bodyparts").isin(bodyparts)
ret = df.loc[:, mask]
ret = AnimalBehaviorAnalysis.get_speed()

else:
raise ValueError(f"{kin_type} is not supported")
n_kpts = len(bodyparts) if bodyparts != ["all"] else n_kpts
Expand Down Expand Up @@ -2794,30 +2787,4 @@ def animals_social_events(

return AnimalAnimalEvent(ret_events)

def generate_videos_by_events(self, events: List[Event]):
"""
Examples
--------
>>> # find where the animal is to the left of object 6 and create videos for those events
>>> def task_program():
>>> behavior_analysis = AnimalBehaviorAnalysis()
>>> left_to_object_events = behavior_analysis.animals_object_events('6', ['to_left'])
>>> behavior_analysis.generate_videos_by_events(left_to_object_events)
>>> return
"""
video_file_path = AnimalBehaviorAnalysis.get_video_file_path()
clip = VideoFileClip(video_file_path)
fps = clip.fps
for event_id, event in enumerate(events):
start_frame = np.where(event.mask)[0][0]
end_frame = np.where(event.mask)[0][-1]
start_in_seconds = start_frame / fps
end_in_seconds = end_frame / fps
output_file = f"event{event_id}.mp4"
trimmed_clip = clip.subclip(start_in_seconds, end_in_seconds)
writer = FFMPEG_VideoWriter(
output_file, trimmed_clip.size, fps=trimmed_clip.fps
)
trimmed_clip.write_videofile(output_file)
print(f"generated video at {output_file}")
return None

6 changes: 1 addition & 5 deletions amadeusgpt/logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from google.cloud import firestore

import os
import streamlit as st
import psutil
Expand All @@ -16,10 +16,6 @@ class AmadeusLogger:
logging.basicConfig(level=level)
filename = None
logger = logging.getLogger()
if "streamlit_cloud" in os.environ:
db = firestore.Client.from_service_account_json(
"amadeusgpt-a1849-firebase-adminsdk-eyfx1-4a1bbc8488.json"
)

@classmethod
def format(cls, message):
Expand Down
12 changes: 0 additions & 12 deletions amadeusgpt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@

############
# all these are for safe execution of generated code
from amadeusgpt.amadeus_security import check_code
from RestrictedPython import (
compile_restricted,
safe_globals,
safe_builtins,
utility_builtins,
limited_builtins,
)
from RestrictedPython.Guards import (
guarded_unpack_sequence,
guarded_iter_unpack_sequence,
)

############

Expand Down
5 changes: 2 additions & 3 deletions amadeusgpt/modules/implementation/embedding/umap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
import umap
from umap.umap_ import UMAP
import umap.umap_ as umap
from amadeusgpt.implementation import AnimalBehaviorAnalysis
from .transform import align_poses

Expand All @@ -10,7 +9,7 @@ def compute_embedding_with_umap_and_plot_embedding(
):
features = inputs.reshape(inputs.shape[0], -1)
features = np.nan_to_num(features)
reducer = UMAP(n_components=n_dimension, min_dist=0.5)
reducer = umap.UMAP()(n_components=n_dimension, min_dist=0.5)
embedding = reducer.fit_transform(features)

behavior_analysis = AnimalBehaviorAnalysis()
Expand Down
2 changes: 1 addition & 1 deletion conda/amadesuGPT.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ channels:
dependencies:
- python<3.10
- pip
- pytorch
- jupyter
- hdf5
Loading