KUOCHENG commited on
Commit
4c06e08
·
verified ·
1 Parent(s): 17253f8

Create star.py

Browse files
Files changed (1) hide show
  1. star.py +36 -0
star.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ import numpy as np
3
+ import os
4
+
5
+ class STARDataset(datasets.GeneratorBasedBuilder):
6
+ """STAR Dataset with NPY file loading"""
7
+
8
+ VERSION = datasets.Version("1.0.0")
9
+
10
+ def _info(self):
11
+ return datasets.DatasetInfo(
12
+ features=datasets.Features({
13
+ "id": datasets.Value("int32"),
14
+ "hr_path": datasets.Value("string"),
15
+ "lr_path": datasets.Value("string"),
16
+ "split": datasets.Value("string"),
17
+ })
18
+ )
19
+
20
+ def _split_generators(self, dl_manager):
21
+ return [
22
+ datasets.SplitGenerator(
23
+ name=datasets.Split.TRAIN,
24
+ gen_kwargs={"filepath": "sampled_data/x2/train_metadata.jsonl"},
25
+ ),
26
+ datasets.SplitGenerator(
27
+ name=datasets.Split.VALIDATION,
28
+ gen_kwargs={"filepath": "sampled_data/x2/validation_metadata.jsonl"},
29
+ ),
30
+ ]
31
+
32
+ def _generate_examples(self, filepath):
33
+ import json
34
+ with open(filepath, 'r') as f:
35
+ for idx, line in enumerate(f):
36
+ yield idx, json.loads(line)