def save_dict(kv_dict, save_dict_path):
    # save the path dict, the key is image name, the value is the image/feature path
    #kv_dict: key-value dict, look like {'imag':'osdfjskldfnklvjdaf'}
    #save_dict_path: save path for prototxt file
    path_dict = rw.PathDict()
    for k in kv_dict.keys():
        one_path = path_dict.path_dict.add()
        one_path.key = k
        one_path.value = kv_dict[k]

    data = path_dict.SerializeToString()
    #    if os.path.exists( save_dict_path ):
    #        print('ErrorMessage:', save_dict_path, ' is already exisit!')
    #        return -1
    with open(save_dict_path, 'a') as f:
        f.write(data)
def read_dict(dict_path):
    # read the key-value dict, wich save by save_dict function
    #dict_path: the prototxt file path
    # get the key-value

    if not os.path.exists(dict_path):
        print('ErrorMessage:', dict_path, ' is not exisit!')
        return -1
    with open(dict_path, 'r') as f:
        data = f.read()

    data_proto = rw.PathDict()
    data_proto.ParseFromString(data)

    pdict = {}
    for one_elem in data_proto.path_dict:
        pdict[one_elem.key] = one_elem.value
    return pdict