def init_model(transform): use_gpu = True inference_engine = None neural_network = None postprocessors = None if transform == 'gesture': # Load feature extractor feature_extractor = feature_extractors.StridedInflatedEfficientNet() feature_extractor.load_weights_from_resources( 'backbone/strided_inflated_efficientnet.ckpt') feature_extractor.eval() # Load a logistic regression classifier gesture_classifier = LogisticRegression( num_in=feature_extractor.feature_dim, num_out=30) checkpoint = load_weights_from_resources( 'gesture_detection/efficientnet_logistic_regression.ckpt') gesture_classifier.load_state_dict(checkpoint) gesture_classifier.eval() # Concatenate feature extractor and met converter neural_network = Pipe(feature_extractor, gesture_classifier) postprocessors = [ PostprocessClassificationOutput(INT2LAB, smoothing=4) ] elif transform == 'fitness': weight = float(60) height = float(170) age = float(20) gender = 'female' # Load feature extractor feature_extractor = feature_extractors.StridedInflatedMobileNetV2() feature_extractor.load_weights_from_resources( 'backbone/strided_inflated_mobilenet.ckpt') feature_extractor.eval() # Load fitness activity classifier gesture_classifier = LogisticRegression( num_in=feature_extractor.feature_dim, num_out=81) checkpoint = load_weights_from_resources( 'fitness_activity_recognition/mobilenet_logistic_regression.ckpt') gesture_classifier.load_state_dict(checkpoint) gesture_classifier.eval() # Load MET value converter met_value_converter = calorie_estimation.METValueMLPConverter() checkpoint = load_weights_from_resources( 'calorie_estimation/mobilenet_features_met_converter.ckpt') met_value_converter.load_state_dict(checkpoint) met_value_converter.eval() # Concatenate feature extractor with downstream nets neural_network = Pipe( feature_extractor, feature_converter=[gesture_classifier, met_value_converter]) postprocessors = [ PostprocessClassificationOutput(INT2LAB, smoothing=8, indices=[0]), calorie_estimation.CalorieAccumulator(weight=weight, height=height, age=age, gender=gender, smoothing=12, indices=[1]) ] if neural_network is not None: inference_engine = InferenceEngine(neural_network, use_gpu=use_gpu) start_inference(inference_engine) return (inference_engine, postprocessors), None
path_out = args['--path_out'] or None title = args['--title'] or None use_gpu = False # Load feature extractor feature_extractor = feature_extractors.StridedInflatedEfficientNet() feature_extractor.load_weights_from_resources('backbone/strided_inflated_efficientnet.ckpt') # feature_extractor = feature_extractors.StridedInflatedMobileNetV2() # feature_extractor.load_weights_from_resources(r'../resources\backbone\strided_inflated_mobilenet.ckpt') feature_extractor.eval() # Load a logistic regression classifier gesture_classifier = LogisticRegression(num_in=feature_extractor.feature_dim, num_out=30) checkpoint = load_weights_from_resources('gesture_detection/efficientnet_logistic_regression.ckpt') # checkpoint = load_weights_from_resources('gesture_detection/mobilenet_logistic_regression.ckpt') gesture_classifier.load_state_dict(checkpoint) gesture_classifier.eval() # Concatenate feature extractor and met converter net = Pipe(feature_extractor, gesture_classifier) postprocessor = [ PostprocessClassificationOutput(INT2LAB, smoothing=4) ] display_ops = [ sense.display.DisplayFPS(expected_camera_fps=net.fps, expected_inference_fps=net.fps / net.step_size),
def test_load_weights_from_resources_on_absolute_path(self): _ = nn_utils.load_weights_from_resources(self.ABSOLUTE_PATH)
def test_load_weights_from_resources_on_relative_path(self): _ = nn_utils.load_weights_from_resources(self.RELATIVE_PATH)
camera_id = int(args['--camera_id'] or 0) path_in = args['--path_in'] or None path_out = args['--path_out'] or None title = args['--title'] or None use_gpu = args['--use_gpu'] # Load feature extractor feature_extractor = feature_extractors.StridedInflatedEfficientNet() feature_extractor.load_weights_from_resources( 'backbone/strided_inflated_efficientnet.ckpt') feature_extractor.eval() # Load a logistic regression classifier gesture_classifier = LogisticRegression( num_in=feature_extractor.feature_dim, num_out=5) checkpoint = load_weights_from_resources( 'fitness_rep_counting/efficientnet_logistic_regression.ckpt') gesture_classifier.load_state_dict(checkpoint) gesture_classifier.eval() # Concatenate feature extractor and met converter net = Pipe(feature_extractor, gesture_classifier) postprocessor = [ PostprocessRepCounts(INT2LAB), PostprocessClassificationOutput(INT2LAB, smoothing=1) ] display_ops = [ sense.display.DisplayFPS(expected_camera_fps=net.fps, expected_inference_fps=net.fps / net.step_size),
use_gpu = args['--use_gpu'] camera_id = int(args['--camera_id'] or 0) path_in = args['--path_in'] or None path_out = args['--path_out'] or None title = args['--title'] or None # Load feature extractor feature_extractor = feature_extractors.StridedInflatedMobileNetV2() feature_extractor.load_weights_from_resources( 'backbone/strided_inflated_mobilenet.ckpt') feature_extractor.eval() # Load MET value converter met_value_converter = calorie_estimation.METValueMLPConverter() checkpoint = load_weights_from_resources( 'calorie_estimation/mobilenet_features_met_converter.ckpt') met_value_converter.load_state_dict(checkpoint) met_value_converter.eval() # Concatenate feature extractor and met converter net = Pipe(feature_extractor, met_value_converter) post_processors = [ calorie_estimation.CalorieAccumulator(weight=weight, height=height, age=age, gender=gender, smoothing=12) ] display_ops = [
camera_id = int(args['--camera_id'] or 0) path_in = args['--path_in'] or None path_out = args['--path_out'] or None title = args['--title'] or None use_gpu = args['--use_gpu'] # Load feature extractor feature_extractor = feature_extractors.StridedInflatedMobileNetV2() feature_extractor.load_weights_from_resources( 'backbone/strided_inflated_mobilenet.ckpt') feature_extractor.eval() # Load fitness activity classifier gesture_classifier = LogisticRegression( num_in=feature_extractor.feature_dim, num_out=81) checkpoint = load_weights_from_resources( 'fitness_activity_recognition/mobilenet_logistic_regression.ckpt') gesture_classifier.load_state_dict(checkpoint) gesture_classifier.eval() # Load MET value converter met_value_converter = calorie_estimation.METValueMLPConverter() checkpoint = load_weights_from_resources( 'calorie_estimation/mobilenet_features_met_converter.ckpt') met_value_converter.load_state_dict(checkpoint) met_value_converter.eval() # Concatenate feature extractor with downstream nets net = Pipe(feature_extractor, feature_converter=[gesture_classifier, met_value_converter]) post_processors = [