def make_anchors(self, feature_pyramid, use_tf=False):
     with tf.variable_scope('make_anchors'):
         anchor = GenerateAnchors(self.cfgs, self.method)
         if use_tf and self.method == 'H':
             anchor_list = anchor.generate_all_anchor_tf(feature_pyramid)
         else:
             anchor_list = anchor.generate_all_anchor(feature_pyramid)
     return anchor_list
 def make_anchors(self, feature_pyramid):
     with tf.variable_scope('make_anchors'):
         anchor = GenerateAnchors(self.cfgs, self.anchor_mode)
         anchor_list = anchor.generate_all_anchor(feature_pyramid)
     return anchor_list
Beispiel #3
0
    def test_pb(self, frozen_graph_path, test_dir):

        graph = self.load_graph(frozen_graph_path)
        print("we are testing ====>>>>", frozen_graph_path)

        img = graph.get_tensor_by_name("input_img:0")
        dets = graph.get_tensor_by_name("DetResults:0")

        with tf.Session(graph=graph) as sess:
            for img_path in os.listdir(test_dir):
                print(img_path)
                a_img = cv2.imread(os.path.join(test_dir,
                                                img_path))[:, :, ::-1]

                raw_h, raw_w = a_img.shape[0], a_img.shape[1]

                short_size, max_len = self.cfgs.IMG_SHORT_SIDE_LEN, cfgs.IMG_MAX_LENGTH
                if raw_h < raw_w:
                    new_h, new_w = short_size, min(
                        int(short_size * float(raw_w) / raw_h), max_len)
                else:
                    new_h, new_w = min(int(short_size * float(raw_h) / raw_w),
                                       max_len), short_size
                img_resize = cv2.resize(a_img, (new_w, new_h))
                dets_val = sess.run(dets,
                                    feed_dict={img: img_resize[:, :, ::-1]})

                bbox_pred, cls_prob = dets_val[:, :5], dets_val[:, 5:(
                    5 + self.cfgs.CLASS_NUM)]
                anchor = GenerateAnchors(self.cfgs, 'H')

                h1, w1 = math.ceil(new_h / 2), math.ceil(new_w / 2)
                h2, w2 = math.ceil(h1 / 2), math.ceil(w1 / 2)
                h3, w3 = math.ceil(h2 / 2), math.ceil(w2 / 2)
                h4, w4 = math.ceil(h3 / 2), math.ceil(w3 / 2)
                h5, w5 = math.ceil(h4 / 2), math.ceil(w4 / 2)
                h6, w6 = math.ceil(h5 / 2), math.ceil(w5 / 2)
                h7, w7 = math.ceil(h6 / 2), math.ceil(w6 / 2)

                h_dict = {'P3': h3, 'P4': h4, 'P5': h5, 'P6': h6, 'P7': h7}
                w_dict = {'P3': w3, 'P4': w4, 'P5': w5, 'P6': w6, 'P7': w7}
                anchors = anchor.generate_all_anchor_pb(h_dict, w_dict)
                anchors = np.concatenate(anchors, axis=0)

                x_c = (anchors[:, 2] + anchors[:, 0]) / 2
                y_c = (anchors[:, 3] + anchors[:, 1]) / 2
                h = anchors[:, 2] - anchors[:, 0] + 1
                w = anchors[:, 3] - anchors[:, 1] + 1
                theta = -90 * np.ones_like(x_c)
                anchors = np.transpose(np.stack([x_c, y_c, w, h, theta]))

                detected_boxes, detected_scores, detected_categories = self.postprocess_detctions(
                    bbox_pred, cls_prob, anchors)

                if True:
                    # detected_indices = det_scores_r_ >= self.cfgs.VIS_SCORE
                    # detected_scores = det_scores_r_[detected_indices]
                    # detected_boxes = det_boxes_r_[detected_indices]
                    # detected_categories = det_category_r_[detected_indices]

                    drawer = DrawBox(self.cfgs)

                    det_detections_r = drawer.draw_boxes_with_label_and_scores(
                        img_resize[:, :, ::-1],
                        boxes=detected_boxes,
                        labels=detected_categories,
                        scores=detected_scores,
                        method=1,
                        in_graph=True)

                    save_dir = os.path.join('test_pb', self.cfgs.VERSION,
                                            'pb_img_vis')
                    tools.makedirs(save_dir)

                    cv2.imwrite(save_dir + '/{}'.format(img_path),
                                det_detections_r[:, :, ::-1])