Datasets:

Modalities:
Image
Languages:
English
Libraries:
Datasets
License:
shohei-ta commited on
Commit
9e430eb
1 Parent(s): 40ae688

Upload 9 files

Browse files
Files changed (10) hide show
  1. .gitattributes +1 -0
  2. README.md +40 -0
  3. dev.json +0 -0
  4. dev.zip +3 -0
  5. load_dataset.py +241 -0
  6. poster_pdf.zip +3 -0
  7. test.json +0 -0
  8. test.zip +3 -0
  9. train.json +3 -0
  10. train.zip +3 -0
.gitattributes CHANGED
@@ -53,3 +53,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
 
 
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
56
+ train.json filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,3 +1,43 @@
1
  ---
2
  license: cc
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: cc
3
+ language:
4
+ - en
5
+ size_categories:
6
+ - 1K<n<10K
7
  ---
8
+
9
+ This is the dataset repository of a paper ''SciPostLayout: A Dataset for Layout Analysis and Layout Generation of Scientific Posters''.
10
+ This dataset includes 7,755 poster images in train set, 50 poster images in dev/test sets, respectively.
11
+ The file structure is as follows.
12
+
13
+ - train.zip
14
+ - 7,755 poster images of train set.
15
+ - dev.zip
16
+ - 50 poster images of dev set.
17
+ - test.zip
18
+ - 50 poster images of test set.
19
+ - train.json
20
+ - annotation data of train set.
21
+ - dev.json
22
+ - annotation data of valid set.
23
+ - test.json
24
+ - annotation data of test set.
25
+ - load_dataset.py
26
+ - example script to load the dataset.
27
+ - poster_pdf.zip
28
+ - poster pdf files (optional)
29
+
30
+ After downloading the data set, place each file as follows to run load_dataset.py
31
+
32
+ - load_dataset.py
33
+ - scipostlayout
34
+ - raw
35
+ - train
36
+ - train png files
37
+ - dev
38
+ - dev png files
39
+ - test
40
+ - test png files
41
+ - train.json
42
+ - dev.json
43
+ - test.json
dev.json ADDED
The diff for this file is too large to render. See raw diff
 
