def get_class_weights(dataPath='./train.json'):
    print('-- get_class_info --')
    with open(dataPath, 'r') as f:
        DB = json.load(f)
    obj_dict = {}
    color_dict = {}
    os_dict = {}
    rel_dict = {}
    for (idx, data) in enumerate(DB):
        for obj in data['objects']:
            if (obj['class'] in obj_dict):
                obj_dict[obj['class']] += 1
            else:
                obj_dict[obj['class']] = 1
            if (obj['color'] in color_dict):
                color_dict[obj['color']] += 1
            else:
                color_dict[obj['color']] = 1
            if (obj['open_state'] in os_dict):
                os_dict[obj['open_state']] += 1
            else:
                os_dict[obj['open_state']] = 1
        if (len(data['objects']) > 0):
            rel_dict['background'] = ((len(data['objects']) * (len(data['objects']) - 1)) - len(data['relationships']))
        for rel in data['relationships']:
            if (rel['predicate'] in rel_dict):
                rel_dict[rel['predicate']] += 1
            else:
                rel_dict[rel['predicate']] = 1
    output = [obj_dict, color_dict, os_dict, rel_dict]
    print('results')
    pprint(output)

    def get_weight(class_dict):
        values = np.array(list(class_dict.values())).astype(float)
        weights = np.zeros_like(values)
        print(values)
        sum = values.sum()
        for (i, v) in enumerate(values):
            values[i] /= sum
        max = values.max()
        for (i, v) in enumerate(values):
            weights[i] = (max / values[i])
        weights_dict = dict(zip(class_dict.keys(), weights.tolist()))
        return weights_dict
    print('\nweights')
    all_weights = {}
    all_weights['object'] = get_weight(obj_dict)
    all_weights['color'] = get_weight(color_dict)
    all_weights['open_state'] = get_weight(os_dict)
    all_weights['relationship'] = get_weight(rel_dict)
    pprint(all_weights['object'])
    pprint(all_weights['color'])
    pprint(all_weights['open_state'])
    pprint(all_weights['relationship'])
    with open('./class_weights.json', 'w') as f:
        json.dump(all_weights, f, indent='\t')
    print('generate class_weights.json')
def get_class_weights(dataPath='./train.json'):
    print('-- get_class_info --')
    with open(dataPath, 'r') as f:
        DB = json.load(f)
    obj_dict = {}
    color_dict = {}
    os_dict = {}
    rel_dict = {}
    for (idx, data) in enumerate(DB):
        for obj in data['objects']:
            if (obj['class'] in obj_dict):
                obj_dict[obj['class']] += 1
            else:
                obj_dict[obj['class']] = 1
            if (obj['color'] in color_dict):
                color_dict[obj['color']] += 1
            else:
                color_dict[obj['color']] = 1
            if (obj['open_state'] in os_dict):
                os_dict[obj['open_state']] += 1
            else:
                os_dict[obj['open_state']] = 1
        if (len(data['objects']) > 0):
            rel_dict['background'] = ((len(data['objects']) * (len(data['objects']) - 1)) - len(data['relationships']))
        for rel in data['relationships']:
            if (rel['predicate'] in rel_dict):
                rel_dict[rel['predicate']] += 1
            else:
                rel_dict[rel['predicate']] = 1
    output = [obj_dict, color_dict, os_dict, rel_dict]
    print('results')
    pprint(output)

    def get_weight(class_dict):
        values = np.array(list(class_dict.values())).astype(float)
        weights = np.zeros_like(values)
        print(values)
        sum = values.sum()
        for (i, v) in enumerate(values):
            values[i] /= sum
        max = values.max()
        for (i, v) in enumerate(values):
            weights[i] = (max / values[i])
        weights_dict = dict(zip(class_dict.keys(), weights.tolist()))
        return weights_dict
    print('\nweights')
    all_weights = {}
    all_weights['object'] = get_weight(obj_dict)
    all_weights['color'] = get_weight(color_dict)
    all_weights['open_state'] = get_weight(os_dict)
    all_weights['relationship'] = get_weight(rel_dict)
    pprint(all_weights['object'])
    pprint(all_weights['color'])
    pprint(all_weights['open_state'])
    pprint(all_weights['relationship'])
    with open('./class_weights.json', 'w') as f:
        json.dump(all_weights, f, indent='\t')
    print('generate class_weights.json')