Esempio n. 1
0
def full_energy_batch(out_dir, out_filename, batch_split, gmm1=None, query_tup=None, include_neg=True, use_scaling=True):
    import dog_walking_gmm as dwg
    import irsg_querygen as qgen
    
    if gmm1 is None:
        gmm1 = get_dw_gmms()
    
    if query_tup is None:
        query_str = 'dog_walker holding leash attached_to dog'
        query_obj = qgen.gen_two_rel_chain(query_str)
        query_tup = (query_obj, query_str)
    
    query = qgen.gen_two_rel_chain('dog_walker holding leash attached_to dog')
    batches = []
    
    if batch_split == 'pos':
        print('  Running PSU images')
        pos_test = energy_batch('pos_test', query_tup[0], gmm1, verbose=True, use_scaling=use_scaling)
        batches.append(('pos', 'True', 'True', pos_test))
    elif batch_split == 'stanford':
        print('  Running Stanford images')
        res = energy_batch(batch_split, query_tup[0], gmm1, verbose=True, use_scaling=use_scaling)
        batches.append(('pos', 'True', 'True', res))
    else:
        print('unknown batch split type "{}"'.format(batch_split))
    
    if batch_split == 'neg' or include_neg:
        print('  Running negative images (No person, No dog)')
        neg_np_nd = energy_batch('neg_np_nd', query_tup[0], gmm1, verbose=True, use_scaling=use_scaling)
        batches.append(('neg', 'False', 'False', neg_np_nd))
        
        print('  Running negative images (No person, dog)')
        neg_np_pd = energy_batch('neg_np_pd', query_tup[0], gmm1, verbose=True, use_scaling=use_scaling)
        batches.append(('neg', 'False', 'True', neg_np_pd))
        
        print('  Running negative images (person, No dog)')
        neg_pp_nd = energy_batch('neg_pp_nd', query_tup[0], gmm1, verbose=True, use_scaling=use_scaling)
        batches.append(('neg', 'True', 'False', neg_pp_nd))
        
        print('  Running negative images (person, dog)')
        neg_pp_pd = energy_batch('neg_pp_pd', query_tup[0], gmm1, verbose=True, use_scaling=use_scaling)
        batches.append(('neg', 'True', 'True', neg_pp_pd))
    
    # store all the scores
    f = open(out_dir + out_filename, 'wb')
    for batch in batches:
        pos_neg_flag = batch[0]
        person_flag = batch[1]
        dog_flag = batch[2]
        results = batch[3]
        prefix = '{}, {}, {}, '.format(pos_neg_flag, person_flag, dog_flag)
        for result in results:
            line = prefix + '{}, {:4f}\n'.format(result[0], result[1])
            f.write(line)
    f.close()
Esempio n. 2
0
def full_viz_plot_batch(out_dir, batch_split, gmms=None, query_tup=None, include_neg=False, use_scaling=True):
    import irsg_querygen as qgen
    
    if gmms is None:
        gmms = get_dw_gmms()
    
    if query_tup is None:
        query_str = 'dog_walker holding leash attached_to dog'
        query_obj = qgen.gen_two_rel_chain(query_str)
        query_tup = (query_obj, query_str)
    
    if batch_split == 'pos':
        print('  Running PSU images')
        viz_plot_batch('pos_test', query_tup, gmms, out_dir, verbose=True, use_scaling=use_scaling)
    elif batch_split == 'stanford':
        print('  Running Stanford images')
        viz_plot_batch(batch_split, query_tup, gmms, out_dir, verbose=True, use_scaling=use_scaling)
    else:
        return
    
    if include_neg:
        print('  Running negative images (No person, No dog)')
        viz_plot_batch('neg_np_nd', query_tup, gmms, out_dir, verbose=True, use_scaling=use_scaling)
        print('  Running negative images (No person, dog)')
        viz_plot_batch('neg_np_pd', query_tup, gmms, out_dir, verbose=True, use_scaling=use_scaling)
        print('  Running negative images (person, No dog)')
        viz_plot_batch('neg_pp_nd', query_tup, gmms, out_dir, verbose=True, use_scaling=use_scaling)
        print('  Running negative images (person, dog)')
        viz_plot_batch('neg_pp_pd', query_tup, gmms, out_dir, verbose=True, use_scaling=use_scaling)
Esempio n. 3
0
def full_viz_batch(out_dir, out_filename, batch_split, gmms=None, query_tup=None):
    import irsg_querygen as qgen
    
    if gmms is None:
        gmms = get_dw_gmms()
    
    if query_tup is None:
        query_str = 'dog_walker holding leash attached_to dog'
        query_obj = qgen.gen_two_rel_chain(query_str)
        query_tup = (query_obj, query_str)
    lines = []
    
    if batch_split == 'pos':
        print('  Running PSU images')
        pos_test = viz_batch('pos_test', query_tup, gmms, verbose=True)
        lines.extend(pos_test)
    elif batch_split == 'stanford':
        print('  Running Stanford images')
        res = viz_batch(batch_split, query_tup, gmms, verbose=True)
    else:
        print('  Running negative images (No person, No dog)')
        neg_np_nd = viz_batch('neg_np_nd', query_tup, gmms, verbose=True)
        lines.extend(neg_np_nd)
        
        print('  Running negative images (No person, dog)')
        neg_np_pd = viz_batch('neg_np_pd', query_tup, gmms, verbose=True)
        lines.extend(neg_np_pd)
        
        print('  Running negative images (person, No dog)')
        neg_pp_nd = viz_batch('neg_pp_nd', query_tup, gmms, verbose=True)
        lines.extend(neg_pp_nd)
        
        print('  Running negative images (person, dog)')
        neg_pp_pd = viz_batch('neg_pp_pd', query_tup, gmms, verbose=True)
        lines.extend(neg_pp_pd)
    
    # store all the viz data
    fq_filename = out_dir
    if fq_filename[-1] != '/':
        fq_filename += '/'
    fq_filename += out_filename
    
    f = open(fq_filename, 'wb')
    for line in lines:
        f.write(line)
    f.close()
