2 Copyright (c) 2019 Intel Corporation
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
17 from ..config import ConfigValidator, StringField
18 from ..preprocessor.preprocessors import Preprocessor
21 class PreprocessingExecutor:
22 def __init__(self, processors=None, dataset_name='custom', dataset_meta=None):
24 self.dataset_meta = dataset_meta
30 for processor in processors:
31 preprocessor_config = PreprocessorConfig(
32 "{}.preprocessors".format(dataset_name), on_extra_argument=ConfigValidator.IGNORE_ON_EXTRA_ARGUMENT
35 type_ = processor.get(identifier)
36 preprocessor_config.validate(processor, type_)
37 preprocessor = Preprocessor.provide(processor[identifier], config=processor, name=type_)
39 self.processors.append(preprocessor)
41 def process(self, images, batch_annotation=None):
42 for i, _ in enumerate(images):
43 for processor in self.processors:
44 images[i] = processor(
45 image=images[i], annotation_meta=batch_annotation[i].metadata if batch_annotation else None
51 class PreprocessorConfig(ConfigValidator):
52 type = StringField(choices=Preprocessor.providers)