tsbpp commited on
Commit
7478fdb
1 Parent(s): 31bf73b

Upload 2 files

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. dataset.json +3 -0
  3. loadDataset.py +100 -0
.gitattributes CHANGED
@@ -53,3 +53,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
 
 
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
56
+ dataset.json filter=lfs diff=lfs merge=lfs -text
dataset.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c9d2bb4c67462e2649be5099a3b790c95ad073fe46243310b79a1d4c8bee75ed
3
+ size 112962519
loadDataset.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import sys
3
+ import os
4
+ import urllib.request as ureq
5
+ import pdb
6
+
7
+ download=1 # 0 if images are already downloaded
8
+
9
+ ###############################################################
10
+ ######################### load dataset json file ###############
11
+ ################################################################
12
+ with open('dataset.json', 'r') as fp:
13
+ data = json.load(fp)
14
+
15
+ ## dictionary data contains image URL, questions and answers ##
16
+
17
+
18
+
19
+
20
+ ################################################################
21
+ ############### Script for downloading images ##################
22
+ ################################################################
23
+ ## Make a directory images to store all images there ##########
24
+ if download == 1:
25
+ os.mkdir('./images')
26
+ for k in data.keys():
27
+ ext=os.path.splitext(data[k]['imageURL'])[1]
28
+ outputFile='images/%s%s'%(k,ext)
29
+ pdb.set_trace()
30
+ ureq.urlretrieve(data[k]['imageURL'],outputFile)
31
+
32
+
33
+
34
+ #################################################################
35
+ ################### Example of data access #####################
36
+ ################################################################
37
+ for k in data.keys():
38
+ ext=os.path.splitext(data[k]['imageURL'])[1]
39
+ imageFile='images/%s%s'%(k,ext)
40
+
41
+ print('************************')
42
+ print('Image file: %s'%(imageFile))
43
+ print('List of questions:')
44
+ print(data[k]['questions'])
45
+ print('List of corresponding answers:')
46
+ print(data[k]['answers'])
47
+ print('Use this image as training (1), validation (2) or testing (3): %s'%(data[k]['split']))
48
+ print('*************************')
49
+
50
+
51
+
52
+
53
+
54
+ ######################################################################
55
+ ########################### Get dataset stats ########################
56
+ ######################################################################
57
+ genSet=set()
58
+ for k in data.keys():
59
+ genSet.add(data[k]['genre'])
60
+
61
+
62
+
63
+ numImages=len(data.keys())
64
+ numQApairs=0
65
+ numWordsInQuestions=0
66
+ numWordsInAnswers=0
67
+ numQuestionsPerImage=0
68
+ ANS=set() # Set of unique answers
69
+ authorSet=set()
70
+ bookSet=set()
71
+
72
+
73
+ for imgId in data.keys():
74
+ numQApairs = numQApairs+len(data[imgId]['questions'])
75
+ numQuestionsPerImage = numQuestionsPerImage + len(data[imgId]['questions'])
76
+ authorSet.add(data[imgId]['authorName'])
77
+ bookSet.add(data[imgId]['title'])
78
+
79
+ for qno in range(len(data[imgId]['questions'])):
80
+ ques=data[imgId]['questions'][qno]
81
+ numWordsInQuestions = numWordsInQuestions+len(ques.split())
82
+ for ano in range(len(data[imgId]['answers'])):
83
+ ans=data[imgId]['answers'][ano]
84
+ ANS.add(ans)
85
+ numWordsInAnswers = numWordsInAnswers+len(str(ans).split())
86
+
87
+
88
+
89
+ print("--------------------------------")
90
+ print("Number of Images: %d" %(numImages))
91
+ print("Number of QA pairs: %d" %(numQApairs))
92
+ print("Number of unique author: %d" %(len(authorSet)))
93
+ print("Number of unique title: %d" %(len(bookSet)))
94
+ print("Number of unique answers: %d" %(len(ANS)))
95
+ print("Number of unique genre: %d" %(len(genSet)))
96
+ print("Average question length (in words): %.2f" %(float(numWordsInQuestions)/float(numQApairs)))
97
+ print("Average answer length (in words): %.2f" %(float(numWordsInAnswers)/float(numQApairs)))
98
+ print("Average number of questions per image: %.2f" %(float(numQuestionsPerImage)/float(numImages)))
99
+ print("--------------------------------")
100
+