MrPotato commited on
Commit
cc323ce
·
1 Parent(s): 6818114

changed chunk generation

Browse files
Files changed (1) hide show
  1. ref_seg_ger.py +12 -7
ref_seg_ger.py CHANGED
@@ -115,7 +115,7 @@ def load_image(image_path, size=None):
115
  class RefSeg(datasets.GeneratorBasedBuilder):
116
  """TODO: Short description of my dataset."""
117
 
118
- CHUNK_SIZE = 512
119
  VERSION = datasets.Version("1.0.0")
120
 
121
  # This is an example of a dataset with multiple configurations.
@@ -255,12 +255,17 @@ class RefSeg(datasets.GeneratorBasedBuilder):
255
  if input != '':
256
  clean_input_ids.append(input)
257
  clean_labels.append(labels[i])
258
- for chunk_id, index in enumerate(range(0, len(clean_input_ids), self.CHUNK_SIZE)):
259
- split_ids = clean_input_ids[index:max(len(clean_input_ids), index + self.CHUNK_SIZE)]
 
 
 
 
 
260
  #split_bboxes = bboxes[index:index + self.CHUNK_SIZE]
261
  # split_rgbs = rgbs[index:index + self.CHUNK_SIZE]
262
  # split_fonts = fonts[index:index + self.CHUNK_SIZE]
263
- split_labels = clean_labels[index:max(len(clean_input_ids), index + self.CHUNK_SIZE)]
264
  #split_labels_post = [item for sublist in split_labels for item in sublist]
265
  # if(len(split_ids) != len(split_labels)):
266
  # print(f)
@@ -278,13 +283,13 @@ class RefSeg(datasets.GeneratorBasedBuilder):
278
 
279
  yield key, {
280
  #"id": f"{os.path.basename(f)}_{chunk_id}",
281
- 'input_ids': split_ids,
282
- 'attention_mask': [1] * len(split_ids),
283
  #"bbox": split_bboxes,
284
  # "RGBs": split_rgbs,
285
  # "fonts": split_fonts,
286
  #"image": image,
287
  #"original_image": original_image,
288
- "labels": split_labels
289
  }
290
  key += 1
 
115
  class RefSeg(datasets.GeneratorBasedBuilder):
116
  """TODO: Short description of my dataset."""
117
 
118
+ CHUNK_SIZE = 256
119
  VERSION = datasets.Version("1.0.0")
120
 
121
  # This is an example of a dataset with multiple configurations.
 
255
  if input != '':
256
  clean_input_ids.append(input)
257
  clean_labels.append(labels[i])
258
+ n_chunks = int(len(clean_input_ids)/self.CHUNK_SIZE) if len(clean_input_ids)%self.CHUNK_SIZE == 0 \
259
+ else int(len(clean_input_ids)/self.CHUNK_SIZE) + 1
260
+ split_ids = np.array_split(clean_input_ids, n_chunks)
261
+ split_labels = np.array_split(clean_labels, n_chunks)
262
+ for chunk_ids, chunk_labels in zip(split_ids, split_labels):
263
+ #for chunk_id, index in enumerate(range(0, len(clean_input_ids), self.CHUNK_SIZE)):
264
+ #split_ids = clean_input_ids[index:max(len(clean_input_ids), index + self.CHUNK_SIZE)]
265
  #split_bboxes = bboxes[index:index + self.CHUNK_SIZE]
266
  # split_rgbs = rgbs[index:index + self.CHUNK_SIZE]
267
  # split_fonts = fonts[index:index + self.CHUNK_SIZE]
268
+ #split_labels = clean_labels[index:max(len(clean_input_ids), index + self.CHUNK_SIZE)]
269
  #split_labels_post = [item for sublist in split_labels for item in sublist]
270
  # if(len(split_ids) != len(split_labels)):
271
  # print(f)
 
283
 
284
  yield key, {
285
  #"id": f"{os.path.basename(f)}_{chunk_id}",
286
+ 'input_ids': chunk_ids,
287
+ 'attention_mask': [1] * len(chunk_ids),
288
  #"bbox": split_bboxes,
289
  # "RGBs": split_rgbs,
290
  # "fonts": split_fonts,
291
  #"image": image,
292
  #"original_image": original_image,
293
+ "labels": chunk_labels
294
  }
295
  key += 1