match_rcnn/mmdetection/tools/prepare_img_meta.py
def split_data(pos_pair_dict_path, train_ratio):
    ''' split data for training and validating matchrcnn model'''
    with open(pos_pair_dict_path, 'r') as f:
        pos_pair_dict = json.load(f)

    # get match-avaible images
    ma_images = []
    for k in list(pos_pair_dict.keys()):
        if pos_pair_dict[k] == []:
            pass
        else:
            ma_images.append(k)

    # get the training number
    train_num = int(len(ma_images) * 0.85)
    train_idxs = random.sample(range(len(ma_images)), train_num)

    # form the train.json
    train = {}
    for i in train_idxs:
        imgn = ma_images[i]
        train[imgn] = pos_pair_dict[imgn]

    with open('train_pos_pair_dict.json', 'w') as train_f:
        json.dump(train, train_f)

    print("The train annotation file for match rcnn is saved to '/train_pos_pair_dict.json'")

    # form the val.json
    val = {}
    for j, k in enumerate(ma_images):
        if k not in list(train.keys()):
            val[k] = pos_pair_dict[k]
        print(str(j+1),'/',str(len(ma_images)))
    with open('val_pos_pair_dict.json', 'w') as val_f:
        json.dump(val, val_f)
    print("The val annotation file for match rcnn is saved to '/val_pos_pair_dict.json'")
 split data for training and validating matchrcnn model
split data for training and validating matchrcnn model
split data for training and validating matchrcnn model
def split_data(pos_pair_dict_path, train_ratio):
    with open(pos_pair_dict_path, 'r') as f:
        pos_pair_dict = json.load(f)
    ma_images = []
    for k in list(pos_pair_dict.keys()):
        if pos_pair_dict[k] == []:
            pass
        else:
            ma_images.append(k)
    train_num = int(len(ma_images) * 0.85)
    train_idxs = random.sample(range(len(ma_images)), train_num)
    train = {}
    for i in train_idxs:
        imgn = ma_images[i]
        train[imgn] = pos_pair_dict[imgn]
    with open('train_pos_pair_dict.json', 'w') as train_f:
        json.dump(train, train_f)
    print("The train annotation file for match rcnn is saved to '/train_pos_pair_dict.json'")
    val = {}
    for j, k in enumerate(ma_images):
        if k not in list(train.keys()):
            val[k] = pos_pair_dict[k]
        print(str(j+1),'/',str(len(ma_images)))
    with open('val_pos_pair_dict.json', 'w') as val_f:
        json.dump(val, val_f)
    print("The val annotation file for match rcnn is saved to '/val_pos_pair_dict.json'")
def split_data ( pos_pair_dict_path , train_ratio ) : with open ( pos_pair_dict_path , 'r' ) as f : pos_pair_dict = json . load ( f ) ma_images = [ ] for k in list ( pos_pair_dict . keys ( ) ) : if pos_pair_dict [ k ] == [ ] : pass else : ma_images . append ( k ) train_num = int ( len ( ma_images ) * 0.85 ) train_idxs = random . sample ( range ( len ( ma_images ) ) , train_num ) train = { } for i in train_idxs : imgn = ma_images [ i ] train [ imgn ] = pos_pair_dict [ imgn ] with open ( 'train_pos_pair_dict.json' , 'w' ) as train_f : json . dump ( train , train_f ) print ( "The train annotation file for match rcnn is saved to '/train_pos_pair_dict.json'" ) val = { } for j , k in enumerate ( ma_images ) : if k not in list ( train . keys ( ) ) : val [ k ] = pos_pair_dict [ k ] print ( str ( j + 1 ) , '/' , str ( len ( ma_images ) ) ) with open ( 'val_pos_pair_dict.json' , 'w' ) as val_f : json . dump ( val , val_f ) print ( "The val annotation file for match rcnn is saved to '/val_pos_pair_dict.json'" )
split data for training and validating matchrcnn model
split data for training and validating matchrcnn model
''' split data for training and validating matchrcnn model''' # get match-avaible images # get the training number # form the train.json # form the val.json
pos_pair_dict_path
train_ratio