"tests/rag/test_retrieval_rag.py" did not exist on "f4e04cd2c671312c8f750f55cf9f51753718f0df"
Commit 5d419763 authored by Vishnu Banna's avatar Vishnu Banna
Browse files

model Kmean comments adressed

parent d9a51198
...@@ -186,10 +186,10 @@ class AnchorBoxes(hyperparams.Config): ...@@ -186,10 +186,10 @@ class AnchorBoxes(hyperparams.Config):
level_limits: Optional[List[int]] = None level_limits: Optional[List[int]] = None
anchors_per_scale: int = 3 anchors_per_scale: int = 3
generate_anchors: bool = False generate_anchors: bool = True
scaling_mode: str = "sqrt" scaling_mode: str = "sqrt"
box_generation_mode: str = "per_level" box_generation_mode: str = "per_level"
num_samples: Optional[int] = None num_samples: int = 200
def get(self, min_level, max_level): def get(self, min_level, max_level):
"""Distribute them in order to each level. """Distribute them in order to each level.
......
# Copyright 2021 The TensorFlow Authors. All Rights Reserved.
import math #
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""K-means for generation of anchor boxes for YOLO."""
import numpy as np import numpy as np
import tensorflow as tf import tensorflow as tf
...@@ -13,7 +26,7 @@ from matplotlib.pyplot import cm ...@@ -13,7 +26,7 @@ from matplotlib.pyplot import cm
import logging import logging
def IOU(X, centroids_X, iou_type = "iou"): def _iou(X, centroids_X, iou_type = "iou"):
"""Compute the WH IOU between the ground truths and the centroids.""" """Compute the WH IOU between the ground truths and the centroids."""
# set the center of the boxes to zeros # set the center of the boxes to zeros
...@@ -34,12 +47,12 @@ class AnchorKMeans: ...@@ -34,12 +47,12 @@ class AnchorKMeans:
def boxes(self): def boxes(self):
return self._boxes.numpy() return self._boxes.numpy()
def get_box_from_dataset(self, dataset, image_w=512, num_samples = None): def get_box_from_dataset(self, dataset, image_w=512, num_samples = -1):
"""Load all the boxes in the dataset into memory.""" """Load all the boxes in the dataset into memory."""
box_list = [] box_list = []
for i, sample in enumerate(dataset): for i, sample in enumerate(dataset):
if num_samples is not None and i > num_samples: if num_samples > 0 and i > num_samples:
break break
width = sample["width"] width = sample["width"]
height = sample["height"] height = sample["height"]
...@@ -92,7 +105,7 @@ class AnchorKMeans: ...@@ -92,7 +105,7 @@ class AnchorKMeans:
clusters = tf.cast(clusters, tf.float32) clusters = tf.cast(clusters, tf.float32)
# compute the IOU # compute the IOU
return IOU(boxes, clusters) return _iou(boxes, clusters)
def maximization(self, boxes, clusters, assignments): def maximization(self, boxes, clusters, assignments):
"""K-means maximization term""" """K-means maximization term"""
...@@ -186,7 +199,7 @@ class AnchorKMeans: ...@@ -186,7 +199,7 @@ class AnchorKMeans:
scaling_mode = "sqrt_log", scaling_mode = "sqrt_log",
box_generation_mode = "across_level", box_generation_mode = "across_level",
image_resolution=[512, 512, 3], image_resolution=[512, 512, 3],
num_samples = None): num_samples = -1):
"""Run k-means on th eboxes for a given input resolution. """Run k-means on th eboxes for a given input resolution.
Args: Args:
...@@ -266,7 +279,7 @@ class BoxGenInputReader(input_reader.InputReader): ...@@ -266,7 +279,7 @@ class BoxGenInputReader(input_reader.InputReader):
scaling_mode = "sqrt", scaling_mode = "sqrt",
box_generation_mode = "across_level", box_generation_mode = "across_level",
image_resolution=[512, 512, 3], image_resolution=[512, 512, 3],
num_samples = None, num_samples = -1,
input_context=None): input_context=None):
"""Run k-means on th eboxes for a given input resolution. """Run k-means on th eboxes for a given input resolution.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment