def _draw_bboxes(): img = tf.squeeze(images[i]) bboxes = tf.gather(bbox_regs[i], indices) class_probs = tf.gather(bbox_probs[i], indices) # bboxes = tf.zeros_like(bboxes) anchors = tf.gather(all_anchors, indices) bboxes = bbox_decode( bboxes, anchors, self.model_cfg.scale_factors) # bboxes = tf.expand_dims(bboxes, axis=0) scores = tf.gather(obj_prob, indices) selected_indices = tf.image.non_max_suppression( bboxes, scores, max_output_size=10, iou_threshold=0.5) bboxes = tf.gather(bboxes, selected_indices) class_probs = tf.gather(class_probs, selected_indices) top_probs, top_classes = tf.nn.top_k(class_probs, 3) vis_fn = functools.partial( vis.visualize_bboxes_on_image, class_labels=self.labels ) out_img = tf.py_func( vis_fn, [img, bboxes, top_classes, top_probs], tf.uint8) return tf.expand_dims(out_img, axis=0)
def _get_bboxes(): boxes = tf.gather(bbox_regs[i], indices) anchors = tf.gather(self.anchors, indices) boxes = bbox_decode(boxes, anchors, self.model_cfg.scale_factors) scores_ = tf.gather(bbox_probs[i], indices) scores_ = tf.expand_dims(scores_, axis=1) boxes *= tf.constant( [self.patch_h, self.patch_w, self.patch_h, self.patch_w], dtype=tf.float32) delta = tf.constant([ patches_top[i], patches_left[i], patches_top[i], patches_left[i] ], dtype=tf.float32) boxes += delta return tf.concat([boxes, scores_], axis=1)
def _get_bboxes(): bboxes = tf.gather(bbox_regs[i], indices) class_probs = tf.gather(bbox_probs[i], indices) # bboxes = tf.zeros_like(bboxes) anchors = tf.gather(self.anchors, indices) bboxes = bbox_decode(bboxes, anchors, self.model_cfg.scale_factors) # bboxes = tf.expand_dims(bboxes, axis=0) scores = tf.gather(obj_prob, indices) selected_indices = tf.image.non_max_suppression( bboxes, scores, max_output_size=30, iou_threshold=0.4) bboxes = tf.gather(bboxes, selected_indices) scaling = tf.constant( [self.img_h, self.img_w, self.img_h, self.img_w], dtype=tf.float32) scaling = tf.expand_dims(scaling, axis=0) bboxes = bboxes * scaling class_probs = tf.gather(class_probs, selected_indices) top_probs, top_classes = tf.nn.top_k(class_probs, self.infer_cfg.top_k) return bboxes, top_probs, top_classes