Skip to content

Commit 77c2f43

Browse files
committed
Benchmark pytorch: fix loop
1 parent 58a094a commit 77c2f43

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

dlclive/benchmark_pytorch.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,6 @@ def benchmark(
173173
print(f"Error: Could not open video file {video_path}")
174174
return
175175

176-
# Start empty dict to save poses to for each frame
177-
poses, times = [], []
178-
# Create variable indicate current frame. Later in the code +1 is added to frame_index
179-
frame_index = 0
180-
181176
# Retrieve bodypart names and number of keypoints
182177
bodyparts = dlc_live.read_config()["metadata"]["bodyparts"]
183178
num_keypoints = len(bodyparts)
@@ -209,24 +204,27 @@ def benchmark(
209204
frameSize=(frame_width, frame_height),
210205
)
211206

207+
# Start empty dict to save poses to for each frame
208+
poses, times = [], []
209+
frame_index = 0
210+
212211
while True:
213212
ret, frame = cap.read()
214213
if not ret:
215214
break
216-
# if frame_index == 0:
217-
# pose = dlc_live.init_inference(frame) # load DLC model
215+
218216
try:
219-
# pose = dlc_live.get_pose(frame)
217+
start_time = time.perf_counter()
220218
if frame_index == 0:
221-
# dlc_live.dynamic = (False, dynamic[1], dynamic[2]) # TODO trying to fix issues with dynamic cropping jumping back and forth between dyanmic cropped and original image
222-
pose, inf_time = dlc_live.init_inference(frame) # load DLC model
219+
pose = dlc_live.init_inference(frame) # Loads model
223220
else:
224-
# dlc_live.dynamic = dynamic
225-
pose, inf_time = dlc_live.get_pose(frame)
221+
pose = dlc_live.get_pose(frame)
226222
except Exception as e:
227223
print(f"Error analyzing frame {frame_index}: {e}")
224+
frame_index += 1
228225
continue
229226

227+
inf_time = time.perf_counter() - start_time
230228
poses.append({"frame": frame_index, "pose": pose})
231229
times.append(inf_time)
232230

0 commit comments

Comments
 (0)