示例#1
0
def jsonFileFeatures(txt_feature_folder, json_feature_folder, scales, batch_size):
    for scale in scales:
        myIO.basic.check_folder(os.path.join(json_feature_folder, str(scale)))
    
    for scale in scales: 
        scale_feature_json = defaultdict(lambda: defaultdict(lambda: None))
        txt_feature_folder_of_scale = os.path.join(txt_feature_folder,str(scale))
        feature_fps = os.listdir(txt_feature_folder_of_scale)
        batch_feature_num = batch_size * scale2RowNumber(scale)**2
        for cnt, feature_fp in enumerate(feature_fps):
            if len(feature_fps)/batch_feature_num != cnt / batch_feature_num:
                continue
            if cnt != 0 and cnt % (batch_feature_num)== 0:
#                 pass

                with open(os.path.join(json_feature_folder, str(scale), str(cnt / (batch_feature_num)-1) + '.json'),'w') as batch_feature_file:
                    json.dump(scale_feature_json, batch_feature_file)
                    scale_feature_json = defaultdict(lambda: defaultdict(lambda: None))
                    print "%d / %d finished and saved"%(cnt, len(feature_fps)-1)
            if scale != 100:
                year, imid, d1, d2 = feature_fp.split('.')[0].split('_')
                filename = '_'.join([year,imid])
                index = int(d1)*scale2RowNumber(scale)+int(d2)
                scale_feature_json[filename][index] = reader.file2FloatList(os.path.join(txt_feature_folder_of_scale, feature_fp))
            else:
                filename= feature_fp.split('.')[0]
                index = 0
                scale_feature_json[filename][index] = reader.file2FloatList(os.path.join(txt_feature_folder_of_scale, feature_fp))
        with open(os.path.join(json_feature_folder, str(scale), str(cnt / (batch_feature_num)) + '.json'),'w') as batch_feature_file:
            print os.path.join(json_feature_folder, str(scale), str(cnt / (batch_feature_num)) + '.json')
            json.dump(scale_feature_json, batch_feature_file)
            scale_feature_json = defaultdict(lambda: defaultdict(lambda: None))
            print "%d / %d finished and saved"%(cnt, len(feature_fps)-1)
示例#2
0
def getJsonFeature(scale, filename, feature_root_folder):
    json_feature = defaultdict(lambda:None)
    for d1 in range(scale2RowNumber(scale)):
        for d2 in range(scale2RowNumber(scale)):
            if scale != 100:
                feature_file_fp = os.path.join(feature_root_folder, '_'.join([filename, str(d1), str(d2)+'.txt']))
                feature = reader.file2FloatList(feature_file_fp)
                json_feature[d1*scale2RowNumber(scale)+d2] = feature
            else:
                feature_file_fp = os.path.join(feature_root_folder, filename)
                feature = reader.file2FloatList(feature_file_fp)
                json_feature[d1*scale2RowNumber(scale)+d2] = feature
    return json_feature
示例#3
0
def getJsonFeature(scale, filename, feature_root_folder):
    json_feature = defaultdict(lambda: None)
    for d1 in range(scale2RowNumber(scale)):
        for d2 in range(scale2RowNumber(scale)):
            if scale != 100:
                feature_file_fp = os.path.join(
                    feature_root_folder,
                    '_'.join([filename, str(d1),
                              str(d2) + '.txt']))
                feature = reader.file2FloatList(feature_file_fp)
                json_feature[d1 * scale2RowNumber(scale) + d2] = feature
            else:
                feature_file_fp = os.path.join(feature_root_folder, filename)
                feature = reader.file2FloatList(feature_file_fp)
                json_feature[d1 * scale2RowNumber(scale) + d2] = feature
    return json_feature
示例#4
0
def jsonFileFeatures(txt_feature_folder, json_feature_folder, scales,
                     batch_size):
    for scale in scales:
        myIO.basic.check_folder(os.path.join(json_feature_folder, str(scale)))

    for scale in scales:
        scale_feature_json = defaultdict(lambda: defaultdict(lambda: None))
        txt_feature_folder_of_scale = os.path.join(txt_feature_folder,
                                                   str(scale))
        feature_fps = os.listdir(txt_feature_folder_of_scale)
        batch_feature_num = batch_size * scale2RowNumber(scale)**2
        for cnt, feature_fp in enumerate(feature_fps):
            if len(feature_fps) / batch_feature_num != cnt / batch_feature_num:
                continue
            if cnt != 0 and cnt % (batch_feature_num) == 0:
                #                 pass

                with open(
                        os.path.join(
                            json_feature_folder, str(scale),
                            str(cnt / (batch_feature_num) - 1) + '.json'),
                        'w') as batch_feature_file:
                    json.dump(scale_feature_json, batch_feature_file)
                    scale_feature_json = defaultdict(
                        lambda: defaultdict(lambda: None))
                    print "%d / %d finished and saved" % (cnt,
                                                          len(feature_fps) - 1)
            if scale != 100:
                year, imid, d1, d2 = feature_fp.split('.')[0].split('_')
                filename = '_'.join([year, imid])
                index = int(d1) * scale2RowNumber(scale) + int(d2)
                scale_feature_json[filename][index] = reader.file2FloatList(
                    os.path.join(txt_feature_folder_of_scale, feature_fp))
            else:
                filename = feature_fp.split('.')[0]
                index = 0
                scale_feature_json[filename][index] = reader.file2FloatList(
                    os.path.join(txt_feature_folder_of_scale, feature_fp))
        with open(
                os.path.join(json_feature_folder, str(scale),
                             str(cnt / (batch_feature_num)) + '.json'),
                'w') as batch_feature_file:
            print os.path.join(json_feature_folder, str(scale),
                               str(cnt / (batch_feature_num)) + '.json')
            json.dump(scale_feature_json, batch_feature_file)
            scale_feature_json = defaultdict(lambda: defaultdict(lambda: None))
            print "%d / %d finished and saved" % (cnt, len(feature_fps) - 1)