This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 212
Data Pipeline V2: Cleanup #1018
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bec0d11
update
tchaton 58a51de
update
tchaton aad4f64
update
tchaton b375dee
update
tchaton 0ca1b79
update
tchaton 88f6f85
Merge branch 'master' into cleanup_api
tchaton cdd5c43
update
tchaton 8e0a352
Merge branch 'cleanup_api' of https://github.com/PyTorchLightning/lig…
tchaton fa8688c
resolve bug
tchaton a38ea32
update
tchaton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,10 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from functools import partial | ||
from typing import Any, Callable, Dict, Hashable, Optional, Sequence, Tuple, Type, TYPE_CHECKING, Union | ||
from typing import Any, Callable, Dict, Hashable, List, Optional, Sequence, Tuple, Type, TYPE_CHECKING, Union | ||
|
||
from flash.core.data.data_module import DataModule | ||
from flash.core.data.data_pipeline import DataPipelineState | ||
from flash.core.data.io.input import DataKeys, InputFormat | ||
from flash.core.data.io.input_transform import InputTransform | ||
from flash.core.integrations.fiftyone.utils import FiftyOneLabelUtilities | ||
|
@@ -151,11 +152,12 @@ def __init__( | |
"coco": partial(IceVisionInput, parser=COCOBBoxParser), | ||
"via": partial(IceVisionInput, parser=VIABBoxParser), | ||
"voc": partial(IceVisionInput, parser=VOCBBoxParser), | ||
"icedata": partial(IceVisionInput, parser=parser), | ||
InputFormat.FILES: IceVisionInput, | ||
InputFormat.FOLDERS: partial(IceVisionInput, parser=parser), | ||
InputFormat.FIFTYONE: ObjectDetectionFiftyOneInput, | ||
}, | ||
default_input=InputFormat.FILES, | ||
default_input="icedata", | ||
) | ||
|
||
self._default_collate = self._identity | ||
|
@@ -179,7 +181,7 @@ class ObjectDetectionData(DataModule): | |
input_transform_cls = ObjectDetectionInputTransform | ||
|
||
@classmethod | ||
def from_folders( | ||
def from_icedata( | ||
cls, | ||
train_folder: Optional[str] = None, | ||
train_ann_file: Optional[str] = None, | ||
|
@@ -196,11 +198,14 @@ def from_folders( | |
parser: Optional[Union[Callable, Type[Parser]]] = None, | ||
**data_module_kwargs, | ||
) -> "ObjectDetectionData": | ||
|
||
dataset_kwargs = dict(parser=parser, data_pipeline_state=DataPipelineState()) | ||
|
||
return cls( | ||
IceVisionInput(RunningStage.TRAINING, train_folder, train_ann_file, parser=parser), | ||
IceVisionInput(RunningStage.VALIDATING, val_folder, val_ann_file, parser=parser), | ||
IceVisionInput(RunningStage.TESTING, test_folder, test_ann_file, parser=parser), | ||
IceVisionInput(RunningStage.PREDICTING, predict_folder, parser=parser), | ||
IceVisionInput(RunningStage.TRAINING, train_folder, train_ann_file, **dataset_kwargs), | ||
IceVisionInput(RunningStage.VALIDATING, val_folder, val_ann_file, **dataset_kwargs), | ||
IceVisionInput(RunningStage.TESTING, test_folder, test_ann_file, **dataset_kwargs), | ||
IceVisionInput(RunningStage.PREDICTING, predict_folder, **dataset_kwargs), | ||
input_transform=cls.input_transform_cls( | ||
train_transform, | ||
val_transform, | ||
|
@@ -249,7 +254,7 @@ def from_coco( | |
:class:`~flash.core.data.io.input_transform.InputTransform` hook names to callable transforms. | ||
image_size: The size to resize images (and their bounding boxes) to. | ||
""" | ||
return cls.from_folders( | ||
return cls.from_icedata( | ||
train_folder=train_folder, | ||
train_ann_file=train_ann_file, | ||
val_folder=val_folder, | ||
|
@@ -304,7 +309,7 @@ def from_voc( | |
:class:`~flash.core.data.io.input_transform.InputTransform` hook names to callable transforms. | ||
image_size: The size to resize images (and their bounding boxes) to. | ||
""" | ||
return cls.from_folders( | ||
return cls.from_icedata( | ||
train_folder=train_folder, | ||
train_ann_file=train_ann_file, | ||
val_folder=val_folder, | ||
|
@@ -359,7 +364,7 @@ def from_via( | |
:class:`~flash.core.data.io.input_transform.InputTransform` hook names to callable transforms. | ||
image_size: The size to resize images (and their bounding boxes) to. | ||
""" | ||
return cls.from_folders( | ||
return cls.from_icedata( | ||
train_folder=train_folder, | ||
train_ann_file=train_ann_file, | ||
val_folder=val_folder, | ||
|
@@ -407,3 +412,80 @@ def from_fiftyone( | |
), | ||
**data_module_kwargs, | ||
) | ||
|
||
@classmethod | ||
def from_folders( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ethanwharris Not sure about those. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like it 😃 |
||
cls, | ||
predict_folder: Optional[str] = None, | ||
predict_transform: Optional[Dict[str, Callable]] = None, | ||
image_size: Tuple[int, int] = (128, 128), | ||
**data_module_kwargs: Any, | ||
) -> "DataModule": | ||
"""Creates a :class:`~flash.core.data.data_module.DataModule` object from the given folders using the | ||
:class:`~flash.core.data.io.input.Input` of name | ||
:attr:`~flash.core.data.io.input.InputFormat.FOLDERS` | ||
from the passed or constructed :class:`~flash.core.data.io.input_transform.InputTransform`. | ||
tchaton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Args: | ||
predict_folder: The folder containing the predict data. | ||
predict_transform: The dictionary of transforms to use during predicting which maps | ||
data_module_kwargs: The keywords arguments for creating the datamodule. | ||
|
||
Returns: | ||
The constructed data module. | ||
""" | ||
return cls( | ||
None, | ||
None, | ||
None, | ||
IceVisionInput(RunningStage.PREDICTING, predict_folder), | ||
input_transform=cls.input_transform_cls( | ||
None, | ||
None, | ||
None, | ||
predict_transform, | ||
tchaton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
image_size=image_size, | ||
), | ||
**data_module_kwargs, | ||
) | ||
|
||
@classmethod | ||
def from_files( | ||
cls, | ||
predict_files: Optional[List[str]] = None, | ||
predict_transform: Optional[Dict[str, Callable]] = None, | ||
image_size: Tuple[int, int] = (128, 128), | ||
**data_module_kwargs: Any, | ||
) -> "DataModule": | ||
"""Creates a :class:`~flash.core.data.data_module.DataModule` object from the given folders using the | ||
:class:`~flash.core.data.io.input.Input` of name | ||
:attr:`~flash.core.data.io.input.InputFormat.FOLDERS` | ||
from the passed or constructed :class:`~flash.core.data.io.input_transform.InputTransform`. | ||
tchaton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Args: | ||
predict_files: The list of files containing the predict data. | ||
predict_transform: The dictionary of transforms to use during predicting which maps | ||
data_module_kwargs: The keywords arguments for creating the datamodule. | ||
|
||
Returns: | ||
The constructed data module. | ||
""" | ||
return cls( | ||
None, | ||
None, | ||
None, | ||
IceVisionInput(RunningStage.PREDICTING, predict_files), | ||
input_transform=cls.input_transform_cls( | ||
None, | ||
None, | ||
None, | ||
tchaton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
predict_transform, | ||
image_size=image_size, | ||
), | ||
**data_module_kwargs, | ||
) | ||
|
||
from_tensor = None | ||
from_json = None | ||
from_csv = None | ||
from_datasets = None |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ethanwharris Do we want to do this for now? Just an idea, but might not be worth it.