Merge branch 'master' into face_tremor

This commit is contained in:
vjbytes102
2020-12-09 18:20:40 -05:00
committed by GitHub
6 changed files with 29 additions and 17 deletions

View File

@@ -136,7 +136,7 @@ def process_movement(video_uri, out_dir, dbm_group, r_config, dlib_model):
facial_tremor.fac_tremor_process(video_uri, out_dir, r_config, model_output=True) facial_tremor.fac_tremor_process(video_uri, out_dir, r_config, model_output=True)
def process_nlp(video_uri, out_dir, dbm_group, r_config, deep_path): def process_nlp(video_uri, out_dir, dbm_group, tran_tog, r_config, deep_path):
""" """
processing nlp features processing nlp features
Args: Args:
@@ -144,12 +144,12 @@ def process_nlp(video_uri, out_dir, dbm_group, r_config, deep_path):
dbm_group: list of features to process; r_config: raw feature config object dbm_group: list of features to process; r_config: raw feature config object
deep_path: deep speech build path deep_path: deep speech build path
""" """
if dbm_group != None and len(dbm_group)>0 and 'nlp' not in dbm_group: if dbm_group != None and len(dbm_group)>0 and 'speech' not in dbm_group:
return return
logger.info('Processing nlp variables from data in {}'.format(video_uri)) logger.info('Processing nlp variables from data in {}'.format(video_uri))
transcribe.run_transcribe(video_uri, out_dir, r_config, deep_path) transcribe.run_transcribe(video_uri, out_dir, r_config, deep_path)
speech_features.run_speech_feature(video_uri, out_dir, r_config) speech_features.run_speech_feature(video_uri, out_dir, r_config, tran_tog)
def remove_file(file_path): def remove_file(file_path):

View File

@@ -10,6 +10,7 @@ import pandas as pd
import glob import glob
from os.path import join from os.path import join
import logging import logging
import shutil
from dbm_lib.dbm_features.raw_features.util import util as ut from dbm_lib.dbm_features.raw_features.util import util as ut
from dbm_lib.dbm_features.raw_features.util import nlp_util as n_util from dbm_lib.dbm_features.raw_features.util import nlp_util as n_util
@@ -21,7 +22,7 @@ speech_dir = 'nlp/speech_feature'
speech_ext = '_nlp.csv' speech_ext = '_nlp.csv'
transcribe_ext = 'nlp/transcribe/*_transcribe.csv' transcribe_ext = 'nlp/transcribe/*_transcribe.csv'
def run_speech_feature(video_uri, out_dir, r_config): def run_speech_feature(video_uri, out_dir, r_config, tran_tog):
""" """
Processing all patient's for fetching nlp features Processing all patient's for fetching nlp features
------------------- -------------------
@@ -42,6 +43,9 @@ def run_speech_feature(video_uri, out_dir, r_config):
logger.info('Saving Output file {} '.format(out_loc)) logger.info('Saving Output file {} '.format(out_loc))
ut.save_output(df_speech, out_loc, fl_name, speech_dir, speech_ext) ut.save_output(df_speech, out_loc, fl_name, speech_dir, speech_ext)
if (tran_tog == None) or (tran_tog != 'on'):
shutil.rmtree(os.path.dirname(transcribe_path[0]))
except Exception as e: except Exception as e:
logger.error('Failed to process video file') logger.error('Failed to process video file')

View File

@@ -126,7 +126,7 @@ def process_speech(transcribe_df,r_config):
Returns: Returns:
Dataframe for speech features Dataframe for speech features
""" """
transcribe_df = transcribe_df.replace(np.nan, '', regex=True)
err_transcribe = transcribe_df[r_config.err_reason].iloc[0] err_transcribe = transcribe_df[r_config.err_reason].iloc[0]
transcribe = transcribe_df[r_config.nlp_transcribe].iloc[0] transcribe = transcribe_df[r_config.nlp_transcribe].iloc[0]
total_time = transcribe_df[r_config.nlp_totalTime].iloc[0] total_time = transcribe_df[r_config.nlp_totalTime].iloc[0]

View File

