Wunda Coursera Deep Learning course deeplearning.ai programming work--autonomous driving-car (4.3)

Source: Internet
Author: User
Tags coursera deep learning keras
Autonomous Driving-car Detection

Welcome to your Week 3 programming assignment. You'll learn about object detection using the very powerful YOLO model. Many of the "ideas in" notebook are described in the two YOLO et al., Papers:redmon (2016 2640) and RedMon and Farhadi, 2016 (https://arxiv.org/abs/1612.08242).

You'll learnto:
-use object detection on a car detection dataset
-Deal with bounding boxes

Run the following cell to load the packages and dependencies this are going to is useful for your journey!

Import argparse
import os
import keras
import Matplotlib.pyplot as plt from
matplotlib.pyplot Import Imshow
Import scipy.io
import scipy.misc
import numpy as NP
import pandas as PD
import PiL
Import TensorFlow as TF from
ipython.display import SVG from
keras.utils.vis_utils import Model_to_dot
From Keras import backend as K.
keras.layers Import Input, Lambda, conv2d from
keras.models import Load_mode L, Model from
yolo_utils import read_classes, read_anchors, Generate_colors, Preprocess_image, Draw_boxes, Scale_ Boxes from
Yad2k.models.keras_yolo import Yolo_head, Yolo_boxes_to_corners, Preprocess_true_boxes, Yolo_loss, Yolo_body

%matplotlib Inline

ImportantNote: As you can, we import Keras ' s backend as K. This means the to use a Keras function in this notebook, you'll need to write:k.function (...). 1-problem Statement

You are are working on a self-driving car. As a critical component of this project, your ' d like to-a car detection system. To collect data, "ve mounted a camera to" hood (meaning the front) of the car, which takes pictures of the road Ahea D Every few seconds while you drive around.

You ' ve gathered all of images into a folder and have labelled them to drawing bounding boxes around every car you found . Here's an example of the what your bounding boxes look like.

If you are have classes that your want YOLO to recognize, you can represent the class label C c either as a integer from 1 To, or as a 80-dimensional vector (with numbers) one component of which is 1 and the rest of which are 0. The video lectures had used the latter representation; In this notebook, we'll use the both representations, depending on which are more convenient to a particular step.

In this exercise, you'll learn how YOLO works and then apply it to the car detection. Because the YOLO model is very computationally expensive to train, we'll load pre-trained weights for your use. 2-yolo

YOLO ("A look Once") are a popular algoritm because it achieves high accuracy while also being able to run in Real-t Ime. This algorithm ' only looks once ' at the ' image in ' sense that it requires only one forward propagation pass through the Network to make predictions. After Non-max suppression, it then outputs recognized objects together with the bounding. 2.1-model Details

The things to know:
-The input is a batch of images of shape (m, 608, 608, 3)
-The output is a list of bounding boxes along with the recognized classes. Each bounding box was represented by 6 numbers (Pc,bx,by,bh,bw,c) (P_c, b_x, b_y, B_h, B_w, c) as explained above. If you have expand C c into a 80-dimensional vector, each bounding box was then represented by numbers.

We'll use 5 anchor boxes. So you can have the YOLO architecture as the Following:image (M, 608, 608, 3)-> DEEP CNN-> ENCODING (M, 19, 1 9, 5, 85).

Lets look in greater detail to what this encoding represents.

If the Center/midpoint of an object falls into a grid cell, that grid cell is responsible to detecting that object.

Since we are using 5 anchor boxes, each of the x19 cells thus encodes information about 5 boxes. Anchor boxes are defined by their width and height.

For simplicity, we'll flatten the last two last dimensions of the shape (5,) encoding. So the output of the Deep CNN is (19, 19, 425).

Figure 3 : flattening The last two last dimensions

Now, for each box (in each cell) we'll compute the following elementwise product and extract a probability that box Contains a certain class.

Here's one way to visualize what YOLO are predicting on a image:
-For each of the 19x19 grid cells, find the maximum of the probability scores (taking a max across both the 5 anchor Boxe s and across different classes).
-Color that grid cell according to what object, grid cell considers the most likely.

Doing this results the picture:

Figure 5 : Each of the 19x19 grid cells colored according-which class has the largest predicted probability in That cell.

This is the visualization isn ' t a core part of the YOLO algorithm itself for making predictions; It ' s just a nice way of visualizing of the algorithm.
Another way to visualize YOLO ' s output are to plot the bounding boxes the IT outputs. Doing that results in a visualization like this:


Figure 6 : Each cell gives for you 5 boxes. In total, the model predicts:19x19x5 = 1805 boxes just by looking once at the image (one forward pass through the network )! Different colors denote different classes.

In the figure above, we are plotted only boxes the model had assigned a high probability to, but this is still too many B Oxes. You ' d like to filter the algorithm's output down to a much smaller number of detected objects. To did so, you'll use Non-max suppression. Specifically, you'll carry out these steps:
-Get rid of boxes with a low score (meaning, the box are not very confident about detecting a class)
-Select only one box when several boxes overlap and detect the same object. 2.2-filtering with a threshold on class scores

You are are going to apply a-a-thresholding. You are like would the ' get rid ' of any box for which the class ' score ' is less than a chosen threshold.

The model gives you are a total of 19x19x5x85 numbers and with each box described by numbers. It ' ll be convenient to rearrange the (19,19,5,85) (or (19,19,425) dimensional tensor into the following variables:
-Box_confidence:tensor of Shape (19x19,5,1) (\times, 5, 1) containing PC P_c (confidence probability that there ' s Some object) for each of the 5 boxes predicted in the 19x19 cells.
-Boxes:tensor of Shape (19x19,5,4) (\times, 5, 4) containing (BX,BY,BH,BW) (b_x, b_y, B_h, B_w) for each of the 5 Boxes per cell.
-Box_class_probs:tensor of Shape (19x19,5,80) (\times, 5) containing the detection probabilities (C1,C2,... C80 (C_1, c_2, ... c_{80}) for each of the "classes for each of the" 5 boxes per cell.

Exercise: Implement Yolo_filter_boxes ().
1. Compute box scores by doing the Elementwise product as described in Figure 4. The following code may help your choose the right operator:

A = Np.random.randn (19*19, 5, 1)
B = Np.random.randn (19*19, 5,)
C = A * b # shape of C would be (19*19, 5, 80)
For each box, find:
The index of the class with the Maximum box score (Hint) (is careful with what axis you choose; consider using axis=-1) th e corresponding box score (Hint

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.