Esempio n. 4
0
def viz_plot(outdir='/home/econser/School/research/output/', filename='dog-walking301.csv', image_type='pos_test', gmms=None, query_tup=None, use_scaling=True):
    import opengm as ogm
    import plot_utils as pt; reload(pt)
    import irsg_querygen as qgen
    
    if gmms is None:
        gmms = get_dw_gmms()
    
    image_num = filename_to_id(filename)
    
    if query_tup is None:
        query_str = 'dog_walker holding leash attached_to dog'
        query_obj = qgen.gen_two_rel_chain(query_str)
        query_tup = (query_obj, query_str)
    
    pregen_dir = dir_map[image_type]
    classes = [obj.names for obj in query_tup[0].objects]
    pg_comps = get_pregen_components(filename, pregen_dir, gmms, classes)
    
    pgm, pgm_to_sg = gen_factor_graph(query_tup[0], pg_comps, use_scaling=use_scaling)
    energy, best_box_ixs, marginals = do_inference(pgm)
    
    image_subdir = 'psu_dw/DogWalkingSituationNegativeExamples'
    if image_type == 'neg_np_nd':
        image_subdir += '/NoDogNoPerson'
    elif image_type == 'neg_np_pd':
        image_subdir += '/DogNoPerson'
    elif image_type == 'neg_pp_nd':
        image_subdir += '/PersonNoDog'
    elif image_type == 'neg_pp_pd':
        image_subdir += '/DogAndPerson'
    elif image_type == 'pos_test' or image_type == 'pos_train':
        image_subdir = 'psu_dw/PortlandSimpleDogWalking'
    elif image_type == 'stanford':
        image_subdir = 'StanfordSimpleDogWalking'
    
    image_filename = id_to_filename(image_num, image_type)
    
    pt.draw_best_objects('/home/econser/School/research/images/'+image_subdir, pg_comps, best_box_ixs, energy, out_dir=outdir, out_filename='viz_'+image_filename.split('.')[0]+'.png')
Esempio n. 5
0
def viz_csv(filename='dog-walking301.csv', image_type='pos_test', gmms=None, query_tup=None):
    import irsg_querygen as qgen
    import opengm as ogm
    
    if gmms is None:
        gmms = get_dw_gmms()
    
    image_num = filename_to_id(filename)
    
    if query_tup is None:
        query_str = 'dog_walker holding leash attached_to dog'
        query_obj = qgen.gen_two_rel_chain(query_str)
        query_tup = (query_obj, query_str)
    
    pregen_dir = dir_map[image_type]
    classes = [obj.names for obj in query_tup[0].objects]
    pg_comps = get_pregen_components(filename, pregen_dir, gmms, classes)
    
    pgm, pgm_to_sg = gen_factor_graph(query_tup[0], pg_comps)
    energy, best_box_ixs, marginals = do_inference(pgm)
    
    # generate the csv data
    # 0 : image ID
    viz_data = '{:03d}, 0, "{}"\n'.format(image_num, query_tup[1])
    
    # 1 : object ix, obj name, bbox coords
    for pgm_obj_ix, bbox_ix in enumerate(best_box_ixs):
        sg_obj_ix = pgm_to_sg[pgm_obj_ix]
        sg_obj = pg_comps.unary_components[sg_obj_ix]
        
        obj_name = sg_obj.name
        b = sg_obj.boxes[bbox_ix]
        
        viz_data += '{:03d}, 1, {}, "{}", {}, {}, {}, {}\n'.format(image_num, sg_obj_ix, obj_name, int(b[0]), int(b[1]), int(b[2]), int(b[3]))
    
    # 2 : energy
    viz_data += '{:03d}, 2, {:0.4f}\n'.format(image_num, energy)
    
    # 3 : match/no match
    # TODO: paramaterize the TP IDs
    if image_num <= 400:
        viz_data += '{:03d}, 3, match\n'.format(image_num)
    else:
        viz_data += '{:03d}, 3, no match\n'.format(image_num)
    
    # 4 : image subdirectory
    image_subdir = 'DogWalkingSituationNegativeExamples'
    if image_type == 'neg_np_nd':
        image_subdir += '/NoDogNoPerson'
    elif image_type == 'neg_np_pd':
        image_subdir += '/DogNoPerson'
    elif image_type == 'neg_pp_nd':
        image_subdir += '/PersonNoDog'
    elif image_type == 'neg_pp_pd':
        image_subdir += '/DogAndPerson'
    elif image_type == 'pos_test' or image_type == 'pos_train':
        image_subdir = 'PortlandSimpleDogWalking'
    viz_data += '{:03d}, 4, {}\n'.format(image_num, image_subdir)
    
    # 5 : image filename
    image_filename = id_to_filename(image_num, image_type)
    viz_data += '{:03d}, 5, {}\n'.format(image_num, image_filename)
    
    return viz_data