axiong commited on
Commit
449b79c
1 Parent(s): 9712d05

Update pmc_oa.py

Browse files
Files changed (1) hide show
  1. pmc_oa.py +39 -3
pmc_oa.py CHANGED
@@ -30,6 +30,8 @@ _URLs = {
30
  "images": "https://huggingface.co/datasets/axiong/pmc_oa/resolve/main/images.zip",
31
  # "pmc_oa_beta": "https://huggingface.co/datasets/axiong/pmc_oa/resolve/main/test.jsonl",
32
  # "pmc_oa": "https://huggingface.co/datasets/axiong/pmc_oa/resolve/main/valid.jsonl",
 
 
33
  "pmc_oa_beta": "https://huggingface.co/datasets/axiong/pmc_oa/resolve/main/pmc_oa_beta.jsonl",
34
  "pmc_oa": "https://huggingface.co/datasets/axiong/pmc_oa/resolve/main/pmc_oa.jsonl",
35
  }
@@ -51,6 +53,10 @@ class PMC_OA(datasets.GeneratorBasedBuilder):
51
 
52
  VERSION = datasets.Version("1.0.0")
53
  BUILDER_CONFIGS = [
 
 
 
 
54
  PMC_OA_Config(
55
  name="pmc_oa_beta",
56
  description="<subfigure, caption> pairs. Subfigures detected by a DETR model.",
@@ -62,7 +68,20 @@ class PMC_OA(datasets.GeneratorBasedBuilder):
62
  ]
63
 
64
  def _info(self):
65
- if self.config.name == "pmc_oa_beta":
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  return datasets.DatasetInfo(
67
  description=_DESCRIPTION,
68
  features=datasets.Features(
@@ -94,7 +113,13 @@ class PMC_OA(datasets.GeneratorBasedBuilder):
94
  def _split_generators(self, dl_manager):
95
  """Returns SplitGenerators."""
96
  downloaded_files = dl_manager.download_and_extract(_URLs)
97
- if self.config.name == "pmc_oa_beta":
 
 
 
 
 
 
98
  return [
99
  datasets.SplitGenerator(
100
  name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["pmc_oa_beta"], "image_dir": downloaded_files['images']}
@@ -113,7 +138,18 @@ class PMC_OA(datasets.GeneratorBasedBuilder):
113
 
114
  with jsonlines.open(filepath) as reader:
115
  for _id, obj in enumerate(reader):
116
- if self.config.name == "pmc_oa_beta":
 
 
 
 
 
 
 
 
 
 
 
117
  relative_image_path = obj['image']
118
  image_path = os.path.join(image_dir, "caption_T060_filtered_top4_sep_v0_subfigures", relative_image_path)
119
  caption = obj['caption']
 
30
  "images": "https://huggingface.co/datasets/axiong/pmc_oa/resolve/main/images.zip",
31
  # "pmc_oa_beta": "https://huggingface.co/datasets/axiong/pmc_oa/resolve/main/test.jsonl",
32
  # "pmc_oa": "https://huggingface.co/datasets/axiong/pmc_oa/resolve/main/valid.jsonl",
33
+ "demo_images": "https://huggingface.co/datasets/axiong/test/resolve/main/images.zip",
34
+ "demo_captions": "https://huggingface.co/datasets/axiong/test/resolve/main/mini_dataset.jsonl",
35
  "pmc_oa_beta": "https://huggingface.co/datasets/axiong/pmc_oa/resolve/main/pmc_oa_beta.jsonl",
36
  "pmc_oa": "https://huggingface.co/datasets/axiong/pmc_oa/resolve/main/pmc_oa.jsonl",
37
  }
 
53
 
54
  VERSION = datasets.Version("1.0.0")
55
  BUILDER_CONFIGS = [
56
+ PMC_OA_Config(
57
+ name="demo",
58
+ description="Demo subset to show dataset samples.",
59
+ ),
60
  PMC_OA_Config(
61
  name="pmc_oa_beta",
62
  description="<subfigure, caption> pairs. Subfigures detected by a DETR model.",
 
68
  ]
69
 
70
  def _info(self):
71
+ if self.config.name == "demo":
72
+ return datasets.DatasetInfo(
73
+ description=_DESCRIPTION,
74
+ features=datasets.Features(
75
+ {
76
+ "image": datasets.Value("string"),
77
+ "caption": datasets.Value("string"),
78
+ }
79
+ ),
80
+ supervised_keys=None,
81
+ citation=_CITATION,
82
+ homepage=_HOMEPAGE,
83
+ )
84
+ elif self.config.name == "pmc_oa_beta":
85
  return datasets.DatasetInfo(
86
  description=_DESCRIPTION,
87
  features=datasets.Features(
 
113
  def _split_generators(self, dl_manager):
114
  """Returns SplitGenerators."""
115
  downloaded_files = dl_manager.download_and_extract(_URLs)
116
+ if self.config.name == "demo":
117
+ return [
118
+ datasets.SplitGenerator(
119
+ name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["demo_captions"], "image_dir": downloaded_files['demo_images']}
120
+ )
121
+ ]
122
+ elif self.config.name == "pmc_oa_beta":
123
  return [
124
  datasets.SplitGenerator(
125
  name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["pmc_oa_beta"], "image_dir": downloaded_files['images']}
 
138
 
139
  with jsonlines.open(filepath) as reader:
140
  for _id, obj in enumerate(reader):
141
+ if self.config.name == "demo":
142
+ relative_image_path = obj['image']
143
+ image_path = os.path.join(image_dir, "images", relative_image_path)
144
+ caption = obj['caption']
145
+ yield _id, {
146
+ "image": {
147
+ "path": image_path,
148
+ "bytes": open(image_path, "rb").read(),
149
+ },
150
+ "caption": caption,
151
+ }
152
+ elif self.config.name == "pmc_oa_beta":
153
  relative_image_path = obj['image']
154
  image_path = os.path.join(image_dir, "caption_T060_filtered_top4_sep_v0_subfigures", relative_image_path)
155
  caption = obj['caption']