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

Bug in ssd_batch_generator module, parse_csv function #27

Closed
JeremyBYU opened this issue Dec 8, 2017 · 2 comments
Closed

Bug in ssd_batch_generator module, parse_csv function #27

JeremyBYU opened this issue Dec 8, 2017 · 2 comments
Labels

Comments

@JeremyBYU
Copy link

Hey I think I found a bug in ssd_batch_geneartor.parse_csv. The issue comes from an example file as so:

fname, xmin, xmax, ymin,ymax,class_id
a.jpg,1,2,3,4,1,
b.jpg,1,2,3,4,1,
c.jpg,1,2,3,4,1

The last c.jpg will not be added to filenames and labels. It is skipped.

Notice that the last row is a new file (important because your logic looks at this condition).

The error appears here.

                else: # If this box belongs to a new image file
                    self.labels.append(np.stack(current_labels, axis=0)) # appending the PREVIOUS labels
                    self.filenames.append(os.path.join(self.images_path, current_file)) # appending the PREVIOUS filenames
                    current_labels = []
                    current_file = i[0] # This will never be added, we are on the last line/iteration of loop
                    current_labels.append(i[1:]) # This will never be added, we are on the last line/iteration of loop

Proposal to fix (which I'm using and worked okay:

                else: # If this box belongs to a new image file
                    self.labels.append(np.stack(current_labels, axis=0))
                    self.filenames.append(os.path.join(self.images_path, current_file))
                    current_labels = []
                    current_file = i[0]
                    current_labels.append(i[1:])
                    if idx == len(data)-1: # If this is the last line of the CSV file
                        self.labels.append(np.stack(current_labels, axis=0))
                        self.filenames.append(os.path.join(self.images_path, current_file))

Hope it helps!

@pierluigiferrari
Copy link
Owner

pierluigiferrari commented Dec 10, 2017

You're right, thank you for catching that, and thanks for the precise description.

It might be worthwhile mentioning that this bug only occurred if the last image of the dataset contains only one box.

Fixed now, and while I was at it I did a tiny bit of refactoring of parse_csv(), too. Two if-statements in there were unnecessary, and i is a terrible name for anything that is not an index.

@JeremyBYU
Copy link
Author

Great! Closing because acknowledged and fixed.

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

No branches or pull requests

2 participants