Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while inferencing #17

Open
QuickLearner171998 opened this issue Apr 22, 2020 · 11 comments
Open

Error while inferencing #17

QuickLearner171998 opened this issue Apr 22, 2020 · 11 comments

Comments

@QuickLearner171998
Copy link

QuickLearner171998 commented Apr 22, 2020

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

# for id in range(polys.shape[0]):

Any idea why this is happening?

@Wovchena
Copy link
Owner

This happens because nothing is detected.

@QuickLearner171998
Copy link
Author

I modified this

def __getitem__(self, idx):

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
Copy link
Owner

Looks correct

@QuickLearner171998
Copy link
Author

QuickLearner171998 commented Apr 22, 2020

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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

@Wovchena
Copy link
Owner

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

@QuickLearner171998
Copy link
Author

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

@Wovchena
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants