Luka-Wang commited on
Commit
e0b8f82
·
1 Parent(s): 36c5f8f

Update coco.py

Browse files
Files changed (1) hide show
  1. coco.py +5 -15
coco.py CHANGED
@@ -73,29 +73,19 @@ class NewDataset(datasets.GeneratorBasedBuilder):
73
  # data = datasets.load_dataset('my_dataset', 'second_domain')
74
  BUILDER_CONFIGS = [
75
  datasets.BuilderConfig(name="train", version=VERSION, description="This part of my dataset covers a first domain"),
76
- datasets.BuilderConfig(name="second_domain", version=VERSION, description="This part of my dataset covers a second domain"),
77
  ]
78
 
79
  DEFAULT_CONFIG_NAME = "train" # It's not mandatory to have a default configuration. Just use one if it make sense.
80
 
81
  def _info(self):
82
  # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
83
- if self.config.name == "train": # This is the name of the configuration selected in BUILDER_CONFIGS above
84
- features = datasets.Features(
85
  {
86
  "filepath": datasets.Value("string"),
87
  "filename": datasets.Value("string"),
88
  "raw": datasets.Value("string")
89
  }
90
- )
91
- else: # This is an example to show how to have different features for "first_domain" and "second_domain"
92
- features = datasets.Features(
93
- {
94
- "filepath": datasets.Value("string"),
95
- "filename": datasets.Value("string"),
96
- "raw": datasets.Value("string")
97
- }
98
- )
99
  return datasets.DatasetInfo(
100
  # This is the description that will appear on the datasets page.
101
  description=_DESCRIPTION,
@@ -125,9 +115,9 @@ class NewDataset(datasets.GeneratorBasedBuilder):
125
  def _generate_examples(self, filepath):
126
  """This function returns the examples in the raw (text) form."""
127
  logger.info("generating examples from = %s", filepath)
128
- with open(filepath) as f:
129
- squad = json.loads(f)
130
- for image in squad["images"]:
131
  filepath = image["filepath"]
132
  filename = image["filename"]
133
  for sentence in image["sentences"]:
 
73
  # data = datasets.load_dataset('my_dataset', 'second_domain')
74
  BUILDER_CONFIGS = [
75
  datasets.BuilderConfig(name="train", version=VERSION, description="This part of my dataset covers a first domain"),
 
76
  ]
77
 
78
  DEFAULT_CONFIG_NAME = "train" # It's not mandatory to have a default configuration. Just use one if it make sense.
79
 
80
  def _info(self):
81
  # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
82
+ features=datasets.Features(
 
83
  {
84
  "filepath": datasets.Value("string"),
85
  "filename": datasets.Value("string"),
86
  "raw": datasets.Value("string")
87
  }
88
+ ),
 
 
 
 
 
 
 
 
89
  return datasets.DatasetInfo(
90
  # This is the description that will appear on the datasets page.
91
  description=_DESCRIPTION,
 
115
  def _generate_examples(self, filepath):
116
  """This function returns the examples in the raw (text) form."""
117
  logger.info("generating examples from = %s", filepath)
118
+ with open(filepath, encoding="utf-8") as f:
119
+ data = json.loads(f)
120
+ for image in data["images"]:
121
  filepath = image["filepath"]
122
  filename = image["filename"]
123
  for sentence in image["sentences"]: