This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
268 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from abc import ABC, abstractmethod | ||
from random import shuffle | ||
from typing import Iterable, List | ||
|
||
from tfaip.base import DataGeneratorParams | ||
from tfaip.base.data.pipeline.definitions import PipelineMode, Sample | ||
|
||
|
||
class DataGenerator(ABC): | ||
def __init__(self, mode: PipelineMode, params: 'DataGeneratorParams'): | ||
params.validate() | ||
self.mode = mode | ||
self.params = params | ||
|
||
@abstractmethod | ||
def __len__(self): | ||
raise NotImplementedError | ||
|
||
@abstractmethod | ||
def generate(self) -> Iterable[Sample]: | ||
raise NotImplementedError | ||
|
||
|
||
class RawDataGenerator(DataGenerator): | ||
def __init__(self, raw_data: List[Sample], mode: PipelineMode, params: 'DataGeneratorParams'): | ||
super(RawDataGenerator, self).__init__(mode, params) | ||
self.raw_data = raw_data | ||
|
||
def __len__(self): | ||
return len(self.raw_data) | ||
|
||
def generate(self) -> Iterable[Sample]: | ||
if self.mode == PipelineMode.Training: | ||
shuffle(self.raw_data) | ||
return self.raw_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from dataclasses import dataclass, field | ||
from typing import List | ||
|
||
from dataclasses_json import dataclass_json | ||
|
||
from tfaip.base.data.pipeline.definitions import DataProcessorFactoryParams | ||
|
||
|
||
@dataclass_json | ||
@dataclass | ||
class SamplePipelineParams: | ||
run_parallel: bool = True | ||
sample_processors: List[DataProcessorFactoryParams] = field(default_factory=list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from typing import List, Optional, Callable, Iterable, TYPE_CHECKING | ||
|
||
from tfaip.base.data.pipeline.dataprocessor import DataProcessorFactory, SequenceProcessor | ||
from tfaip.base.data.pipeline.definitions import DataProcessorFactoryParams, Sample, PipelineMode | ||
from tfaip.base.data.pipeline.parallelpipeline import ParallelDataProcessorPipeline | ||
|
||
if TYPE_CHECKING: | ||
from tfaip.base.data.pipeline.datapipeline import DataPipeline | ||
|
||
|
||
def create_processor_fn(factory: DataProcessorFactory, processors: List[DataProcessorFactoryParams], params, mode: PipelineMode) -> SequenceProcessor: | ||
return factory.create_sequence(processors, params, mode) | ||
|
||
|
||
class SampleProcessorPipeline: | ||
def __init__(self, data_pipeline: 'DataPipeline', processor_fn: Optional[Callable[[], SequenceProcessor]] = None): | ||
self.data_pipeline = data_pipeline | ||
self.create_processor_fn = processor_fn | ||
|
||
def apply(self, samples: Iterable[Sample]) -> Iterable[Sample]: | ||
if not self.create_processor_fn: | ||
for sample in samples: | ||
yield sample | ||
else: | ||
processor = self.create_processor_fn() | ||
for sample in samples: | ||
r = processor.apply_on_sample(sample) | ||
if r is not None: | ||
yield r | ||
|
||
|
||
class ParallelSampleProcessingPipeline(SampleProcessorPipeline): | ||
def apply(self, samples: Iterable[Sample]) -> Iterable[Sample]: | ||
parallel_pipeline = ParallelDataProcessorPipeline(self.data_pipeline, samples, | ||
create_processor_fn=self.create_processor_fn, | ||
auto_repeat_input=False) | ||
for x in parallel_pipeline.output_generator(): | ||
yield x | ||
|
||
parallel_pipeline.join() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.