bastienp commited on
Commit
19794d7
·
1 Parent(s): 8b1cbd1

feat: read json format intead of txt

Browse files
Files changed (2) hide show
  1. data/train.zip +2 -2
  2. visible-watermark-pita.py +54 -26
data/train.zip CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:92d954ab8239a064b7874ab3466c861fc2c7240129bd7235609c1bcc31c473ed
3
- size 1585836
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:61378ec4eed5bf3c71a91dcfb464a34ab6b74028f80e1e5a6e042f6e91dd0295
3
+ size 1586223
visible-watermark-pita.py CHANGED
@@ -1,8 +1,9 @@
1
  import os
2
  from glob import glob
3
- from PIL import Image
4
 
5
  import datasets
 
 
6
 
7
  _DESCRIPTION = """\
8
  Watermark Dataset
@@ -15,23 +16,57 @@ _URLS = {"train": f"{_REPO}/train.zip", "valid": f"{_REPO}/valid.zip"}
15
 
16
  _CATEGORIES = ["watermark"]
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  class WatermarkPita(datasets.GeneratorBasedBuilder):
19
  """Watermark Dataset"""
20
 
21
- VERSION = datasets.Version("1.0.0")
 
 
 
 
 
 
 
 
 
22
 
23
  def _info(self):
24
  return datasets.DatasetInfo(
25
  features=datasets.Features(
26
  {
27
  "image": datasets.Image(),
28
- "objects": datasets.Sequence({
29
- "label": datasets.ClassLabel(names=_CATEGORIES),
30
- "bbox": datasets.Sequence(datasets.Value("int32"), length=4)
31
- }),
 
 
 
 
32
  }
33
  ),
34
- supervised_keys=None,
35
  description=_DESCRIPTION,
36
  )
37
 
@@ -49,7 +84,6 @@ class WatermarkPita(datasets.GeneratorBasedBuilder):
49
  ),
50
  ]
51
 
52
-
53
  def _generate_examples(self, split, data_dir):
54
  image_dir = os.path.join(data_dir, "images")
55
  label_dir = os.path.join(data_dir, "labels")
@@ -58,26 +92,20 @@ class WatermarkPita(datasets.GeneratorBasedBuilder):
58
  label_paths = sorted(glob(label_dir + "/*.txt"))
59
 
60
  for idx, (image_path, label_path) in enumerate(zip(image_paths, label_paths)):
61
- im = Image.open(image_path)
62
- width, height = im.size
63
-
64
  with open(label_path, "r") as f:
65
- lines = f.readlines()
66
 
67
  objects = []
68
- for line in lines:
69
- line = line.strip().split()
70
-
71
- bbox_class = int(line[0])
72
- bbox_top_left = int(float(line[1]) * width)
73
- bbox_top_right = int(float(line[2]) * height)
74
- bbox_bottom_left = int(float(line[3]) * width)
75
- bbox_bottom_right = int(float(line[4]) * height)
76
-
77
-
78
- objects.append({
79
- "label": bbox_class,
80
- "bbox": [bbox_top_left, bbox_top_right, bbox_bottom_left, bbox_bottom_right]
81
- })
82
 
83
  yield idx, {"image": image_path, "objects": objects}
 
1
  import os
2
  from glob import glob
 
3
 
4
  import datasets
5
+ import json
6
+ from PIL import Image
7
 
8
  _DESCRIPTION = """\
9
  Watermark Dataset
 
16
 
17
  _CATEGORIES = ["watermark"]
18
 
19
+
20
+ class WatermarkPitaConfig(datasets.BuilderConfig):
21
+ """Builder Config for Food-101"""
22
+
23
+ def __init__(self, repository, urls, categories, **kwargs):
24
+ """BuilderConfig for Food-101.
25
+
26
+ Args:
27
+ repository: `string`, the name of the repository.
28
+ urls: `dict<string, string>`, the urls to the data.
29
+ categories: `list<string>`, the categories of the data.
30
+
31
+ **kwargs: keyword arguments forwarded to super.
32
+ """
33
+ VERSION = datasets.Version("1.0.0")
34
+
35
+ super(WatermarkPitaConfig, self).__init__(version=VERSION, **kwargs)
36
+ self.repository = repository
37
+ self.urls = categories
38
+ self.categories = categories
39
+
40
+
41
  class WatermarkPita(datasets.GeneratorBasedBuilder):
42
  """Watermark Dataset"""
43
 
44
+ BUILDER_CONFIGS = [
45
+ WatermarkPitaConfig(
46
+ name="text",
47
+ repository=_REPO,
48
+ urls=_URLS,
49
+ categories=_CATEGORIES,
50
+ )
51
+ ]
52
+
53
+ _DEFAULT_CONFIG_NAME = "text"
54
 
55
  def _info(self):
56
  return datasets.DatasetInfo(
57
  features=datasets.Features(
58
  {
59
  "image": datasets.Image(),
60
+ "objects": datasets.Sequence(
61
+ {
62
+ "label": datasets.ClassLabel(names=_CATEGORIES),
63
+ "bbox": datasets.Sequence(
64
+ datasets.Value("int32"), length=4
65
+ ),
66
+ }
67
+ ),
68
  }
69
  ),
 
70
  description=_DESCRIPTION,
71
  )
72
 
 
84
  ),
85
  ]
86
 
 
87
  def _generate_examples(self, split, data_dir):
88
  image_dir = os.path.join(data_dir, "images")
89
  label_dir = os.path.join(data_dir, "labels")
 
92
  label_paths = sorted(glob(label_dir + "/*.txt"))
93
 
94
  for idx, (image_path, label_path) in enumerate(zip(image_paths, label_paths)):
 
 
 
95
  with open(label_path, "r") as f:
96
+ bbox = json.load(f)
97
 
98
  objects = []
99
+ objects.append(
100
+ {
101
+ "label": bbox["label"],
102
+ "bbox": [
103
+ bbox["x"],
104
+ bbox["y"],
105
+ bbox["width"],
106
+ bbox["height"],
107
+ ],
108
+ }
109
+ )
 
 
 
110
 
111
  yield idx, {"image": image_path, "objects": objects}