コード例 #1
0
    def predict(self, input_path, output_path):
        K.set_learning_phase(0)

        image = cv2.imread(input_path)
        resized_image = cv2.resize(image, (self.IMAGE_H, self.IMAGE_W))
        resized_image = self.normalize_input(resized_image)
        input_image = resized_image.reshape((1, self.IMAGE_H, self.IMAGE_W, 3))
        dummy_array = np.zeros((1,1,1,1,self.MAX_BOX_PER_IMAGE,4))

        netout = self.model.predict([input_image, dummy_array])[0]
        boxes  = decode_netout(netout, self.OBJ_THRESHOLD, self.NMS_THRESHOLD, self.ANCHORS, len(self.LABELS))
        image = draw_boxes(image, boxes, self.LABELS)

        print len(boxes), 'Bounding Boxes Found'
        print "File Saved to", output_path
        cv2.imwrite(output_path, image)
コード例 #2
0
    def predict(self, input_paths, output_paths):
        assert len(input_paths) == self.SEQUENCE_LENGTH

        x = np.zeros((1, self.SEQUENCE_LENGTH, self.IMAGE_H, self.IMAGE_W, 3))
        b = np.zeros(
            (1, self.SEQUENCE_LENGTH, 1, 1, 1, 1, self.MAX_BOX_PER_IMAGE, 4))
        for i, input_path in enumerate(input_paths):
            image = cv2.imread(image_path)
            resized_image = cv2.resize(image, (self.IMAGE_H, self.IMAGE_W))
            resized_image = normalize(resized_image)
            x[0, i] = resized_image.reshape((1, self.IMAGE_H, self.IMAGE_W, 3))
            b[0, i] = np.zeros((1, 1, 1, 1, self.MAX_BOX_PER_IMAGE, 4))

        netouts = self.model.predict([x, b])[0]

        for i, netout in enumerate(netouts):
            boxes = decode_netout(netout, self.OBJ_THRESHOLD,
                                  self.NMS_THRESHOLD, self.ANCHORS,
                                  len(self.LABELS))
            image = draw_boxes(image, boxes, self.LABELS)

            print len(boxes), 'Bounding Boxes Found'
            print "File Saved to", output_paths[i]
            cv2.imwrite(output_paths[i], image)