Wovchena / text-detection-fots.pytorch

FOTS text detection branch reimplementation, hmean: 83.3%
79 stars 21 forks source link

Error while inferencing #17

Open QuickLearner171998 opened 4 years ago

QuickLearner171998 commented 4 years ago

I am facing this issue -

Test:   0%|                                             | 0/500 [00:00<?, ?it/s]Traceback (most recent call last):
  File "test.py", line 90, in <module>
    test(net, args.images_folder, args.output_folder, args.height_size)
  File "test.py", line 65, in test
    cv2.polylines(image, numpy_reshaped_pred_polys.round().astype(int), True, (255, 0, 0))
UnboundLocalError: local variable 'numpy_reshaped_pred_polys' referenced before assignment
Test:   0%|                                | 0/500 [00:00<?, ?it/s, img_105.jpg]

I tried to debug and found polys.shape[0] is 0 I have uncommented the code for visualization

https://github.com/Wovchena/text-detection-fots.pytorch/blob/04b969c87491630dce38cdb48932aa33115798c6/test.py#L43

Any idea why this is happening?

Wovchena commented 4 years ago

This happens because nothing is detected.

QuickLearner171998 commented 4 years ago

I modified this https://github.com/Wovchena/text-detection-fots.pytorch/blob/04b969c87491630dce38cdb48932aa33115798c6/datasets.py#L159

to

        img = cv2.imread(os.path.join(os.path.join(self.root, self.img_dir), self.image_prefix[idx] + '.jpg'), cv2.IMREAD_COLOR).astype(np.float32)
        quads = []
        texts = []
        # lines = [line.rstrip('\n') for line in open(os.path.join(os.path.join(self.root, self.labels_dir), 'gt_' + self.image_prefix[idx] + '.txt'),
        #                                             encoding='utf-8-sig')]
        p = os.path.join(os.path.join(self.root, self.labels_dir), 'gt_' + self.image_prefix[idx] + '.txt')

        with open(p, 'r') as f:
            reader = csv.reader(f)
            for line in reader:
                label = line[-1]
                line = [i.strip('\ufeff').strip('\xef\xbb\xbf') for i in line]
                numbers = np.array(list(map(float, line[:8])))
                quads.append(numbers.reshape((4, 2)))
                texts.append('###' != label)
        return transform(img, np.stack(quads), texts, self.normalizer, self)

Is it incorrect or I should train for more number of epochs

Wovchena commented 4 years ago

Looks correct

QuickLearner171998 commented 4 years ago

Hey there might be an error in the way I have created annotations. Suppose I have set of polygons points- [(x1,y1)...] so this is how I create the ICDAR format annotations.

   rect = cv2.minAreaRect(np.array(polygon_points,dtype=np.int32))
   box = np.int0(cv2.boxPoints(rect)).tolist()
   line = [point for points in box for point in points]

The only thing I want to know is - Is this order of selecting points correct. I tried to check this from ICDAR website but only found points are in clockwise order. Can you help please?

Wovchena commented 4 years ago

This boils down to whether Polygon from shapely.geometry can process different order of points. It defensively can't when the order is [0, 2, 1, 3] and it is handled by except shapely.errors.TopologicalError, but I don't know about counter clockwise order.

QuickLearner171998 commented 4 years ago

So I ran the test.py and saw the visualizations of gt are correctly drawn. So this guarantees that the annotations are correct, right?

Wovchena commented 4 years ago

It only guarantees that annotations are correct from visualizer's point of view. But since transform() is a different function you cant say that it treats annotations in the exactly same way.

QuickLearner171998 commented 4 years ago

Ohh...so which is the correct order of points to be followed?

Wovchena commented 4 years ago

Well, if you say ICDAR is in clockwise order, than clockwise order is correct order because the net works for ICDAR.

QuickLearner171998 commented 4 years ago

Actually I meant which point should come first for eg..upper-left, lower-left, etc

Wovchena commented 4 years ago

I think it doesn't meter: the points go through minAreaRect() which returns points in consistent order. Polygon also shouldn't care.