|
|
|
|
|
|
|
|
from typing import List, Union |
|
|
import numpy as np |
|
|
|
|
|
import datasets |
|
|
from .CustomAnchorShapeGenerator import CustomAnchorShape, filled_anchors |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_CITATION = """\ |
|
|
@InProceedings{huggingface:dataset, |
|
|
title = {A great new dataset}, |
|
|
author={huggingface, Inc. |
|
|
}, |
|
|
year={2020} |
|
|
} |
|
|
""" |
|
|
|
|
|
|
|
|
_DESCRIPTION = """\ |
|
|
This is Custom Anchor shape dataset. |
|
|
""" |
|
|
|
|
|
|
|
|
_HOMEPAGE = "" |
|
|
|
|
|
|
|
|
_LICENSE = "" |
|
|
|
|
|
|
|
|
class CustomAnchorShapeConfig(datasets.BuilderConfig): |
|
|
"""Builder Config for CustomShape.""" |
|
|
|
|
|
def __init__(self, size, custom_data, **kwargs): |
|
|
"""BuilderConfig for CustomShape. |
|
|
|
|
|
Args: |
|
|
**kwargs: keyword arguments forwarded to super. |
|
|
""" |
|
|
super(CustomAnchorShapeConfig, self).__init__(version=datasets.Version("1.0.0"),**kwargs) |
|
|
self.size = size |
|
|
self.custom_data = custom_data |
|
|
|
|
|
|
|
|
class CustomAnchorShapeDataset(datasets.GeneratorBasedBuilder): |
|
|
"""CustomShape dataset.""" |
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
|
CustomAnchorShapeConfig( |
|
|
name='64size', |
|
|
description='64x64 size custom shape dataset.', |
|
|
size=64, |
|
|
custom_data={ |
|
|
"train": ['s_curve', |
|
|
'swiss_roll', |
|
|
[0.5, 0.5], |
|
|
[[0.25, 0.25], [0.75, 0.75]],], |
|
|
"validation": ['s_curve', |
|
|
'swiss_roll', |
|
|
[0.5, 0.5], |
|
|
[0.25, 0.25], |
|
|
[0.25, 0.75], |
|
|
[0.75, 0.75], |
|
|
[0.75, 0.25], |
|
|
[[0.25, 0.25], [0.75, 0.75]], |
|
|
[[0.25, 0.75], [0.75, 0.25]],], |
|
|
} |
|
|
), |
|
|
CustomAnchorShapeConfig( |
|
|
name='224size', |
|
|
description='224x224 size custom shape dataset.', |
|
|
size=224, |
|
|
custom_data={ |
|
|
"train": ['s_curve', |
|
|
'swiss_roll', |
|
|
[0.5, 0.5], |
|
|
[[0.25, 0.25], [0.75, 0.75]],], |
|
|
"validation": ['s_curve', |
|
|
'swiss_roll', |
|
|
[0.5, 0.5], |
|
|
[0.25, 0.25], |
|
|
[0.25, 0.75], |
|
|
[0.75, 0.75], |
|
|
[0.75, 0.25], |
|
|
[[0.25, 0.25], [0.75, 0.75]], |
|
|
[[0.25, 0.75], [0.75, 0.25]],], |
|
|
} |
|
|
), |
|
|
] |
|
|
|
|
|
def _info(self): |
|
|
features = datasets.Features( |
|
|
{ |
|
|
'image_id': datasets.Value('int64'), |
|
|
'image': datasets.Image(), |
|
|
'width': datasets.Value('int64'), |
|
|
'height': datasets.Value('int64'), |
|
|
'object': datasets.features.Sequence({ |
|
|
'bbox': datasets.features.Sequence(datasets.Value('float64')), |
|
|
}) |
|
|
} |
|
|
) |
|
|
return datasets.DatasetInfo( |
|
|
description=_DESCRIPTION, |
|
|
features=features, |
|
|
) |
|
|
|
|
|
def _split_generators(self, dl_manager): |
|
|
return [ |
|
|
datasets.SplitGenerator( |
|
|
name=datasets.Split.TRAIN, |
|
|
gen_kwargs={ |
|
|
"size": self.config.size, |
|
|
"custom_data": self.config.custom_data['train'], |
|
|
}, |
|
|
), |
|
|
] |
|
|
|
|
|
def _generate_examples( |
|
|
self, |
|
|
size: Union[int, tuple], |
|
|
custom_data: List[Union[np.ndarray, str]], |
|
|
): |
|
|
if isinstance(size, int): |
|
|
width, height = size, size |
|
|
else: |
|
|
width, height = size |
|
|
|
|
|
custom_shape = CustomAnchorShape( |
|
|
width, |
|
|
height, |
|
|
custom_data=custom_data, |
|
|
) |
|
|
|
|
|
for idx, data in enumerate(custom_shape.custom_data): |
|
|
yield idx, { |
|
|
'image_id': idx, |
|
|
'image': custom_shape.get_distribution(data, type='img'), |
|
|
'width': width, |
|
|
'height': height, |
|
|
'object': { |
|
|
'bbox': custom_shape.get_distribution(data, type='1d'), |
|
|
} |
|
|
} |