def generate_prior_knowledge(dataPath='./thor_DB_msdn.json'):
    print('-- generate_prior_knowledge --')
    with open(dataPath) as f:
        db = json.load(f)
    prior_knowledge = {}
    obj_category = dict()
    for data in db:
        objs = data['objects']
        for obj in objs:
            if (obj['class'] in obj_category):
                if (obj['size_3d'][0] >= obj['size_3d'][2]):
                    size = [obj['size_3d'][0], obj['size_3d'][1], obj['size_3d'][2]]
                else:
                    size = [obj['size_3d'][2], obj['size_3d'][1], obj['size_3d'][0]]
                obj_category[obj['class']]['size_3d'].append(size)
            else:
                obj_category[obj['class']] = {}
                if (obj['size_3d'][0] >= obj['size_3d'][2]):
                    size = [obj['size_3d'][0], obj['size_3d'][1], obj['size_3d'][2]]
                else:
                    size = [obj['size_3d'][2], obj['size_3d'][1], obj['size_3d'][0]]
                obj_category[obj['class']]['size_3d'] = [size]
    for (k, v) in obj_category.items():
        obj_category[k]['size_3d'] = np.array(v['size_3d']).mean(0).tolist()
    prior_knowledge['objects'] = obj_category
    with open('./prior_knowledge.json', 'w') as f:
        json.dump(prior_knowledge, f, indent='\t')
    print('generate prior_knowledge.json')
def generate_prior_knowledge(dataPath='./thor_DB_msdn.json'):
    print('-- generate_prior_knowledge --')
    with open(dataPath) as f:
        db = json.load(f)
    prior_knowledge = {}
    obj_category = dict()
    for data in db:
        objs = data['objects']
        for obj in objs:
            if (obj['class'] in obj_category):
                if (obj['size_3d'][0] >= obj['size_3d'][2]):
                    size = [obj['size_3d'][0], obj['size_3d'][1], obj['size_3d'][2]]
                else:
                    size = [obj['size_3d'][2], obj['size_3d'][1], obj['size_3d'][0]]
                obj_category[obj['class']]['size_3d'].append(size)
            else:
                obj_category[obj['class']] = {}
                if (obj['size_3d'][0] >= obj['size_3d'][2]):
                    size = [obj['size_3d'][0], obj['size_3d'][1], obj['size_3d'][2]]
                else:
                    size = [obj['size_3d'][2], obj['size_3d'][1], obj['size_3d'][0]]
                obj_category[obj['class']]['size_3d'] = [size]
    for (k, v) in obj_category.items():
        obj_category[k]['size_3d'] = np.array(v['size_3d']).mean(0).tolist()
    prior_knowledge['objects'] = obj_category
    with open('./prior_knowledge.json', 'w') as f:
        json.dump(prior_knowledge, f, indent='\t')
    print('generate prior_knowledge.json')