def test_predict(self, mock_load, mock_predict, mock_preprocess_ds): mock_load.return_value = ParallelPostFit() mock_preprocess_ds.return_value = [1, 2, 3] testable = SKLinearImageModel(pkl_file='trained_models/hog_sklearn.pkl') testable.predict(self.X) mock_load.assert_called_once() mock_predict.assert_called_once_with([1, 2, 3])
help='Limit to accept probability to predict a class.') arg_parser.add_argument('dir', help='Path to the input directory with image files.') parsed_args = arg_parser.parse_args(sys.argv[1:]) input_directory = parsed_args.dir pkl_file = parsed_args.pkl_file probability_threshold = float(parsed_args.probability_threshold) try: dir_parser = DirectoryParser(input_directory) except ValueError as e: print(*e.args) sys.exit(1) print(f"Data dir: {dir_parser}") feature_extractor = ImageFeatureExtractor() if parsed_args.model_type == ModelUsageType.sk: model = SKLinearImageModel(pkl_file=pkl_file, probability_threshold=probability_threshold) X, _ = feature_extractor.transform_image_to_dataset(dir_parser.full_path_image_files)[0] else: model = TFModel(pre_train=pkl_file, probability_threshold=probability_threshold) X, _ = feature_extractor.transform_image_to_dataset(dir_parser.full_path_image_files, image_size=model.image_shape[:-1])[0] prediction = model.predict(X) for filepath, prediction in zip(dir_parser.full_path_image_files, prediction): print(f"{filepath}: {prediction.value}")