def main(args): # Read command line args audio_file = args.audio_file_path model = ModelParams(args.model_file_path) labels = dict_labels(args.labels_file_path) # Create the ArmNN inference runner network = ArmnnNetworkExecutor(model.path, args.preferred_backends) audio_capture = AudioCapture(model) buffer = audio_capture.from_audio_file(audio_file) # Create the preprocessor mfcc_params = MFCCParams(sampling_freq=16000, num_fbank_bins=128, mel_lo_freq=0, mel_hi_freq=8000, num_mfcc_feats=13, frame_len=512, use_htk_method=False, n_FFT=512) mfcc = MFCC(mfcc_params) preprocessor = Preprocessor(mfcc, model_input_size=296, stride=160) text = "" current_r_context = "" is_first_window = True print("Processing Audio Frames...") for audio_data in buffer: # Prepare the input Tensors input_tensors = prepare_input_tensors(audio_data, network.input_binding_info, preprocessor) # Run inference output_result = network.run(input_tensors) # Slice and Decode the text, and store the right context current_r_context, text = decode_text(is_first_window, labels, output_result) is_first_window = False display_text(text) print(current_r_context, flush=True)
def main(args): video, video_writer, frame_count = init_video_file_capture( args.video_file_path, args.output_video_file_path) executor = ArmnnNetworkExecutor(args.model_file_path, args.preferred_backends) process_output, resize_factor = get_model_processing( args.model_name, video, executor.input_binding_info) labels = dict_labels(args.label_path, include_rgb=True) for _ in tqdm(frame_count, desc='Processing frames'): frame_present, frame = video.read() if not frame_present: continue input_tensors = preprocess(frame, executor.input_binding_info) output_result = executor.run(input_tensors) detections = process_output(output_result) draw_bounding_boxes(frame, detections, resize_factor, labels) video_writer.write(frame) print('Finished processing frames') video.release(), video_writer.release()
def main(args): video, video_writer, frame_count = init_video(args.video_file_path, args.output_video_file_path) net_id, runtime, input_binding_info, output_binding_info = create_network( args.model_file_path, args.preferred_backends) output_tensors = ann.make_output_tensors(output_binding_info) labels, process_output, resize_factor = get_model_processing( args.model_name, video, input_binding_info) labels = dict_labels( labels if args.label_path is None else args.label_path) for _ in tqdm(frame_count, desc='Processing frames'): frame_present, frame = video.read() if not frame_present: continue input_tensors = preprocess(frame, input_binding_info) inference_output = execute_network(input_tensors, output_tensors, runtime, net_id) detections = process_output(inference_output) draw_bounding_boxes(frame, detections, resize_factor, labels) video_writer.write(frame) print('Finished processing frames') video.release(), video_writer.release()
def main(args): video = init_video_stream_capture(args.video_source) executor = ArmnnNetworkExecutor(args.model_file_path, args.preferred_backends) process_output, resize_factor = get_model_processing( args.model_name, video, executor.input_binding_info) labels = dict_labels(args.label_path, include_rgb=True) while True: frame_present, frame = video.read() frame = cv2.flip(frame, 1) # Horizontally flip the frame if not frame_present: raise RuntimeError('Error reading frame from video stream') input_tensors = preprocess(frame, executor.input_binding_info) print("Running inference...") output_result = executor.run(input_tensors) detections = process_output(output_result) draw_bounding_boxes(frame, detections, resize_factor, labels) cv2.imshow('PyArmNN Object Detection Demo', frame) if cv2.waitKey(1) == 27: print('\nExit key activated. Closing video...') break video.release(), cv2.destroyAllWindows()
def main(args): enable_profile = args.profiling_enabled == "true" action_profiler = Profiling(enable_profile) overall_profiler = Profiling(enable_profile) overall_profiler.profiling_start() action_profiler.profiling_start() if args.tflite_delegate_path is not None: from network_executor_tflite import TFLiteNetworkExecutor as NetworkExecutor exec_input_args = (args.model_file_path, args.preferred_backends, args.tflite_delegate_path) else: from network_executor import ArmnnNetworkExecutor as NetworkExecutor exec_input_args = (args.model_file_path, args.preferred_backends) executor = NetworkExecutor(*exec_input_args) action_profiler.profiling_stop_and_print_us("Executor initialization") action_profiler.profiling_start() video, video_writer, frame_count = init_video_file_capture( args.video_file_path, args.output_video_file_path) process_output, resize_factor = get_model_processing( args.model_name, video, executor.get_shape()) action_profiler.profiling_stop_and_print_us("Video initialization") labels = dict_labels(args.label_path, include_rgb=True) if all(element is not None for element in [ args.style_predict_model_file_path, args.style_transfer_model_file_path, args.style_image_path, args.style_transfer_class ]): style_image = cv2.imread(args.style_image_path) action_profiler.profiling_start() style_transfer_executor = style_transfer.StyleTransfer( args.style_predict_model_file_path, args.style_transfer_model_file_path, style_image, args.preferred_backends, args.tflite_delegate_path) action_profiler.profiling_stop_and_print_us( "Style Transfer Executor initialization") for _ in tqdm(frame_count, desc='Processing frames'): frame_present, frame = video.read() if not frame_present: continue model_name = args.model_name if model_name == "ssd_mobilenet_v1": input_data = preprocess(frame, executor.get_data_type(), executor.get_shape(), True) else: input_data = preprocess(frame, executor.get_data_type(), executor.get_shape(), False) action_profiler.profiling_start() output_result = executor.run([input_data]) action_profiler.profiling_stop_and_print_us("Running inference") detections = process_output(output_result) if all(element is not None for element in [ args.style_predict_model_file_path, args.style_transfer_model_file_path, args.style_image_path, args.style_transfer_class ]): action_profiler.profiling_start() frame = style_transfer.create_stylized_detection( style_transfer_executor, args.style_transfer_class, frame, detections, resize_factor, labels) action_profiler.profiling_stop_and_print_us( "Running Style Transfer") else: draw_bounding_boxes(frame, detections, resize_factor, labels) video_writer.write(frame) print('Finished processing frames') overall_profiler.profiling_stop_and_print_us("Total compute time") video.release(), video_writer.release()
def main(args): enable_profile = args.profiling_enabled == "true" action_profiler = Profiling(enable_profile) action_profiler.profiling_start() if args.tflite_delegate_path is not None: from network_executor_tflite import TFLiteNetworkExecutor as NetworkExecutor exec_input_args = (args.model_file_path, args.preferred_backends, args.tflite_delegate_path) else: from network_executor import ArmnnNetworkExecutor as NetworkExecutor exec_input_args = (args.model_file_path, args.preferred_backends) executor = NetworkExecutor(*exec_input_args) action_profiler.profiling_stop_and_print_us("Executor initialization") action_profiler.profiling_start() video = init_video_stream_capture(args.video_source) action_profiler.profiling_stop_and_print_us("Video initialization") model_name = args.model_name process_output, resize_factor = get_model_processing( args.model_name, video, executor.get_shape()) labels = dict_labels(args.label_path, include_rgb=True) if all(element is not None for element in [ args.style_predict_model_file_path, args.style_transfer_model_file_path, args.style_image_path, args.style_transfer_class ]): style_image = cv2.imread(args.style_image_path) action_profiler.profiling_start() style_transfer_executor = style_transfer.StyleTransfer( args.style_predict_model_file_path, args.style_transfer_model_file_path, style_image, args.preferred_backends, args.tflite_delegate_path) action_profiler.profiling_stop_and_print_us( "Style Transfer Executor initialization") while True: frame_present, frame = video.read() frame = cv2.flip(frame, 1) # Horizontally flip the frame if not frame_present: raise RuntimeError('Error reading frame from video stream') action_profiler.profiling_start() if model_name == "ssd_mobilenet_v1": input_data = preprocess(frame, executor.get_data_type(), executor.get_shape(), True) else: input_data = preprocess(frame, executor.get_data_type(), executor.get_shape(), False) output_result = executor.run([input_data]) if not enable_profile: print("Running inference...") action_profiler.profiling_stop_and_print_us("Running inference...") detections = process_output(output_result) if all(element is not None for element in [ args.style_predict_model_file_path, args.style_transfer_model_file_path, args.style_image_path, args.style_transfer_class ]): action_profiler.profiling_start() frame = style_transfer.create_stylized_detection( style_transfer_executor, args.style_transfer_class, frame, detections, resize_factor, labels) action_profiler.profiling_stop_and_print_us( "Running Style Transfer") else: draw_bounding_boxes(frame, detections, resize_factor, labels) cv2.imshow('PyArmNN Object Detection Demo', frame) if cv2.waitKey(1) == 27: print('\nExit key activated. Closing video...') break video.release(), cv2.destroyAllWindows()