Skip to content

Commit becfe83

Browse files
Update
1 parent 79eda22 commit becfe83

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

tools/utils.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ def postprocess(self, output, print_output=True, top_k=1):
122122
output: list
123123
"""
124124
if not isinstance(self.input_file, list):
125-
self.input_file = [self.input_file, ]
125+
self.input_file = [
126+
self.input_file,
127+
]
126128
output = output[0] # [B, num_cls]
127129
N = output.shape[0]
128130
output = F.softmax(paddle.to_tensor(output), axis=-1).numpy()
@@ -298,7 +300,7 @@ def _gen_props(self, pred_bm, pred_start, pred_end, print_output=True):
298300

299301
# print top-5 predictions
300302
if print_output:
301-
print("BMN Inference results of {0} :".format(self.feat_path))
303+
print("Current video file: {0} :".format(self.feat_path))
302304
for pred in proposal_list[:5]:
303305
print(pred)
304306

@@ -400,6 +402,27 @@ def preprocess(self, input_file):
400402
res.append(np.expand_dims(item, axis=0).copy())
401403
return res
402404

405+
def postprocess(self, output, print_output=True):
406+
"""
407+
output: list
408+
"""
409+
if not isinstance(self.input_file, list):
410+
self.input_file = [
411+
self.input_file,
412+
]
413+
output = output[0] # [B, num_cls]
414+
# output = F.softmax(paddle.to_tensor(output), axis=-1).numpy() # done in it's head
415+
N = output.shape[0]
416+
for i in range(N):
417+
classes = np.argpartition(output[i], -self.top_k)[-self.top_k:]
418+
classes = classes[np.argsort(-output[i, classes])]
419+
scores = output[i, classes]
420+
if print_output:
421+
print("Current video file: {0}".format(self.input_file[i]))
422+
for j in range(self.top_k):
423+
print("\ttop-{0} class: {1}".format(j + 1, classes[j]))
424+
print("\ttop-{0} score: {1}".format(j + 1, scores[j]))
425+
403426

404427
@INFERENCE.register()
405428
class STGCN_Inference_helper(Base_Inference_helper):

0 commit comments

Comments
 (0)