Skip to content

bugs of integer division and subplot for one class #15

@YuCosine

Description

@YuCosine

Thanks for your work! It's really handy, saving me a lot of time when learning YOLO in keras :)

I understand this program is for python 3. I run it with python 2.7 though, and a small modification will get it work.
In File "mean_average_precision/mean_average_precision/utils/bbox.py", function jaccard returns 0 when the coordinates of bounding boxes are all integers, because python 2.7 yields an integer for integer division. Modifying line 49 from
return inter / union
to
return inter.astype('float32') / union
works well.

Second, when calculating mAP for just one class, in File "mean_average_precision/mean_average_precision/detection_map.py", function plot raises an error

Traceback (most recent call last):
  File "mean_average_precision/detection_map.py", line 229, in plot
    for i, ax in enumerate(axes.flat):
AttributeError: 'AxesSubplot' object has no attribute 'flat'

because when grid == 1, fig, axes = plt.subplots(nrows=grid, ncols=grid) return axes as type of matplotlib.axes._subplots.AxesSubplot.
I modify it from

        grid = int(math.ceil(math.sqrt(self.n_class)))
        fig, axes = plt.subplots(nrows=grid, ncols=grid)
        mean_average_precision = []
        # TODO: data structure not optimal for this operation...
        for i, ax in enumerate(axes.flat):
            if i > self.n_class - 1:
                break
            precisions, recalls = self.compute_precision_recall_(i, interpolated)
            average_precision = self.compute_ap(precisions, recalls)
            self.plot_pr(ax, i, precisions, recalls, average_precision)
            mean_average_precision.append(average_precision)

to

        grid = int(math.ceil(math.sqrt(self.n_class)))
        if grid == 1:
            fig, ax = plt.subplots()
            mean_average_precision = []
            precisions, recalls = self.compute_precision_recall_(0, interpolated)
            average_precision = self.compute_ap(precisions, recalls)
            self.plot_pr(ax, 0, precisions, recalls, average_precision)
            mean_average_precision.append(average_precision)
        else:
            fig, axes = plt.subplots(nrows=grid, ncols=grid)
            mean_average_precision = []
            # TODO: data structure not optimal for this operation...
            for i, ax in enumerate(axes.flat):
                if i > self.n_class - 1:
                    break
                precisions, recalls = self.compute_precision_recall_(i, interpolated)
                average_precision = self.compute_ap(precisions, recalls)
                self.plot_pr(ax, i, precisions, recalls, average_precision)
                mean_average_precision.append(average_precision)

to get it work, but I think it can be more precise .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions