[merger] speed up numpy conversion
This commit is contained in:
parent
a98770610b
commit
456bd16a59
@ -56,28 +56,23 @@ class Merger(QRunnable):
|
|||||||
numpy.ndarray
|
numpy.ndarray
|
||||||
2D array, Coordinates of the bounding box for each detection. Shape: (num_detections, 4) x1, y1, x2, y2
|
2D array, Coordinates of the bounding box for each detection. Shape: (num_detections, 4) x1, y1, x2, y2
|
||||||
"""
|
"""
|
||||||
|
x = lambda kp: np.array([float(kpp) for kpp in kp[1:-1].split(",")])
|
||||||
logging.info("Converting to numpy ...")
|
logging.info("Converting to numpy ...")
|
||||||
|
# from IPython import embed
|
||||||
|
# embed()
|
||||||
|
dimensions = 2
|
||||||
key_columns = [c for c in df.columns if "key_" in c]
|
key_columns = [c for c in df.columns if "key_" in c]
|
||||||
box_columns = [c for c in df.columns if "box_" in c]
|
box_columns = [c for c in df.columns if "box_" in c]
|
||||||
num_frames = len(df)
|
keypoints = np.empty((len(df), len(key_columns), dimensions))
|
||||||
num_keypoints = len(key_columns)
|
visibility = np.empty((len(df), len(key_columns)))
|
||||||
dimensions = 2
|
boxcoordinates = np.stack([df[b].values for b in box_columns]).astype(np.float32).T
|
||||||
keypoints = np.empty((num_frames, num_keypoints, dimensions))
|
temp_v = df.visible.values
|
||||||
visibility = np.empty((num_frames, num_keypoints))
|
temp_k = np.stack([df[k].values for k in key_columns]).T
|
||||||
boxcoordinates = np.empty((num_frames, 4))
|
for i, k in enumerate(temp_k):
|
||||||
|
temp = np.array([x(kp) for kp in k])
|
||||||
for i, row in df.iterrows():
|
keypoints[i, :, :] = temp
|
||||||
for j, k in enumerate(key_columns):
|
visibility[i,:] = [float(val) for val in temp_v[i][1:-1].split()]
|
||||||
key_data = row[k]
|
|
||||||
l = list(map(float, list(key_data[1:-1].split(","))))
|
|
||||||
keypoints[i, j, :] = l
|
|
||||||
for j, b in enumerate(box_columns):
|
|
||||||
boxcoordinates[i, j] = row[b]
|
|
||||||
if isinstance(row["visible"], str):
|
|
||||||
vis = list(map(float, row["visible"][1:-1].split()))
|
|
||||||
visibility[i, :] = vis
|
|
||||||
else:
|
|
||||||
visibility[i, :] = row["visible"]
|
|
||||||
logging.info("Converting to numpy done!")
|
logging.info("Converting to numpy done!")
|
||||||
return keypoints, visibility, boxcoordinates
|
return keypoints, visibility, boxcoordinates
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user