Skip to content

Commit 00a6eac

Browse files
committed
updated autonaming and calculate_skeleton
1 parent a98ee88 commit 00a6eac

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

DeepLabStream.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,21 @@
66
https://github.com/SchwarzNeuroconLab/DeepLabStream
77
Licensed under GNU General Public License v3.0
88
"""
9-
import time
9+
import multiprocessing as mp
1010
import os
1111
import sys
12-
import multiprocessing as mp
12+
import time
1313
from importlib.util import find_spec
1414

15+
import click
1516
import cv2
1617
import numpy as np
1718
import pandas as pd
18-
import click
1919

20-
from utils.configloader import RESOLUTION, FRAMERATE, OUT_DIR, MODEL_NAME, MULTI_CAM, STACK_FRAMES, \
21-
ANIMALS_NUMBER, STREAMS, STREAMING_SOURCE
22-
from utils.poser import load_deeplabcut, get_pose, find_local_peaks_new, calculate_skeletons,\
23-
get_ma_pose, calculate_ma_skeletons, calculate_skeletons_dlc_live, transform_2skeleton
24-
from utils.plotter import plot_bodyparts, plot_metadata_frame
20+
from utils.configloader import RESOLUTION,FRAMERATE,OUT_DIR,MODEL_NAME,MULTI_CAM,STACK_FRAMES, \
21+
ANIMALS_NUMBER,STREAMS,STREAMING_SOURCE
22+
from utils.plotter import plot_bodyparts,plot_metadata_frame
23+
from utils.poser import load_deeplabcut,get_pose,calculate_skeletons
2524

2625

2726
def create_video_files(directory, devices, resolution, framerate, codec):
@@ -284,7 +283,7 @@ def get_pose_mp(input_q, output_q):
284283
index, frame = input_q.get()
285284
if MODEL_ORIGIN == 'DLC':
286285
scmap, locref, pose = get_pose(frame, config, sess, inputs, outputs)
287-
# TODO: REmove alterations to original
286+
# TODO: Remove alterations to original
288287
#peaks = find_local_peaks_new(scmap, locref, ANIMALS_NUMBER, config)
289288
peaks = pose
290289
if MODEL_ORIGIN == 'MADLC':
@@ -409,9 +408,7 @@ def get_analysed_frames(self) -> tuple:
409408

410409
# Getting the analysed data
411410
analysed_index, peaks = self._multiprocessing[camera]['output'].get()
412-
#TODO: REMOVE IF USELESS
413-
skeletons = [transform_2skeleton(peaks)]
414-
#skeletons = calculate_skeletons(peaks, ANIMALS_NUMBER)
411+
skeletons = calculate_skeletons(peaks, ANIMALS_NUMBER)
415412
print('', end='\r', flush=True) # this is the line you should not remove
416413
analysed_frame, depth_map, input_time = self.get_stored_frames(camera)
417414
analysis_time = time.time() - input_time

utils/poser.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ def find_local_peaks_new(scoremap: np.ndarray, local_reference: np.ndarray, anim
8585
stride = config['stride']
8686
# filtering scoremap
8787
scoremap[scoremap < 0.1] = 0
88-
plot_special_peak()
8988
for joint_num, joint in enumerate(all_joints_names):
9089
all_peaks[joint] = []
9190
# selecting the joint in scoremap and locref
@@ -243,23 +242,30 @@ def extract_to_animal_skeleton(coords):
243242
"""DLC LIVE & DeepPoseKit"""
244243

245244

246-
247245
def transform_2skeleton(pose):
246+
"""Transforms pose estimation into DLStream style "skeleton" posture. If ALL_BODYPARTS is not sufficient,
247+
it will autoname the bodyparts in style bp1, bp2 ..."""
248248
from utils.configloader import ALL_BODYPARTS
249-
skeleton = dict()
250-
counter = 0
251-
for bp in pose:
252-
skeleton[ALL_BODYPARTS[counter]] = tuple(np.array(bp[0:2],dtype = int))
253-
counter += 1
254-
return skeleton
249+
try:
250+
skeleton = dict()
251+
counter = 0
252+
for bp in pose:
253+
skeleton[ALL_BODYPARTS[counter]] = tuple(np.array(bp[0:2],dtype = int))
254+
counter += 1
255+
except KeyError:
256+
skeleton = dict()
257+
counter = 0
258+
for bp in pose:
259+
skeleton[f'bp{counter}'] = tuple(np.array(bp[0:2],dtype = int))
260+
counter += 1
255261

262+
return skeleton
256263

257264
def transform_2pose(skeleton):
258265
pose = np.array([*skeleton.values()])
259266
return pose
260267

261268

262-
263269
def calculate_skeletons_dlc_live(pose ,animals_number: int = 1) -> list:
264270
"""
265271
Creating skeletons from given pose

0 commit comments

Comments
 (0)