Datasets:

toniwuest commited on
Commit
f17dacf
·
verified ·
1 Parent(s): b3f5cd9

Update CLEVR-Sudoku.py

Browse files
Files changed (1) hide show
  1. CLEVR-Sudoku.py +14 -10
CLEVR-Sudoku.py CHANGED
@@ -64,15 +64,13 @@ class CLEVRSudoku(datasets.GeneratorBasedBuilder):
64
  description=_DESCRIPTION,
65
  features=datasets.Features(
66
  {
67
- # TODO: Add features
68
- # "sudoku": datasets.Array2D(shape=(9, 9), dtype=datasets.Image()),
69
  "sudoku": datasets.Sequence(datasets.Sequence(datasets.Image())),
70
- # "options": datasets.Array2D(shape=(9, 10), dtype=datasets.Image()),
71
  # # attributes as dict of features
72
- # "attributes": {
73
- # "key": datasets.Value("int32"),
74
- # "value": datasets.Sequence(datasets.Value("string"))
75
- # },
76
  "id": datasets.Value("int32"),
77
  "solution": datasets.Sequence(datasets.Sequence(datasets.Value("int32"))),
78
  }
@@ -179,12 +177,18 @@ class CLEVRSudoku(datasets.GeneratorBasedBuilder):
179
  sudoku_images = json_content.get("images")
180
  sudoku_images = [os.path.join(image_path, x) if x is not None else None for row in sudoku_images for x in row]
181
  sudoku_images = [sudoku_images[i:i+9] for i in range(0, len(sudoku_images), 9)]
182
-
 
 
 
 
 
 
183
  # Extract the specific fields from the JSON
184
  extracted_data = {
185
  "sudoku": sudoku_images,
186
- # "options": json_content.get("options"),
187
- # "attributes": json_content.get("map_number_to_attributes"),
188
  "file_name": file_name, # The name of the file inside the archive
189
  "id": i, # Extract the 'id' field
190
  "name": json_content.get("name"), # Extract the 'name' field
 
64
  description=_DESCRIPTION,
65
  features=datasets.Features(
66
  {
 
 
67
  "sudoku": datasets.Sequence(datasets.Sequence(datasets.Image())),
68
+ "options": datasets.Sequence(datasets.Sequence(datasets.Image())),
69
  # # attributes as dict of features
70
+ "attributes": {
71
+ "key": datasets.Value("int32"),
72
+ "value": datasets.Sequence(datasets.Value("string"))
73
+ },
74
  "id": datasets.Value("int32"),
75
  "solution": datasets.Sequence(datasets.Sequence(datasets.Value("int32"))),
76
  }
 
177
  sudoku_images = json_content.get("images")
178
  sudoku_images = [os.path.join(image_path, x) if x is not None else None for row in sudoku_images for x in row]
179
  sudoku_images = [sudoku_images[i:i+9] for i in range(0, len(sudoku_images), 9)]
180
+
181
+ # option image paths
182
+ option_images = json_content.get("options")
183
+ max_options = len(option_images[0])
184
+ option_images = [os.path.join(image_path, x) if x is not None else None for row in option_images for x in row]
185
+ option_images = [option_images[i:i+max_options] for i in range(0, len(option_images), max_options)]
186
+
187
  # Extract the specific fields from the JSON
188
  extracted_data = {
189
  "sudoku": sudoku_images,
190
+ "options": option_images,
191
+ "attributes": json_content.get("map_number_to_attributes"),
192
  "file_name": file_name, # The name of the file inside the archive
193
  "id": i, # Extract the 'id' field
194
  "name": json_content.get("name"), # Extract the 'name' field