Spaces:
Runtime error
Runtime error
Update app_utils.py
Browse files- app_utils.py +3 -158
app_utils.py
CHANGED
@@ -108,7 +108,7 @@ def text_score(text):
|
|
108 |
score=-prob*10
|
109 |
else:
|
110 |
score=prob*10
|
111 |
-
print("from func:text_scoreββββ,text:"text,",score:",score)
|
112 |
return text,score
|
113 |
|
114 |
def speech_score(audio):
|
@@ -332,163 +332,8 @@ def video_score(video):
|
|
332 |
|
333 |
###########################################################################################################################
|
334 |
# def video_score(video):
|
335 |
-
|
336 |
-
#
|
337 |
-
# w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
338 |
-
# h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
339 |
-
# fps = np.round(cap.get(cv2.CAP_PROP_FPS))
|
340 |
-
|
341 |
-
# path_save_video_face = 'result_face.mp4'
|
342 |
-
# vid_writer_face = cv2.VideoWriter(path_save_video_face, cv2.VideoWriter_fourcc(*'mp4v'), fps, (224, 224))
|
343 |
-
|
344 |
-
# # path_save_video_hm = 'result_hm.mp4'
|
345 |
-
# # vid_writer_hm = cv2.VideoWriter(path_save_video_hm, cv2.VideoWriter_fourcc(*'mp4v'), fps, (224, 224))
|
346 |
-
|
347 |
-
# lstm_features = []
|
348 |
-
# count_frame = 1
|
349 |
-
# count_face = 0
|
350 |
-
# probs = []
|
351 |
-
# frames = []
|
352 |
-
# last_output = None
|
353 |
-
# last_heatmap = None
|
354 |
-
# cur_face = None
|
355 |
-
|
356 |
-
# with mp_face_mesh.FaceMesh(
|
357 |
-
# max_num_faces=1,
|
358 |
-
# refine_landmarks=False,
|
359 |
-
# min_detection_confidence=0.5,
|
360 |
-
# min_tracking_confidence=0.5) as face_mesh:
|
361 |
-
|
362 |
-
# while cap.isOpened():
|
363 |
-
# _, frame = cap.read()
|
364 |
-
# if frame is None: break
|
365 |
-
|
366 |
-
# frame_copy = frame.copy()
|
367 |
-
# frame_copy.flags.writeable = False
|
368 |
-
# frame_copy = cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
|
369 |
-
# results = face_mesh.process(frame_copy)
|
370 |
-
# frame_copy.flags.writeable = True
|
371 |
-
|
372 |
-
# if results.multi_face_landmarks:
|
373 |
-
# for fl in results.multi_face_landmarks:
|
374 |
-
# startX, startY, endX, endY = get_box(fl, w, h)
|
375 |
-
# cur_face = frame_copy[startY:endY, startX: endX]
|
376 |
-
|
377 |
-
# if count_face%config_data.FRAME_DOWNSAMPLING == 0:
|
378 |
-
# cur_face_copy = pth_processing(Image.fromarray(cur_face))
|
379 |
-
# with torch.no_grad():
|
380 |
-
# features = torch.nn.functional.relu(pth_model_static.extract_features(cur_face_copy)).detach().numpy()
|
381 |
-
|
382 |
-
# # grayscale_cam = cam(input_tensor=cur_face_copy)
|
383 |
-
# # grayscale_cam = grayscale_cam[0, :]
|
384 |
-
# # cur_face_hm = cv2.resize(cur_face,(224,224), interpolation = cv2.INTER_AREA)
|
385 |
-
# # cur_face_hm = np.float32(cur_face_hm) / 255
|
386 |
-
# # heatmap = show_cam_on_image(cur_face_hm, grayscale_cam, use_rgb=False)
|
387 |
-
# # last_heatmap = heatmap
|
388 |
-
|
389 |
-
# if len(lstm_features) == 0:
|
390 |
-
# lstm_features = [features]*10
|
391 |
-
# else:
|
392 |
-
# lstm_features = lstm_features[1:] + [features]
|
393 |
-
|
394 |
-
# lstm_f = torch.from_numpy(np.vstack(lstm_features))
|
395 |
-
# lstm_f = torch.unsqueeze(lstm_f, 0)
|
396 |
-
# with torch.no_grad():
|
397 |
-
# output = pth_model_dynamic(lstm_f).detach().numpy()
|
398 |
-
# last_output = output
|
399 |
-
|
400 |
-
# if count_face == 0:
|
401 |
-
# count_face += 1
|
402 |
-
|
403 |
-
# else:
|
404 |
-
# if last_output is not None:
|
405 |
-
# output = last_output
|
406 |
-
# # heatmap = last_heatmap
|
407 |
-
|
408 |
-
# elif last_output is None:
|
409 |
-
# output = np.empty((1, 7))
|
410 |
-
# output[:] = np.nan
|
411 |
-
|
412 |
-
# probs.append(output[0])
|
413 |
-
# frames.append(count_frame)
|
414 |
-
# else:
|
415 |
-
# if last_output is not None:
|
416 |
-
# lstm_features = []
|
417 |
-
# empty = np.empty((7))
|
418 |
-
# empty[:] = np.nan
|
419 |
-
# probs.append(empty)
|
420 |
-
# frames.append(count_frame)
|
421 |
-
|
422 |
-
# if cur_face is not None:
|
423 |
-
# # heatmap_f = display_info(heatmap, 'Frame: {}'.format(count_frame), box_scale=.3)
|
424 |
-
|
425 |
-
# cur_face = cv2.cvtColor(cur_face, cv2.COLOR_RGB2BGR)
|
426 |
-
# cur_face = cv2.resize(cur_face, (224,224), interpolation = cv2.INTER_AREA)
|
427 |
-
# cur_face = display_info(cur_face, 'Frame: {}'.format(count_frame), box_scale=.3)
|
428 |
-
# vid_writer_face.write(cur_face)
|
429 |
-
# # vid_writer_hm.write(heatmap_f)
|
430 |
-
|
431 |
-
# count_frame += 1
|
432 |
-
# if count_face != 0:
|
433 |
-
# count_face += 1
|
434 |
-
|
435 |
-
# vid_writer_face.release()
|
436 |
-
# # vid_writer_hm.release()
|
437 |
-
|
438 |
-
# stat = statistics_plot(frames, probs)
|
439 |
-
|
440 |
-
# if not stat:
|
441 |
-
# return None, None
|
442 |
-
|
443 |
-
# #for debug
|
444 |
-
# print(type(frames))
|
445 |
-
# print(frames)
|
446 |
-
# print(type(probs))
|
447 |
-
# print(probs)
|
448 |
-
# # to calculate scores
|
449 |
-
# nan=float('nan')
|
450 |
-
# s1 = 0
|
451 |
-
# s2 = 0
|
452 |
-
# s3 = 0
|
453 |
-
# s4 = 0
|
454 |
-
# s5 = 0
|
455 |
-
# s6 = 0
|
456 |
-
# s7 = 0
|
457 |
-
# frames_len=len(frames)
|
458 |
-
# for i in range(frames_len):
|
459 |
-
# if np.isnan(probs[i][0]):
|
460 |
-
# frames_len=frames_len-1
|
461 |
-
# else:
|
462 |
-
# s1=s1+probs[i][0]
|
463 |
-
# s2=s2+probs[i][1]
|
464 |
-
# s3=s3+probs[i][2]
|
465 |
-
# s4=s4+probs[i][3]
|
466 |
-
# s5=s5+probs[i][4]
|
467 |
-
# s6=s6+probs[i][5]
|
468 |
-
# s7=s7+probs[i][6]
|
469 |
-
# s1=s1/frames_len
|
470 |
-
# s2=s2/frames_len
|
471 |
-
# s3=s3/frames_len
|
472 |
-
# s4=s4/frames_len
|
473 |
-
# s5=s5/frames_len
|
474 |
-
# s6=s6/frames_len
|
475 |
-
# s7=s7/frames_len
|
476 |
-
# scores=[s1,s2,s3,s4,s5,s6,s7]
|
477 |
-
# scores_str=str(scores)
|
478 |
-
# with open("local_data/data.txt",'a', encoding="utf8") as f:
|
479 |
-
# f.write(scores_str+'\n')
|
480 |
-
|
481 |
-
# with open("local_data/data.txt",'r', encoding="utf8") as f:
|
482 |
-
# for i in f:
|
483 |
-
# print(i)
|
484 |
-
|
485 |
-
# score1=0*scores[0]-8*scores[1]+4*scores[2]+0*scores[3]+2*scores[4]+2*scores[5]+4*scores[6]
|
486 |
-
|
487 |
-
# #trans the audio file
|
488 |
-
# my_audio_clip = AudioFileClip(video)
|
489 |
-
# my_audio_clip.write_audiofile("data/audio.wav",ffmpeg_params=["-ac","1"])
|
490 |
-
# time.sleep(2)
|
491 |
-
|
492 |
# return stat,score1,"data/audio.wav"
|
493 |
|
494 |
# # #trans the audio file
|
|
|
108 |
score=-prob*10
|
109 |
else:
|
110 |
score=prob*10
|
111 |
+
print("from func:text_scoreββββ,text:",text,",score:",score)
|
112 |
return text,score
|
113 |
|
114 |
def speech_score(audio):
|
|
|
332 |
|
333 |
###########################################################################################################################
|
334 |
# def video_score(video):
|
335 |
+
#
|
336 |
+
# γγγγγγγγγγγγγγγγγ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
# return stat,score1,"data/audio.wav"
|
338 |
|
339 |
# # #trans the audio file
|