pain commited on
Commit
ced594a
·
1 Parent(s): 1fc16bc

Upload mscoco_jsonl_full.py

Browse files
Files changed (1) hide show
  1. mscoco_jsonl_full.py +61 -0
mscoco_jsonl_full.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ import pickle
3
+ import json
4
+
5
+ class EmbeddingsDatasetConfig(datasets.BuilderConfig):
6
+
7
+ def __init__(self, image_base_m, embeddingSize, **kwargs):
8
+ super(EmbeddingsDatasetConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
9
+ self.data_urls = ""
10
+ self.image_base_m = image_base_m
11
+ self.embeddingSize = embeddingSize
12
+
13
+
14
+ class ImageCaptionsEmbeddings(datasets.GeneratorBasedBuilder):
15
+ BUILDER_CONFIGS = [
16
+ EmbeddingsDatasetConfig(
17
+ name="Vit-B-32",
18
+ image_base_m="Vit-B-32-2",
19
+ embeddingSize=512,
20
+ ),
21
+ ]
22
+
23
+ DEFAULT_CONFIG_NAME = "Vit-B-32"
24
+
25
+ def _info(self):
26
+ return datasets.DatasetInfo(
27
+ description='test',
28
+ features=datasets.Features(
29
+ {
30
+ "id": datasets.Value('string'),
31
+ "embedding": datasets.Array2D((1, self.config.embeddingSize), 'float32')
32
+ }
33
+ ),
34
+ )
35
+
36
+ def _split_generators(self, dl_manager):
37
+
38
+ urls_to_download = self.config.data_urls
39
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
40
+
41
+ downloaded_files = ["/home/think3/Desktop/1. MSCOCO_captions_dataset_edited/dataset_test_jsonl/en_captions_json.jsonl"]
42
+ return [
43
+ datasets.SplitGenerator(name=datasets.Split.TRAIN,
44
+ gen_kwargs={
45
+ "data_files": downloaded_files,
46
+ })
47
+ ]
48
+
49
+ def _generate_examples(self, data_files):
50
+
51
+ for data_file in data_files:
52
+
53
+ with open(data_file, "r") as input_file:
54
+ for line in input_file:
55
+
56
+ json_data = json.loads(line)
57
+
58
+ yield json_data["id"], {
59
+ "id": json_data["id"],
60
+ "embedding": json_data["embedding"],
61
+ }