assert (captioner_ckpt is not None)
            captioner_saver.restore(sess, captioner_ckpt)
            used_ids = set()
            json_dump = []

            for i in itertools.count():
                time_start = time.time()
                try:
                    _ids, _target_seq, _image_id = sess.run(
                        [ids, target_seq, image_id])
                except:
                    break
                the_captions = recursive_ids_to_string(_ids[:, 0, :].tolist(),
                                                       vocab)
                the_labels = recursive_ids_to_string(
                    _target_seq[:, :].tolist(), vocab)
                the_image_ids = _image_id.tolist()
                for j, x, y in zip(the_image_ids, the_captions, the_labels):
                    if not j in used_ids:
                        used_ids.add(j)
                        json_dump.append({"image_id": j, "caption": x})
                print(
                    PRINT_STRING.format(
                        i, the_captions[0], the_labels[0],
                        BATCH_SIZE / (time.time() - time_start)))

            print("Finishing evaluating.")
            coco_get_metrics(json_dump, "ckpts/show_and_tell/",
                             get_train_annotations_file())
Esempio n. 2
0
            assert (captioner_ckpt is not None)
            captioner_saver.restore(sess, captioner_ckpt)
            used_ids = set()
            json_dump = []

            for i in itertools.count():
                time_start = time.time()
                try:
                    _ids, _target_seq, _image_id = sess.run(
                        [ids, target_seq, image_id])
                except:
                    break
                the_captions = recursive_ids_to_string(_ids[:, 0, :].tolist(),
                                                       vocab)
                the_labels = recursive_ids_to_string(
                    _target_seq[:, :].tolist(), vocab)
                the_image_ids = _image_id.tolist()
                for j, x, y in zip(the_image_ids, the_captions, the_labels):
                    if not j in used_ids:
                        used_ids.add(j)
                        json_dump.append({"image_id": j, "caption": x})
                print(
                    PRINT_STRING.format(
                        i, the_captions[0], the_labels[0],
                        BATCH_SIZE / (time.time() - time_start)))

            print("Finishing evaluating.")
            coco_get_metrics(json_dump, "ckpts/spatial_attention/",
                             get_train_annotations_file())
            assert (captioner_ckpt is not None)
            captioner_saver.restore(sess, captioner_ckpt)
            used_ids = set()
            json_dump = []

            for i in itertools.count():
                time_start = time.time()
                try:
                    _ids, _target_seq, _image_id = sess.run(
                        [ids, target_seq, image_id])
                except:
                    break
                the_captions = recursive_ids_to_string(_ids[:, 0, :].tolist(),
                                                       vocab)
                the_labels = recursive_ids_to_string(
                    _target_seq[:, :].tolist(), vocab)
                the_image_ids = _image_id.tolist()
                for j, x, y in zip(the_image_ids, the_captions, the_labels):
                    if not j in used_ids:
                        used_ids.add(j)
                        json_dump.append({"image_id": j, "caption": x})
                print(
                    PRINT_STRING.format(
                        i, the_captions[0], the_labels[0],
                        BATCH_SIZE / (time.time() - time_start)))

            print("Finishing evaluating.")
            coco_get_metrics(json_dump, "ckpts/up_down/",
                             get_train_annotations_file())
Esempio n. 4
0
            assert (captioner_ckpt is not None)
            captioner_saver.restore(sess, captioner_ckpt)
            used_ids = set()
            json_dump = []

            for i in itertools.count():
                time_start = time.time()
                try:
                    _ids, _target_seq, _image_id = sess.run(
                        [ids, target_seq, image_id])
                except:
                    break
                the_captions = recursive_ids_to_string(_ids[:, 0, :].tolist(),
                                                       vocab)
                the_labels = recursive_ids_to_string(
                    _target_seq[:, :].tolist(), vocab)
                the_image_ids = _image_id.tolist()
                for j, x, y in zip(the_image_ids, the_captions, the_labels):
                    if not j in used_ids:
                        used_ids.add(j)
                        json_dump.append({"image_id": j, "caption": x})
                print(
                    PRINT_STRING.format(
                        i, the_captions[0], the_labels[0],
                        BATCH_SIZE / (time.time() - time_start)))

            print("Finishing evaluating.")
            coco_get_metrics(json_dump, "ckpts/visual_sentinel/",
                             get_train_annotations_file())