MCPcopy Create free account
hub / github.com/apple/axlearn / _parse_eval_data

Function _parse_eval_data

axlearn/vision/input_detection.py:245–307  ·  view source on GitHub ↗

Parses single data for evaluation.

(
    data: dict[str, Any],
    *,
    output_size: tuple[int, int],
    output_stride: int,
    max_num_instances: int = 100,
    **kwargs,
)

Source from the content-addressed store, hash-verified

243
244
245def _parse_eval_data(
246 data: dict[str, Any],
247 *,
248 output_size: tuple[int, int],
249 output_stride: int,
250 max_num_instances: int = 100,
251 **kwargs,
252):
253 """Parses single data for evaluation."""
254 del kwargs # Delete train-specific kwargs, e.g. kwargs for data augmentation.
255
256 classes = data["groundtruth_classes"]
257 boxes = data["groundtruth_boxes"]
258
259 # Gets original image and its size.
260 image = data["image"]
261 image_shape = tf.shape(input=image)[0:2]
262
263 # Normalizes image with mean and std pixel values.
264 image = whiten(image)
265
266 # Converts boxes from normalized coordinates to pixel coordinates.
267 boxes = utils_detection.denormalize_boxes_tf(boxes, image_shape)
268
269 # Resizes and crops image.
270 image, image_info = resize_and_crop_image(
271 image,
272 desired_size=output_size,
273 padded_size=utils_detection.compute_padded_size(output_size, output_stride),
274 aug_scale_min=1.0, # No scale jitter for evaluation.
275 aug_scale_max=1.0, # No scale jitter for evaluation.
276 )
277 image_data = {"image": image, "image_info": image_info}
278 image_height, image_width, _ = image.get_shape().as_list()
279
280 # Resizes and crops boxes.
281 image_scale = image_info[2, :]
282 offset = image_info[3, :]
283 boxes = utils_detection.resize_and_crop_boxes(boxes, image_scale, image_info[1, :], offset)
284 # Filters out ground truth boxes that are all zeros.
285 indices = utils_detection.get_non_empty_box_indices(boxes)
286 boxes = tf.gather(boxes, indices)
287 classes = tf.gather(classes, indices)
288
289 # Sets up groundtruth data for evaluation.
290 groundtruths = {
291 "source_id": data["source_id"],
292 "height": data["height"],
293 "width": data["width"],
294 "num_detections": tf.shape(data["groundtruth_classes"]),
295 "image_info": image_info,
296 "boxes": utils_detection.denormalize_boxes_tf(data["groundtruth_boxes"], image_shape),
297 "classes": data["groundtruth_classes"],
298 "areas": data["groundtruth_area"],
299 "is_crowds": tf.cast(data["groundtruth_is_crowd"], tf.int32),
300 }
301 groundtruths["source_id"] = utils_detection.process_source_id(groundtruths["source_id"])
302 labels = {

Callers 1

_parserFunction · 0.85

Calls 4

whitenFunction · 0.90
resize_and_crop_imageFunction · 0.85
get_shapeMethod · 0.80
shapeMethod · 0.45

Tested by

no test coverage detected