def create_ctf_file(seq_root, exp_root, output_file, is_training=True): databases = ["RAVDESS", "VIDTIMIT", "SAVEE"] nSeq = 0 fout = open(output_file, "w") for i, db in enumerate(databases): # each database db_dir = seq_root + "/" + db actors = get_items(db_dir) if is_training: if db == "RAVDESS": actors = actors[:20] elif db == "SAVEE": actors = actors[:3] elif db == "VIDTIMIT": actors = actors[:40] else: raise IOError("folder does not exist!") else: if db == "RAVDESS": actors = actors[20:] elif db == "SAVEE": actors = actors[3:] elif db == "VIDTIMIT": actors = actors[40:] else: raise IOError("folder does not exist!") for actor in actors: seq_dir = db_dir + "_feat/" + actor exp_dir = exp_root + "/" + db + "/" + actor items = get_items(seq_dir) for seq in items: print(seq_dir + "/" + seq) seq_path = seq_dir + "/" + seq + "/dbspectrogram.csv" exp_path = exp_dir + "/" + seq + ".npy" if plb.Path(seq_path).exists() and plb.Path(exp_path).exists(): # load data audio = np.loadtxt(seq_path, dtype=np.float32, delimiter=',') exp = np.load(exp_path) if exp.shape[0] != audio.shape[0]: print("length not matched") continue # write write_seq(nSeq, audio, exp, fout) nSeq += 1 else: print("file not exist") fout.close()
def test_one_seq(): # directory to store output video. It will be created if it doesn't exist save_dir = "../speech_dir/output_folder" model_file = "../speech_dir/model_audio2exp_2019-03-24-21-03/model_audio2exp_2019-03-24-21-03.dnn" # video directory holding separate frames of the video. Each image should be square. video_direct = "../FrontalFaceData" # spectrogram sequence is stored in a .csv file audio_dir = "../speech_dir/RAVDESS_feat" # AU labels are stored in an .npy file exp_dir = "../ExpLabels" make_dirs(video_direct,save_dir) video_dir=plb.Path(video_direct) for actor in video_dir.iterdir(): for frame_list in actor.iterdir(): try: video_path=plb.Path(video_direct + "/" + actor.name + "/" + frame_list.name) audio_path = plb.Path(audio_dir + "/" + actor.name + "/" + frame_list.name + "/dbspectrogram.csv") save_path=save_dir + "/" + actor.name + "/" + frame_list.name exp_path=plb.Path(exp_dir + "/" + actor.name + "/" + frame_list.stem + ".npy") video_path=str(video_path) except FileNotFoundError: print("doesn't exit") print(actor.name ,frame_list.name) video_list = get_items(video_path, "full") # set to None if video_dir does not exist model = C.load_model(model_file) visualize_one_audio_seq(model, video_list, audio_path, exp_path, save_path)
def test_one_seq(): # directory to store output video. It will be created if it doesn't exist save_dir = "../speech_dir/test_output_single" model_file = "../speech_dir/model_audio2exp_2019-03-24-21-03/model_audio2exp_2019-03-24-21-03.dnn" # video directory holding separate frames of the video. Each image should be square. video_dir = "../FrontalFaceData" # spectrogram sequence is stored in a .csv file audio_file = "../speech_dir/RAVDESS_feat/Actor_21/01-01-07-02-01-01-21/dbspectrogram.csv" # AU labels are stored in an .npy file exp_file = "../ExpLabels/RAVDESS/Actor_21/01-01-07-02-01-01-21.npy" video_list = get_items(video_dir, "full") # set to None if video_dir does not exist model = C.load_model(model_file) visualize_one_audio_seq(model, video_list, audio_file, exp_file, save_dir)
def test_one_seq(visualizer): """ Test one sequence """ ''' Load model ''' # model_file = "../Model/model_audio2exp_2020-02-25-13-02/model_audio2exp_2020-02-25-13-02.dnn" # model_file = "../Model/model_audio2exp_2020-02-25-15-07/model_audio2exp_2020-02-25-15-07.dnn" # GRU model_file = "../Model/model_audio2exp_2020-02-26-10-49/model_audio2exp_2020-02-26-10-49.dnn" # LSTM model = C.load_model(model_file) ''' Set input and output dir ''' current_time = get_current_time_string() modality_list = ["01"] vocal_channel_list = ["01"] emotion_list = ["01", "02", "03", "04", "05", "06", "07", "08"] emotion_intensity_list = ["01", "02"] statement_list = ["01", "02"] repetition_list = ["01", "02"] actor_list = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24"] actor = "05" for emotion in emotion_list: for emotion_intensity in emotion_intensity_list: for statement in statement_list: for repetition in repetition_list: if emotion == "01" and emotion_intensity == "02": continue start = time.time() sample = f"01-01-{emotion}-{emotion_intensity}-{statement}-{repetition}-{actor}" print(f"[Start] sample: {sample}") save_dir = f"../Test_output/LSTM_{sample}" # video directory holding separate frames of the video. Each image should be square. video_dir = f"../Data/RAVDESS/Video_Frame/Actor_{actor}/{sample}" # spectrogram sequence is stored in a .csv file audio_file = f"../Data/RAVDESS/features/Actor_{actor}/{sample}/dbspectrogram.csv" # AU labels are stored in an .npy file exp_file = f"../Data/ExpLabels/RAVDESS/Actor_{actor}/{sample}.npy" video_list = get_items(video_dir, "full") # set to None if video_dir does not exist visualize_one_audio_seq(model, video_list, audio_file, exp_file, visualizer, save_dir) duration = time.time() - start print(f"Time: {duration}") # filename = "01-01-01-01-01-01-01" # # directory to store output video. It will be created if it doesn't exist # save_dir = f"../Test_output/GRU_{filename}" # # video directory holding separate frames of the video. Each image should be square. # video_dir = f"../Data/RAVDESS/Video_Frame/Actor_01/{filename}" # # spectrogram sequence is stored in a .csv file # audio_file = f"../Data/RAVDESS/features/Actor_01/{filename}/dbspectrogram.csv" # # AU labels are stored in an .npy file # exp_file = f"../Data/ExpLabels/RAVDESS/Actor_01/{filename}.npy" # # single test # save_dir = "../Data/test_output_single" # # model_file = "../Model/model_audio2exp_2020-02-25-13-02/model_audio2exp_2020-02-25-13-02.dnn" # model_file = "../Model/model_audio2exp_2020-02-25-15-07/model_audio2exp_2020-02-25-15-07.dnn" # video_dir = "../Data/RAVDESS/Video_Frame/Actor_01/01-01-01-01-01-01-01" # audio_file = "../Data/RAVDESS/features/Actor_01/01-01-01-01-01-01-01/dbspectrogram.csv" # exp_file = "../Data/ExpLabels/RAVDESS/Actor_01/01-01-01-01-01-01-01.npy" # video_list = get_items(video_dir, "full") # set to None if video_dir does not exist # model = C.load_model(model_file) # # visualize_one_audio_seq(model, video_list, audio_file, exp_file, visualizer, save_dir) print("Eval finished!")