def main(): """ Entry point of the script for using a trained model for predicting videos. i.e: python predict.py -w data/res/2018-09-26-02-30/lipnet_065_1.96.hdf5 -v data/dataset_eval """ print(r''' __ __ ______ __ __ ______ ______ /\ \ /\ \ /\ == \ /\ "-.\ \ /\ ___\ /\__ _\ \ \ \____ \ \ \ \ \ _-/ \ \ \-. \ \ \ __\ \/_/\ \/ \ \_____\ \ \_\ \ \_\ \ \_\\"\_\ \ \_____\ \ \_\ \/_____/ \/_/ \/_/ \/_/ \/_/ \/_____/ \/_/ implemented by Omar Salinas ''') ap = argparse.ArgumentParser() ap.add_argument('-v', '--video-path', required=True, help='Path to video file or batch directory to analize') ap.add_argument('-w', '--weights-path', required=True, help='Path to .hdf5 trained weights file') default_predictor = os.path.join(__file__, '..', 'data', 'predictors', 'shape_predictor_68_face_landmarks.dat') ap.add_argument("-pp", "--predictor-path", required=False, help="(Optional) Path to the predictor .dat file", default=default_predictor) args = vars(ap.parse_args()) weights = os.path.realpath(args['weights_path']) video = os.path.realpath(args['video_path']) predictor_path = os.path.realpath(args["predictor_path"]) if not is_file(weights) or get_file_extension(weights) != '.hdf5': print(Fore.RED + '\nERROR: Trained weights path is not a valid file') return if not is_file(video) and not is_dir(video): print( Fore.RED + '\nERROR: Path does not point to a video file nor to a directory') return if not is_file( predictor_path) or get_file_extension(predictor_path) != '.dat': print(Fore.RED + '\nERROR: Predictor path is not a valid file') return fcount = video_to_frames(os.path.join(video, 'p.mpg')) config = PredictConfig(weights, video, predictor_path, fcount) predict(config)
def get_video_data(path: str, detector, predictor) -> np.ndarray: if get_file_extension(path) == '.mpg': data = extract_video_data(path, detector, predictor, False) return reshape_and_normalize_video_data( data) if data is not None else None else: return get_video_data_from_file(path)
def main(): print(r''' __ __ ______ __ __ ______ __ __ ______ /\ \ /\ \ /\ == \ /\ "-.\ \ /\ ___\ /\_\_\_\ /\__ _\ \ \ \____ \ \ \ \ \ _-/ \ \ \-. \ \ \ __\ \/_/\_\/_ \/_/\ \/ \ \_____\ \ \_\ \ \_\ \ \_\\"\_\ \ \_____\ /\_\/\_\ \ \_\ \/_____/ \/_/ \/_/ \/_/ \/_/ \/_____/ \/_/\/_/ \/_/ ''') ap = argparse.ArgumentParser() ap.add_argument("-v", "--videos-path", required=True, help="Path to videos directory") ap.add_argument("-o", "--output-path", required=True, help="Path for the extracted frames") default_predictor = os.path.join(__file__, '..', '..', 'data', 'predictors', 'shape_predictor_68_face_landmarks.dat') ap.add_argument("-pp", "--predictor-path", required=False, help="(Optional) Path to the predictor .dat file", default=default_predictor) ap.add_argument("-p", "--pattern", required=False, help="(Optional) File name pattern to match", default='*.mpg') ap.add_argument("-fv", "--first-video", required=False, help="(Optional) First video index extracted in each speaker (inclusive)", type=int, default=0) ap.add_argument("-lv", "--last-video", required=False, help="(Optional) Last video index extracted in each speaker (exclusive)", type=int, default=1000) args = vars(ap.parse_args()) videos_path = os.path.realpath(args["videos_path"]) output_path = os.path.realpath(args["output_path"]) pattern = args["pattern"] first_video = args["first_video"] last_video = args["last_video"] predictor_path = os.path.realpath(args["predictor_path"]) if not is_dir(videos_path): print(Fore.RED + 'ERROR: Invalid path to videos directory') return if not isinstance(output_path, str): print(Fore.RED + 'ERROR: Invalid path to output directory') return if not is_file(predictor_path) or get_file_extension(predictor_path) != '.dat': print(Fore.RED + '\nERROR: Predictor path is not a valid file') return if not isinstance(first_video, int) or first_video < 0: print(Fore.RED + '\nERROR: The first video index must be a valid positive integer') return if not isinstance(last_video, int) or last_video < first_video: print(Fore.RED + '\nERROR: The last video index must be a valid positive integer greater than the first video index') return extract_to_npy(videos_path, output_path, predictor_path, pattern, first_video, last_video)
def get_entire_video_data(path: str) -> np.ndarray: if get_file_extension(path) == '.mpg': return np.swapaxes(skvideo.io.vread(path), 1, 2) else: return get_video_data_from_file(path)