Skip to content

Commit

Permalink
add object recognition fig
Browse files Browse the repository at this point in the history
  • Loading branch information
wassname committed Oct 14, 2020
1 parent 27fb846 commit 60e6c1b
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 203 deletions.
355 changes: 154 additions & 201 deletions notebooks/c08_Object_Detection/Object_Detection.ipynb

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions notebooks/c08_Object_Detection/Object_Detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
#
# A more complex problem than the classic image classification problem is the object recognition task. In an image classification we predict the category of an image, however, in object detection not only we classify multiple objects in an image but we can also predict the location of those objects.
#
# <img src="./segmentation.png" width="800"/>
#
#
# In this notebook we will discuss **Faster RCNN** model for object recognition and **Mask RCNN** for instance segmentation.
#
Expand All @@ -70,11 +72,14 @@
# Image Credits: [MTheiler](https://en.wikipedia.org/wiki/Object_detection#/media/File:Detected-with-YOLO--Schreibtisch-mit-Objekten.jpg) License: [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)
#
#
#
#
#
# # Instance Segmentation
#
# In instance segmentation we will combine object recognition and semantic segmentation.
#
# <img width=800 heigh=500 src='maskrcnn.png'>
# <img width=800 height=500 src='maskrcnn.png'>
#
# Credits: [He et al](https://arxiv.org/pdf/1703.06870.pdf)

Expand Down Expand Up @@ -402,7 +407,10 @@ def get_prediction_mask(img_path, threshold):
img = transform(Image.open(img_path))
pred = MRCNN([img])
pred_score = list(pred[0]["scores"].detach().numpy())
pred_t = [pred_score.index(x) for x in pred_score if x > threshold][-1]
pred_ts = [pred_score.index(x) for x in pred_score if x > threshold]
if len(pred_ts)==0:
return [], [], []
pred_t = pred_ts[-1]
masks = (pred[0]["masks"] > 0.5).squeeze().detach().cpu().numpy()
pred_class = [
COCO_INSTANCE_CATEGORY_NAMES[i] for i in list(pred[0]["labels"].numpy())
Expand Down
Binary file added notebooks/c08_Object_Detection/segmentation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 60e6c1b

Please sign in to comment.