Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
removed unused modules. Moved hdf5 to conda yaml. Removed unused depe…
…ndencies. Added installation script
  • Loading branch information
yeshaokai committed Jun 1, 2024
commit 11fc9af4a9341726210360bb4ec3a3249aac01b8
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 @@ -1393,26 +1391,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 @@ -2772,30 +2765,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