File size: 4,568 Bytes
b82b0e2 83a96f9 b82b0e2 9c44a63 6a1852b 9c44a63 90ffea0 b82b0e2 a59f72b b82b0e2 b78c5b4 9c44a63 5d3adef 9c44a63 90ffea0 b82b0e2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# Hugging Face Loading script
from typing import List, Union
import numpy as np
import datasets
from .CustomAnchorShapeGenerator import CustomAnchorShape, filled_anchors
# TODO: Add BibTeX citation
# Find for instance the citation on arxiv or on the dataset repo/website
_CITATION = """\
@InProceedings{huggingface:dataset,
title = {A great new dataset},
author={huggingface, Inc.
},
year={2020}
}
"""
# You can copy an official description
_DESCRIPTION = """\
This is Custom Anchor shape dataset.
"""
# TODO: Add a link to an official homepage for the dataset here
_HOMEPAGE = ""
# TODO: Add the licence for the dataset here if you can find it
_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'),
}
} |