コード例 #1
0
def main(**kwargs):
    subset = kwargs['subset']
    const = FlickrConstants()

    io.mkdir_if_not_exists(const.flickr_paths['proc_dir'])

    image_ids = io.read(const.subset_ids[subset])
    image_ids = [idx.decode() for idx in image_ids.split()]

    # Write boxes to json
    boxes = {}
    for image_id in tqdm(image_ids):
        box_xml = os.path.join(const.flickr_paths['anno_dir'],
                               f'{image_id}.xml')
        boxes[image_id] = get_annotations(box_xml)

    io.dump_json_object(boxes, const.box_json[subset])

    # Write sentence annos to json
    sent = {}
    for image_id in tqdm(image_ids):
        sent_txt = os.path.join(const.flickr_paths['sent_dir'],
                                f'{image_id}.txt')
        sent[image_id] = get_sentence_data(sent_txt)

    io.dump_json_object(sent, const.sent_json[subset])
コード例 #2
0
def main(argv):
	parser = argparse.ArgumentParser()
	parser.add_argument('-d', '--descriptorsFile', help='descriptors dict file', required=True)
	parser.add_argument('-q', '--queryIDs', help='query IDs joined by + symbol', required=True)
	parser.add_argument('-s', '--resultSize', help='result list size', required=True)
	parser.add_argument('-f', '--distanceName', help='distance function name', required=True)
	parser.add_argument('-i', '--img_path_expression', help='the img path expression in which %s is the ID', required=True)
	parser.add_argument('-o', '--plot_file', help='the output file for plotting', required=True)
	ARGS = parser.parse_args()
	samplesDescriptors = io.read(ARGS.descriptorsFile)
	queryIDs = ARGS.queryIDs.split('+')
	resultSize = int(ARGS.resultSize)
	distanceName = ARGS.distanceName
	img_path_expression = ARGS.img_path_expression
	plot_file = ARGS.plot_file

	labelsByID = dict()
	for id in samplesDescriptors.keys():
		labelsByID[id] = id.rsplit('_')[0]

	searchs_results = search.queries(distanceName, resultSize, samplesDescriptors, queryIDs)
	for r in searchs_results:
		print(r)
	precisions, averagePrecisions = search.evaluate_results(searchs_results, labelsByID)
	p_formatted = search.format_mean_std(precisions)
	ap_formatted = search.format_mean_std(averagePrecisions)
	print('results using distance %s:' % distanceName)
	print('P@%d by query:' % resultSize, precisions)
	print('AP@%d by query:' % resultSize, averagePrecisions)
	print('P@%d: %s, AP@%d: %s' % (resultSize, p_formatted, resultSize, ap_formatted))

	search.print_results(searchs_results, precisions, averagePrecisions, p_formatted, ap_formatted, img_path_expression, plot_file)
コード例 #3
0
def main(**kwargs):
    subset = kwargs['subset']
    const = FlickrConstants()

    image_ids = io.read(const.subset_ids[subset])
    image_ids = [idx.decode() for idx in image_ids.split()]

    image_dir = const.flickr_paths['image_dir']

    det_input = []
    for image_id in tqdm(image_ids):
        image_path = os.path.join(image_dir, f'{image_id}.jpg')
        det_input.append({'path': image_path, 'id': image_id})

    io.dump_json_object(
        det_input,
        os.path.join(kwargs['out_dir'],
                     'det_input_' + kwargs['subset'] + '.json'))
コード例 #4
0
ファイル: index.py プロジェクト: so77id/MO446-computervision
def main(argv):
    # Parse arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('-il',
                        '--input_list',
                        help='Input list',
                        required=True)
    parser.add_argument('-if',
                        '--input_folder',
                        help='Input folder',
                        required=True)
    parser.add_argument('-de',
                        '--descriptor_name',
                        help='Descriptor name',
                        required=True)
    parser.add_argument('-rf',
                        '--regions_file',
                        help='Regions input file',
                        required=True)
    parser.add_argument('-nf',
                        '--n_features',
                        help='Number of features',
                        required=True)
    parser.add_argument('-ro',
                        '--region_descriptors_output_file',
                        help='Output file',
                        required=True)
    parser.add_argument('-do',
                        '--descriptors_output_file',
                        help='Output file',
                        required=True)
    parser.add_argument('-vwo',
                        '--visual_words_output_file',
                        help='Output file',
                        required=True)
    parser.add_argument('-d',
                        '--debug',
                        help='Debuggin mode',
                        action='store_true')
    ARGS = parser.parse_args()

    global DEBUG
    DEBUG = ARGS.debug

    regions = io.read(ARGS.regions_file)

    region_descriptors_output_file = ARGS.region_descriptors_output_file
    descriptors_output_file = ARGS.descriptors_output_file
    visual_words_output_file = ARGS.visual_words_output_file

    if os.path.isfile(region_descriptors_output_file) is False:
        with open(ARGS.input_list, 'r') as input_list_files:
            descriptors = {}
            for line in input_list_files:
                print("Reading:", line)
                file_name = "{}/{}".format(ARGS.input_folder,
                                           line).split("\n")[0]
                img = cv2.imread(file_name)

                labeled_image, n_regions = regions[line.split(".")[0]]

                img_descriptor = desc.get_descriptors(
                    img,
                    labeled_image,
                    n_regions,
                    descriptor_name=ARGS.descriptor_name)
                descriptors[line.split(".")[0]] = img_descriptor

            io.write(descriptors, output_file=region_descriptors_output_file)
    else:
        descriptors = io.read(region_descriptors_output_file)

    img_descriptors, visual_words = bovw.describe_images(
        descriptors, int(ARGS.n_features))

    io.write(img_descriptors, output_file=descriptors_output_file)
    io.write(visual_words, output_file=visual_words_output_file)
コード例 #5
0
 def read_image_ids(self):
     image_ids = io.read(self.const.image_ids_txt)
     image_ids = [idx.decode() for idx in image_ids.split()]
     return image_ids