larroy commented on a change in pull request #9784: Fix for the case where 
there are no detections
URL: https://github.com/apache/incubator-mxnet/pull/9784#discussion_r169284102
 
 

 ##########
 File path: example/ssd/detect/detector.py
 ##########
 @@ -136,31 +132,52 @@ class names
         height = img.shape[0]
         width = img.shape[1]
         colors = dict()
-        for i in range(dets.shape[0]):
-            cls_id = int(dets[i, 0])
-            if cls_id >= 0:
-                score = dets[i, 1]
-                if score > thresh:
-                    if cls_id not in colors:
-                        colors[cls_id] = (random.random(), random.random(), 
random.random())
-                    xmin = int(dets[i, 2] * width)
-                    ymin = int(dets[i, 3] * height)
-                    xmax = int(dets[i, 4] * width)
-                    ymax = int(dets[i, 5] * height)
-                    rect = plt.Rectangle((xmin, ymin), xmax - xmin,
-                                         ymax - ymin, fill=False,
-                                         edgecolor=colors[cls_id],
-                                         linewidth=3.5)
-                    plt.gca().add_patch(rect)
-                    class_name = str(cls_id)
-                    if classes and len(classes) > cls_id:
-                        class_name = classes[cls_id]
-                    plt.gca().text(xmin, ymin - 2,
-                                    '{:s} {:.3f}'.format(class_name, score),
-                                    bbox=dict(facecolor=colors[cls_id], 
alpha=0.5),
+        for det in dets:
+            (klass, score, x0, y0, x1, y1) = det
+            if score < thresh:
+                continue
+            cls_id = int(klass)
+            if cls_id not in colors:
+                colors[cls_id] = (random.random(), random.random(), 
random.random())
+            xmin = int(x0 * width)
+            ymin = int(y0 * height)
+            xmax = int(x1 * width)
+            ymax = int(y1 * height)
+            rect = plt.Rectangle((xmin, ymin), xmax - xmin,
+                                 ymax - ymin, fill=False,
+                                 edgecolor=colors[cls_id],
+                                 linewidth=3.5)
+            plt.gca().add_patch(rect)
+            class_name = str(cls_id)
+            if classes and len(classes) > cls_id:
+                class_name = classes[cls_id]
+            plt.gca().text(xmin, ymin - 2,
+                            '{:s} {:.3f}'.format(class_name, score),
+                            bbox=dict(facecolor=colors[cls_id], alpha=0.5),
                                     fontsize=12, color='white')
         plt.show()
 
+    @staticmethod
+    def filter_positive_detections(detections):
+        """
+        First column (class id) is -1 for negative detections
+        :param detections:
+        :return:
+        """
+        class_idx = 0
+        assert(isinstance(detections, mx.nd.NDArray) or isinstance(detections, 
np.ndarray))
+        detections_per_image = []
+        # for each image
+        for i in range(detections.shape[0]):
+            result = []
+            det = detections[i, :, :]
+            for obj in det:
+                if obj[class_idx] >= 0:
 
 Review comment:
   filter_positive_detections doesn't need any member data, it's a pure 
function, reflected by @staticmethod  so one knows that is not going to mutate 
class state. Anyway, maybe is my pedantic defensive programming from other 
safer programming languages, in Python seems everyone codes however they want.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to