示例#1
0
def main():
	"""
	Entry point of the script for training a model.
	i.e: python train.py -d data/dataset -a data/aligns -e 150
	"""

	print(r'''
   __         __     ______   __   __     ______     ______  
  /\ \       /\ \   /\  == \ /\ "-.\ \   /\  ___\   /\__  _\ 
  \ \ \____  \ \ \  \ \  _-/ \ \ \-.  \  \ \  __\   \/_/\ \/ 
   \ \_____\  \ \_\  \ \_\    \ \_\\"\_\  \ \_____\    \ \_\ 
    \/_____/   \/_/   \/_/     \/_/ \/_/   \/_____/     \/_/ 

  implemented by Omar Salinas
	''')

	ap = argparse.ArgumentParser()

	ap.add_argument('-d', '--dataset-path', required=True, help='Path to the dataset root directory')
	ap.add_argument('-a', '--aligns-path', required=True, help='Path to the directory containing all align files')
	ap.add_argument('-e', '--epochs', required=False, help='(Optional) Number of epochs to run', type=int, default=1)
	ap.add_argument('-ic', '--ignore-cache', required=False, help='(Optional) Force the generator to ignore the cache file', action='store_true', default=False)
	ap.add_argument('-s', '--start-epochs', required=False, help='Last Epochs to continue train',type=int, default=0)

	args = vars(ap.parse_args())

	dataset_path = os.path.realpath(args['dataset_path'])
	aligns_path  = os.path.realpath(args['aligns_path'])
	epochs       = args['epochs']
	ignore_cache = args['ignore_cache']
	start_epochs = args['start_epochs']

	if not is_dir(dataset_path):
		print(Fore.RED + '\nERROR: The dataset path is not a directory')
		return

	if not is_dir(aligns_path):
		print(Fore.RED + '\nERROR: The aligns path is not a directory')
		return

	if not isinstance(epochs, int) or epochs <= 0:
		print(Fore.RED + '\nERROR: The number of epochs must be a valid integer greater than zero')
		return

	name   = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M')
	# name = 'thai'
	# name = 'test3'
	config = TrainingConfig(dataset_path, aligns_path, epochs=epochs, use_cache=not ignore_cache, start_epochs=start_epochs)

        	
	train(name, config)
示例#2
0
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)
示例#3
0
def get_list_of_videos(path: str) -> [str]:
    path_is_file = is_file(path) and not is_dir(path)

    if path_is_file:
        print('Predicting for video at: {}'.format(path))
        video_paths = [path]
    else:
        print('Predicting batch at: {}'.format(path))
        video_paths = get_video_files_in_dir(path)
    return video_paths
示例#4
0
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)