Skip to content

Commit

Permalink
issue activeloopai#106 MPII Human Pose Dataset example added
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchitvj committed Nov 1, 2020
1 parent 31788fe commit 3bbd0db
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions examples/MPII Human Pose Dataset/mpii_data_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@


class MPIIGenerator(dataset.DatasetGenerator):
'''
"""
Purpose of generator class is to return dictionary of arrays for the individual example.
This class inherites from dataset.DatasetGenerator so it is called iteratively for the
number of examples present in dataset.
We have defined two functions here:
meta: returns keys of the dictinary which are refered as features and labels of dataset.
__call__ : this function takes the list of features(annotations in this case)as input and
adds the features(or labels) according to the keys in a row of dataset.
'''
"""

def meta(self):

return {
"image": {"shape": (1,), "dtype": "object", "chunksize": 1000},
"dataset": {"shape": (1,), "dtype": "object", "chunksize": 1000},
Expand All @@ -35,7 +33,11 @@ def meta(self):
"joint_self": {"shape": (1,), "dtype": "object", "chunksize": 1000},
"scale_provided": {"shape": (1,), "dtype": "object", "chunksize": 1000},
"joint_others": {"shape": (1,), "dtype": "object", "chunksize": 1000},
"scale_provided_other": {"shape": (1,), "dtype": "object", "chunksize": 1000},
"scale_provided_other": {
"shape": (1,),
"dtype": "object",
"chunksize": 1000
},
"objpos_other": {"shape": (1,), "dtype": "object", "chunksize": 1000},
"annolist_index": {"shape": (1,), "dtype": "object", "chunksize": 1000},
"people_index": {"shape": (1,), "dtype": "object", "chunksize": 1000},
Expand All @@ -47,8 +49,8 @@ def __call__(self, input):
try:
ds = {}
img_path = '/home/sanchit/images/'
n = 1 # for 1 row

n = 1 # for 1 row
ds["image"] = np.empty(n, object)
ds["dataset"] = np.empty(n, object)
ds["isValidation"] = np.empty(n, object)
Expand All @@ -64,18 +66,18 @@ def __call__(self, input):
ds["annolist_index"] = np.empty(n, object)
ds["people_index"] = np.empty(n, object)
ds["numOtherPeople"] = np.empty(n, object)
i = 0 # i = 0 for 1st row, i changes iteratively.

i = 0 # i = 0 for 1st row, i changes iteratively.
ds["image"][i] = np.array(Image.open(img_path + input['img_paths']))
ds["dataset"][i] = input['dataset']
ds["isValidation"][i] = input['isValidation']
ds["img_paths"][i] = input['img_paths']
ds['img_width'][i] = input['img_width']
ds["img_height"][i] = input['img_height']
'''
"""
Some features in input list has another list(more than one list) inside them.
So they are converted to array using np.array(list(list()).
'''
"""
ds["objpos"][i] = np.array(input['objpos'])
ds["joint_self"][i] = np.array(input['joint_self'])
ds["scale_provided"][i] = input['scale_provided']
Expand All @@ -87,19 +89,19 @@ def __call__(self, input):
ds["numOtherPeople"][i] = input['numOtherPeople']

return ds

except Exception as e:
logger.error(e, exc_info=e, stack_info=True)

def load_dataset():
'''
"""
This function is used to load json annotations in the form of dictionary and then
appending all the dictionaries(25205 examples) in the list named annotations.
Then this list is given as input to __call__ function of generator class.
dataset.generate calls the generator class iteratively for each dictionary present
in the list(annotations). Finally it returns the complete dataset with all examples.
'''
"""

with open('/home/sanchit/mpii_annotations.json',"r") as f:

instances = json.load(f)
Expand All @@ -109,18 +111,18 @@ def load_dataset():
for i in range(len(instances)):
annotations.append(instances[i])

# print(annotations[:5])
# print(annotations[:5])
print("Annotations loaded.")

ds = dataset.generate(MPIIGenerator(), annotations)
print("Dataset generated.")

return ds

def main():

t1 = time.time()
# Call the load_dataset function to generate the complete dataset.
# Call the load_dataset function to generate the complete dataset
ds = load_dataset()
# ds.store stores the dataset in "username/MPII_Human_Pose_Dataset"
ds.store("MPII_Human_Pose_Dataset")
Expand Down

0 comments on commit 3bbd0db

Please sign in to comment.