Commit b4f92312 authored by Rudolf Chrispens's avatar Rudolf Chrispens
Browse files

coco validator

parent 7dcb0690
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -144,14 +144,22 @@ class coco_validator(object):

            if save_sampled_captions:
                num_iter = int(np.ceil(features.shape[0] / self.batch_size)) - self.batch_size
                all_sam_cap = np.ndarray((int(np.floor(features.shape[0] / self.batch_size)), 20))
                all_sam_cap = np.ndarray((int(np.ceil(features.shape[0] / self.batch_size)), 20))
                print("all_sam_cap.shape: ", all_sam_cap.shape)

                if _config.validator.max_iteration != -1:
                    num_iter = _config.validator.max_iteration
                for i in range(num_iter):
                    features_batch = features[i * self.batch_size:(i + 1) * self.batch_size]
                    left_side = int(i * self.batch_size)
                    right_side = int((i + 1) * self.batch_size)

                    features_batch = features[left_side:right_side]
                    feed_dict = {self.model.features: features_batch}
                    all_sam_cap[i * self.batch_size:(i + 1) * self.batch_size] = sess.run(sampled_captions, feed_dict)

                    temp = sess.run(sampled_captions, feed_dict)
                    print(f"Input shape: {temp.shape} vs  {left_side}:{right_side}")

                    all_sam_cap[left_side:right_side] = temp
                    if i % 20 == 0:
                        print("#> Validator Batch iteration:" + str(i) + " from max: " + str(num_iter))
                        # print("\t#> all_samp_cap: " + str(i) + "\n", current_reader.decode_captions_2(all_sam_cap[i * self.batch_size - self.batch_size:i * self.batch_size], self.model.idx_to_word))
@@ -164,7 +172,7 @@ class coco_validator(object):
                    os.makedirs(path)
                captionlist_for_eval = []

                for numb, caption in enumerate(all_decoded[:num_iter * self.batch_size]):
                for numb, caption in enumerate(all_decoded):
                    if i % 5 == 0:
                        captionlist_for_eval.append({'caption': ' '.join(caption), 'image_id': int(image_idxs[numb]), 'image_name': data['file_names'][numb] })