def postprocess(inputs, outputs, is_training, apply_nms, nms_score_threshold, nms_iou_threshold, nms_max_num_predicted_boxes, use_furthest_voxel_sampling, num_furthest_voxel_samples, sampler_score_vs_distance_coef): """Post-processor function.""" if not is_training: # Squeeze voxel properties. for key in standard_fields.get_output_voxel_fields(): if key in outputs and outputs[key] is not None: outputs[key] = tf.squeeze(outputs[key], axis=0) for key in standard_fields.get_output_point_fields(): if key in outputs and outputs[key] is not None: outputs[key] = tf.squeeze(outputs[key], axis=0) for key in standard_fields.get_output_object_fields(): if key in outputs and outputs[key] is not None: outputs[key] = tf.squeeze(outputs[key], axis=0) # Mask the valid voxels mask_valid_voxels(inputs=inputs, outputs=outputs) # NMS postprocessor.postprocess( outputs=outputs, score_thresh=nms_score_threshold, iou_thresh=nms_iou_threshold, max_output_size=nms_max_num_predicted_boxes, use_furthest_voxel_sampling=use_furthest_voxel_sampling, num_furthest_voxel_samples=num_furthest_voxel_samples, sampler_score_vs_distance_coef=sampler_score_vs_distance_coef, apply_nms=apply_nms)
def get_batch_size_1_output_voxels(outputs, b): """Returns output dictionary containing tensors with batch size of 1. Note that this function only applies its example selection to the voxel tensors. Args: outputs: A dictionary of tf.Tensors with the network output. b: Example index in the batch. Returns: outputs_1: A dictionary of tf.Tensors with batch size of one. """ b_1_outputs = {} for field in standard_fields.get_output_voxel_fields(): if field in outputs and outputs[field] is not None: b_1_outputs[field] = outputs[field][b] return b_1_outputs
def apply_mask_to_output_voxel_tensors(outputs, valid_mask): """Applies mask to output voxel tensors.""" for field in standard_fields.get_output_voxel_fields(): if field in outputs and outputs[field] is not None: outputs[field] = tf.boolean_mask(outputs[field], valid_mask)
def postprocess(inputs, outputs, is_training, num_furthest_voxel_samples, sampler_score_vs_distance_coef, embedding_similarity_strategy, embedding_similarity_threshold, score_threshold, apply_nms, nms_iou_threshold): """Post-processor function. Args: inputs: A dictionary containing input tensors. outputs: A dictionary containing predicted tensors. is_training: If during training stage or not. num_furthest_voxel_samples: Number of voxels to be sampled using furthest voxel sampling in the postprocessor. sampler_score_vs_distance_coef: The coefficient that balances the weight between furthest voxel sampling and highest score sampling in the postprocessor. embedding_similarity_strategy: Embedding similarity strategy. embedding_similarity_threshold: Similarity threshold used to decide if two point embedding vectors belong to the same instance. score_threshold: Instance score threshold used throughout postprocessing. apply_nms: If True, it will apply non-maximum suppression to the final predictions. nms_iou_threshold: Intersection over union threshold used in non-maximum suppression. """ if not is_training: # Squeeze output voxel properties. for key in standard_fields.get_output_voxel_fields(): if key in outputs and outputs[key] is not None: outputs[key] = tf.squeeze(outputs[key], axis=0) # Squeeze output point properties. for key in standard_fields.get_output_point_fields(): if key in outputs and outputs[key] is not None: outputs[key] = tf.squeeze(outputs[key], axis=0) # Squeeze output object properties. for key in standard_fields.get_output_object_fields(): if key in outputs and outputs[key] is not None: outputs[key] = tf.squeeze(outputs[key], axis=0) # Mask the valid voxels mask_valid_voxels(inputs=inputs, outputs=outputs) # Mask the valid points mask_valid_points(inputs=inputs, outputs=outputs) # NMS postprocessor.postprocess( outputs=outputs, num_furthest_voxel_samples=num_furthest_voxel_samples, sampler_score_vs_distance_coef=sampler_score_vs_distance_coef, embedding_similarity_strategy=embedding_similarity_strategy, embedding_similarity_threshold=embedding_similarity_threshold, apply_nms=apply_nms, nms_score_threshold=score_threshold, nms_iou_threshold=nms_iou_threshold) # Add instance segment point masks at eval time if standard_fields.InputDataFields.points_to_voxel_mapping in inputs: instance_segments_point_mask = ( voxel_utils.sparse_voxel_grid_to_pointcloud( voxel_features=tf.expand_dims(tf.transpose( outputs[standard_fields.DetectionResultFields. instance_segments_voxel_mask]), axis=0), segment_ids=inputs[standard_fields.InputDataFields. points_to_voxel_mapping], num_valid_voxels=inputs[ standard_fields.InputDataFields.num_valid_voxels], num_valid_points=inputs[ standard_fields.InputDataFields.num_valid_points])) outputs[standard_fields.DetectionResultFields. instance_segments_point_mask] = tf.transpose( tf.squeeze(instance_segments_point_mask, axis=0))