dev.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:600922983bee703da3dedda0c782fe4edd66afb19795718956799604e6b4c070
3
+ size 135972578
load_dataset.py ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import errno
3
+ import os.path as osp
4
+ from typing import List, Set, Union
5
+
6
+ import json
7
+ from pathlib import Path
8
+ from typing import List, Set, Union, Dict
9
+
10
+ import torch
11
+ from torch.utils.data import Dataset
12
+ import seaborn as sns
13
+ from pycocotools.coco import COCO
14
+ """
15
+ load raw data
16
+ """
17
+
18
+
19
+ def makedirs(path):
20
+ try:
21
+ os.makedirs(osp.expanduser(osp.normpath(path)))
22
+ except OSError as e:
23
+ if e.errno != errno.EEXIST and osp.isdir(path):
24
+ raise e
25
+
26
+
27
+ def files_exist(files):
28
+ return all([osp.exists(f) for f in files])
29
+
30
+
31
+
32
+ def load_scipostlayout_data(raw_dir: str, max_num_elements: int,
33
+ label_set: Union[List, Set], label2index: Dict):
34
+
35
+ def is_valid(element):
36
+ label = coco.cats[element['category_id']]['name']
37
+ if label not in set(label_set):
38
+ return False
39
+ x1, y1, width, height = element['bbox']
40
+ x2, y2 = x1 + width, y1 + height
41
+
42
+ if x1 < 0 or y1 < 0 or W < x2 or H < y2:
43
+ return False
44
+ if x2 <= x1 or y2 <= y1:
45
+ return False
46
+
47
+ return True
48
+
49
+ train_list, dev_list = None, None
50
+ # raw_dir = osp.join(Path(raw_dir), 'scipostlayout')
51
+ for split in ['train', 'dev', 'test']:
52
+ dataset = []
53
+ coco = COCO(osp.join(raw_dir, f'{split}.json'))
54
+ for img_id in sorted(coco.getImgIds()):
55
+ ann_img = coco.loadImgs(img_id)
56
+ W = float(ann_img[0]['width'])
57
+ H = float(ann_img[0]['height'])
58
+ name = ann_img[0]['file_name']
59
+ # if H < W:
60
+ # continue
61
+
62
+ elements = coco.loadAnns(coco.getAnnIds(imgIds=[img_id]))
63
+ _elements = list(filter(is_valid, elements))
64
+ filtered = len(elements) != len(_elements)
65
+ elements = _elements
66
+
67
+ N = len(elements)
68
+ if N == 0 or max_num_elements < N:
69
+ continue
70
+
71
+ bboxes = []
72
+ labels = []
73
+
74
+ for element in elements:
75
+ # bbox
76
+ x1, y1, width, height = element['bbox']
77
+ b = [x1 / W, y1 / H, width / W, height / H] # bbox format: ltwh
78
+ bboxes.append(b)
79
+
80
+ # label
81
+ label = coco.cats[element['category_id']]['name']
82
+ labels.append(label2index[label])
83
+
84
+ bboxes = torch.tensor(bboxes, dtype=torch.float)
85
+ labels = torch.tensor(labels, dtype=torch.long)
86
+
87
+ data = {
88
+ 'name': name,
89
+ 'bboxes': bboxes,
90
+ 'labels': labels,
91
+ 'canvas_size': [W, H],
92
+ 'filtered': filtered,
93
+ }
94
+ dataset.append(data)
95
+
96
+ if split == 'train':
97
+ train_list = dataset
98
+ elif split == 'dev':
99
+ dev_list = dataset
100
+ else:
101
+ test_list = dataset
102
+
103
+ # shuffle train with seed
104
+ generator = torch.Generator().manual_seed(0)
105
+ indices = torch.randperm(len(train_list), generator=generator)
106
+ train_list = [train_list[i] for i in indices]
107
+
108
+ train_set = train_list
109
+ dev_set = dev_list
110
+ test_set = test_list
111
+ split_dataset = [train_set, dev_set, test_set]
112
+ return split_dataset
113
+
114
+
115
+ class LayoutDataset(Dataset):
116
+
117
+ _label2index = None
118
+ _index2label = None
119
+ _colors = None
120
+
121
+ split_file_names = ['train.pt', 'dev.pt', 'test.pt']
122
+
123
+ def __init__(self,
124
+ root: str,
125
+ data_name: str,
126
+ split: str,
127
+ max_num_elements: int,
128
+ label_set: Union[List, Set],
129
+ online_process: bool = True):
130
+
131
+ self.root = f'{root}/{data_name}/'
132
+ self.raw_dir = osp.join(self.root, 'raw')
133
+ self.max_num_elements = max_num_elements
134
+ self.label_set = label_set
135
+ self.pre_processed_dir = osp.join(
136
+ self.root, 'pre_processed_{}_{}'.format(self.max_num_elements, len(self.label_set)))
137
+ assert split in ['train', 'dev', 'test']
138
+
139
+ if files_exist(self.pre_processed_paths):
140
+ idx = self.split_file_names.index('{}.pt'.format(split))
141
+ print(f'Loading {split}...')
142
+ self.data = torch.load(self.pre_processed_paths[idx])
143
+ else:
144
+ print(f'Pre-processing and loading {split}...')
145
+ makedirs(self.pre_processed_dir)
146
+ split_dataset = self.load_raw_data()
147
+ self.save_split_dataset(split_dataset)
148
+ idx = self.split_file_names.index('{}.pt'.format(split))
149
+ self.data = torch.load(self.pre_processed_paths[idx])
150
+
151
+ self.online_process = online_process
152
+ if not self.online_process:
153
+ self.data = [self.process(item) for item in self.data]
154
+
155
+ @property
156
+ def pre_processed_paths(self):
157
+ return [
158
+ osp.join(self.pre_processed_dir, f) for f in self.split_file_names
159
+ ]
160
+
161
+ @classmethod
162
+ def label2index(self, label_set):
163
+ if self._label2index is None:
164
+ self._label2index = dict()
165
+ for idx, label in enumerate(label_set):
166
+ self._label2index[label] = idx # HACK idx + 1
167
+ return self._label2index
168
+
169
+ @classmethod
170
+ def index2label(self, label_set):
171
+ if self._index2label is None:
172
+ self._index2label = dict()
173
+ for idx, label in enumerate(label_set):
174
+ self._index2label[idx] = label # HACK idx + 1
175
+ return self._index2label
176
+
177
+ @property
178
+ def colors(self):
179
+ if self._colors is None:
180
+ n_colors = len(self.label_set) + 1
181
+ colors = sns.color_palette('husl', n_colors=n_colors)
182
+ self._colors = [
183
+ tuple(map(lambda x: int(x * 255), c)) for c in colors
184
+ ]
185
+ return self._colors
186
+
187
+ def save_split_dataset(self, split_dataset):
188
+ torch.save(split_dataset[0], self.pre_processed_paths[0])
189
+ torch.save(split_dataset[1], self.pre_processed_paths[1])
190
+ torch.save(split_dataset[2], self.pre_processed_paths[2])
191
+
192
+ def load_raw_data(self) -> list:
193
+ raise NotImplementedError
194
+
195
+ def process(self, data) -> dict:
196
+ raise NotImplementedError
197
+
198
+ def __len__(self):
199
+ return len(self.data)
200
+
201
+ def __getitem__(self, idx):
202
+ if self.online_process:
203
+ sample = self.process(self.data[idx])
204
+ else:
205
+ sample = self.data[idx]
206
+ return sample
207
+
208
+
209
+ class SciPostLayoutDataset(LayoutDataset):
210
+ labels = [
211
+ 'Title',
212
+ 'Author Info',
213
+ 'Section',
214
+ 'List',
215
+ 'Text',
216
+ 'Caption',
217
+ 'Figure',
218
+ 'Table',
219
+ 'Unknown'
220
+ ]
221
+
222
+ def __init__(self,
223
+ root: str,
224
+ split: str,
225
+ max_num_elements: int,
226
+ online_process: bool = True):
227
+ data_name = 'scipostlayout'
228
+ super().__init__(root,
229
+ data_name,
230
+ split,
231
+ max_num_elements,
232
+ label_set=self.labels,
233
+ online_process=online_process)
234
+
235
+ def load_raw_data(self) -> list:
236
+ return load_scipostlayout_data(self.raw_dir, self.max_num_elements,
237
+ self.label_set, self.label2index(self.label_set))
238
+
239
+
240
+ if __name__ == "__main__":
241
+ dataset = SciPostLayoutDataset(root="./", split="dev", max_num_elements=50)
poster_pdf.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:63f86a43b8c75d451102709e12c8c417ef91c3e4c3092d6f76c9ef8b31453128
3
+ size 8774293867
test.json ADDED
The diff for this file is too large to render. See raw diff
 
test.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d18be440d37dd86ef4e46690757a9f672593ee3fcdb99b93f293cb3a19ae4c55
3
+ size 143442481
train.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:357cc415d0d89ec1427ce3cdf5342b38df082e0761621d2ffa0f254f100253f8
3
+ size 142449053
train.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c588fa06fdd47e97b7d02039c9fd1b94d079d2875c6ba1586b6afc083c219039
3
+ size 22211140890