@@ -158,7 +158,7 @@ def vad_get_segment_times(sample_rate, frame_duration_ms,
for frame in frames: for frame in frames:
is_speech = vad.is_speech(frame.bytes, sample_rate) is_speech = vad.is_speech(frame.bytes, sample_rate)
sys.stdout.write('1' if is_speech else '0') #sys.stdout.write('1' if is_speech else '0')
if not triggered: if not triggered:
ring_buffer.append((frame, is_speech)) ring_buffer.append((frame, is_speech))
num_voiced = len([f for f, speech in ring_buffer if speech]) num_voiced = len([f for f, speech in ring_buffer if speech])
@@ -167,7 +167,7 @@ def vad_get_segment_times(sample_rate, frame_duration_ms,
# TRIGGERED state. # TRIGGERED state.
if num_voiced > 0.9 * ring_buffer.maxlen: if num_voiced > 0.9 * ring_buffer.maxlen:
triggered = True triggered = True
sys.stdout.write('+(%s)' % (ring_buffer[0][0].timestamp,)) #sys.stdout.write('+(%s)' % (ring_buffer[0][0].timestamp,))
start_times.append(ring_buffer[0][0].timestamp) # BT start_times.append(ring_buffer[0][0].timestamp) # BT
ring_buffer.clear() ring_buffer.clear()
else: else:
@@ -179,18 +179,18 @@ def vad_get_segment_times(sample_rate, frame_duration_ms,
# unvoiced, then enter NOTTRIGGERED and yield whatever # unvoiced, then enter NOTTRIGGERED and yield whatever
# audio we've collected. # audio we've collected.
if num_unvoiced > 0.9 * ring_buffer.maxlen: if num_unvoiced > 0.9 * ring_buffer.maxlen:
sys.stdout.write('-(%s)' % (frame.timestamp + frame.duration)) #sys.stdout.write('-(%s)' % (frame.timestamp + frame.duration))
end_times.append(ring_buffer[0][0].timestamp + frame.duration) # BT end_times.append(ring_buffer[0][0].timestamp + frame.duration) # BT
triggered = False triggered = False
if triggered: # BT if were in triggered state at end of signal, set output time if triggered: # BT if were in triggered state at end of signal, set output time
sys.stdout.write('-(%s)' % (frame.timestamp + frame.duration)) #sys.stdout.write('-(%s)' % (frame.timestamp + frame.duration))
if len(ring_buffer)>0: if len(ring_buffer)>0:
end_times.append(ring_buffer[0][0].timestamp ) # BT end_times.append(ring_buffer[0][0].timestamp ) # BT
else: else:
# only get here in very rare case that we triggered on 2nd-to-last frame # only get here in very rare case that we triggered on 2nd-to-last frame
end_times.append(frame.timestamp + frame.duration) end_times.append(frame.timestamp + frame.duration)
sys.stdout.write('\n') #sys.stdout.write('\n')
return(start_times, end_times) return(start_times, end_times)

View File

@@ -39,9 +39,11 @@ def common_video(video_file, args, r_config):
of.process_open_face(video_file, os.path.dirname(video_file), out_path, OPENFACE_PATH, args.dbm_group,video_tracking=False) of.process_open_face(video_file, os.path.dirname(video_file), out_path, OPENFACE_PATH, args.dbm_group,video_tracking=False)
pf.process_facial(video_file, out_path, args.dbm_group, r_config) pf.process_facial(video_file, out_path, args.dbm_group, r_config)
pf.process_acoustic(video_file, out_path, args.dbm_group, r_config) pf.process_acoustic(video_file, out_path, args.dbm_group, r_config)
pf.process_nlp(video_file, out_path, args.dbm_group, r_config, DEEP_SPEECH)
pf.process_nlp(video_file, out_path, args.dbm_group, args.tr, r_config, DEEP_SPEECH)
if args.dbm_group == None or len(args.dbm_group)>0 and 'movement' in args.dbm_group: if args.dbm_group == None or len(args.dbm_group)>0 and 'movement' in args.dbm_group:
of.process_open_face(video_file, os.path.dirname(video_file), out_path, OPENFACE_PATH_VIDEO, args.dbm_group, video_tracking=True) of.process_open_face(video_file, os.path.dirname(video_file), out_path, OPENFACE_PATH_VIDEO, args.dbm_group, video_tracking=True)
pf.process_movement(video_file, out_path, args.dbm_group, r_config, DLIB_SHAPE_MODEL) pf.process_movement(video_file, out_path, args.dbm_group, r_config, DLIB_SHAPE_MODEL)
pf.remove_file(video_file) pf.remove_file(video_file)
@@ -85,7 +87,7 @@ def process_raw_audio_file(args, s_config, r_config):
out_path = os.path.join(args.output_path, 'raw_variables') out_path = os.path.join(args.output_path, 'raw_variables')
pf.process_acoustic(audio_file[0], out_path, args.dbm_group, r_config) pf.process_acoustic(audio_file[0], out_path, args.dbm_group, r_config)
pf.process_nlp(audio_file[0], out_path, args.dbm_group, r_config, DEEP_SPEECH) pf.process_nlp(audio_file[0], out_path, args.dbm_group, args.tr, r_config, DEEP_SPEECH)
else: else:
logger.info('Enter correct audio(*.wav) file path.') logger.info('Enter correct audio(*.wav) file path.')
@@ -136,7 +138,7 @@ def process_raw_audio_dir(args, s_config, r_config):
out_path = os.path.join(args.output_path, 'raw_variables') out_path = os.path.join(args.output_path, 'raw_variables')
pf.process_acoustic(audio, out_path, args.dbm_group, r_config) pf.process_acoustic(audio, out_path, args.dbm_group, r_config)
pf.process_nlp(audio, out_path, args.dbm_group, r_config, DEEP_SPEECH) pf.process_nlp(audio, out_path, args.dbm_group, args.tr, r_config, DEEP_SPEECH)
except Exception as e: except Exception as e:
logger.error('Failed to process wav file.') logger.error('Failed to process wav file.')
@@ -163,6 +165,7 @@ if __name__=="__main__":
parser.add_argument("--input_path", help="path to the input files", required=True) parser.add_argument("--input_path", help="path to the input files", required=True)
parser.add_argument("--output_path", help="path to the raw and derived variable output", required=True) parser.add_argument("--output_path", help="path to the raw and derived variable output", required=True)
parser.add_argument("--dbm_group", help="list of feature groups", nargs='+') parser.add_argument("--dbm_group", help="list of feature groups", nargs='+')
parser.add_argument("--tr", help="speech transcription toogle")
args = parser.parse_args() args = parser.parse_args()
s_config = config_reader.ConfigReader() s_config = config_reader.ConfigReader()

View File

@@ -7,6 +7,7 @@ helpFunction()
echo -e "\t--input_path: path to the input files" echo -e "\t--input_path: path to the input files"
echo -e "\t--output_path: path to the raw and derived variable output" echo -e "\t--output_path: path to the raw and derived variable output"
echo -e "\t--dbm_group: list of feature groups" echo -e "\t--dbm_group: list of feature groups"
echo -e "\t--tr: Toggle for speech transcription(optional)"
exit 1 # Exit script after printing help exit 1 # Exit script after printing help
} }
@@ -15,6 +16,7 @@ while [ $# -gt 0 ]; do
--input_path=*) input_path="${1#*=}" ;; --input_path=*) input_path="${1#*=}" ;;
--output_path=*) output_path="${1#*=}" ;; --output_path=*) output_path="${1#*=}" ;;
--dbm_group=*) dbm_group="${1#*=}" ;; --dbm_group=*) dbm_group="${1#*=}" ;;
--tr=*) tr="${1#*=}" ;;
*) helpFunction ;; *) helpFunction ;;
esac esac
shift shift
@@ -55,8 +57,11 @@ fi
if [[ $dbm_group == *"movement"* ]]; then if [[ $dbm_group == *"movement"* ]]; then
dbm_new="$dbm_new movement" dbm_new="$dbm_new movement"
fi fi
if [[ $dbm_group == *"nlp"* ]]; then if [[ $dbm_group == *"speech"* ]]; then
dbm_new="$dbm_new nlp" dbm_new="$dbm_new speech"
fi
if [[ $dbm_group == *"speech"* ]] && [[ ${tr} == "on" ]]; then
dbm_new="$dbm_new --tr ${tr}"
fi fi
#docker commands to run container #docker commands to run container
@@ -66,9 +71,9 @@ docker cp $input_path dbm_container:/app/raw_data
docker start dbm_container docker start dbm_container
if [ -z "$dbm_new" ] if [ -z "$dbm_new" ]
then then
docker exec -it dbm_container /bin/bash -c "python3 process_data.py --input_path /app/raw_data --output_path /app/output" docker exec -it dbm_container /bin/bash -c "python3 -W ignore process_data.py --input_path /app/raw_data --output_path /app/output"
else else
docker exec -it dbm_container /bin/bash -c "python3 process_data.py --input_path /app/raw_data --output_path /app/output --dbm_group$dbm_new" docker exec -it dbm_container /bin/bash -c "python3 -W ignore process_data.py --input_path /app/raw_data --output_path /app/output --dbm_group$dbm_new"
fi fi
docker cp dbm_container:/app/output $output_path docker cp dbm_container:/app/output $output_path