• No results found

Lecture 11: Detection and Segmentation

N/A
N/A
Protected

Academic year: 2021

Share "Lecture 11: Detection and Segmentation"

Copied!
104
0
0

Loading.... (view fulltext now)

Full text

(1)

Lecture 11:

Detection and Segmentation

(2)

Administrative

1. Midterms being graded

- Please don’t discuss midterms until next week - some students not yet taken

2. A2 being graded

3. Project milestones due Wed 5/16

(3)

Last Time: Recurrent Networks

(4)

Last Time: Recurrent Networks

(5)

Figure from Karpathy et a, “Deep Visual-Semantic Alignments for Generating Image Descriptions”, CVPR 2015; figure copyright IEEE, 2015.

Reproduced for educational purposes.

Last Time: Recurrent Networks

A cat sitting on a suitcase on the floor

A cat is sitting on a tree branch

A woman is holding

a cat in her hand

(6)

Class Scores Cat: 0.9

Dog: 0.05 Car: 0.01 ...

So far: Image Classification

This image is CC0 public domain

Vector:

4096

Fully-Connected:

4096 to 1000

(7)

Today: Detection, Segmentation

(8)

Other Computer Vision Tasks

Classification + Localization Semantic

Segmentation

Object Detection

Instance

Segmentation

(9)

Other Computer Vision Tasks

Semantic Segmentation

2D Object Detection

DOG, DOG, CAT GRASS, CAT,

TREE, SKY

3D Object Detection

Car

(10)

Semantic Segmentation

Semantic Segmentation

2D Object Detection

DOG, DOG, CAT GRASS, CAT,

3D Object Detection

Car

(11)

Semantic Segmentation

Cow Trees Sky

Label each pixel in the image with a category label

Don’t differentiate

instances, only care about pixels

This image is CC0 public domain

Cat

Sky Trees

(12)

Semantic Segmentation Idea: Sliding Window

Full image

Extract patch Classify center pixel with CNN

Cow Cow

Grass

(13)

Semantic Segmentation Idea: Sliding Window

Full image

Extract patch Classify center pixel with CNN

Cow Cow

Grass

(14)

Semantic Segmentation Idea: Fully Convolutional

Input:

3 x H x W

Conv Conv Conv Conv

Scores:

argmax

Predictions:

Design a network as a bunch of convolutional layers

to make predictions for pixels all at once!

(15)

Semantic Segmentation Idea: Fully Convolutional

Input:

3 x H x W

Conv Conv Conv Conv

Scores:

C x H x W

argmax

Predictions:

H x W Design a network as a bunch of convolutional layers

to make predictions for pixels all at once!

(16)

Semantic Segmentation Idea: Fully Convolutional

Input:

3 x H x W Predictions:

Design network as a bunch of convolutional layers, with downsampling and upsampling inside the network!

High-res:

D x H/2 x W/2

High-res:

D x H/2 x W/2 Med-res:

D

2

x H/4 x W/4

Med-res:

D

2

x H/4 x W/4

Low-res:

D

3

x H/4 x W/4

(17)

Semantic Segmentation Idea: Fully Convolutional

Input:

3 x H x W Predictions:

H x W Design network as a bunch of convolutional layers, with

downsampling and upsampling inside the network!

High-res:

D

1

x H/2 x W/2

High-res:

D

1

x H/2 x W/2 Med-res:

D

2

x H/4 x W/4

Med-res:

D

2

x H/4 x W/4

Low-res:

D

3

x H/4 x W/4 Downsampling:

Pooling, strided convolution

Upsampling:

???

(18)

In-Network upsampling: “Unpooling”

1 2

3 4

Input: 2 x 2 Output: 4 x 4

1 1 2 2

1 1 2 2

3 3 4 4

3 3 4 4

Nearest Neighbor

1 2

3 4

Input: 2 x 2 Output: 4 x 4

1 0 2 0

0 0 0 0

3 0 4 0

0 0 0 0

“Bed of Nails”

(19)

In-Network upsampling: “Max Unpooling”

Input: 4 x 4

1 2 6 3

3 5 2 1

1 2 2 1

7 3 4 8

1 2

3 4

Input: 2 x 2 Output: 4 x 4

0 0 2 0

0 1 0 0

0 0 0 0

3 0 0 4

Max Unpooling Use positions from pooling layer

5 6

7 8

Max Pooling

Remember which element was max!

Rest of the network

Output: 2 x 2

(20)

Learnable Upsampling: Transpose Convolution

Recall:Typical 3 x 3 convolution, stride 1 pad 1

(21)

Recall: Normal 3 x 3 convolution, stride 1 pad 1

Input: 4 x 4 Output: 4 x 4

Dot product between filter and input

Learnable Upsampling: Transpose Convolution

(22)

Dot product between filter and input

Recall: Normal 3 x 3 convolution, stride 1 pad 1

Learnable Upsampling: Transpose Convolution

(23)

Input: 4 x 4 Output: 2 x 2

Recall: Normal 3 x 3 convolution, stride 2 pad 1

Learnable Upsampling: Transpose Convolution

(24)

Dot product between filter and input

Recall: Normal 3 x 3 convolution, stride 2 pad 1

Learnable Upsampling: Transpose Convolution

(25)

Input: 4 x 4 Output: 2 x 2 Dot product

between filter and input

Filter moves 2 pixels in the input for every one pixel in the output

Stride gives ratio between movement in input and output

Recall: Normal 3 x 3 convolution, stride 2 pad 1

Learnable Upsampling: Transpose Convolution

(26)

3 x 3 transpose convolution, stride 2 pad 1

Learnable Upsampling: Transpose Convolution

(27)

Input: 2 x 2 Output: 4 x 4 Input gives

weight for filter

3 x 3 transpose convolution, stride 2 pad 1

Learnable Upsampling: Transpose Convolution

(28)

Input gives weight for filter

Sum where output overlaps

3 x 3 transpose convolution, stride 2 pad 1

Filter moves 2 pixels in the output for every one pixel in the input

Stride gives ratio between movement in output and input

Learnable Upsampling: Transpose Convolution

(29)

Input: 2 x 2 Output: 4 x 4 Input gives

weight for filter

Sum where output overlaps

3 x 3 transpose convolution, stride 2 pad 1

Filter moves 2 pixels in the output for every one pixel in the input

Stride gives ratio between movement in output and input

Learnable Upsampling: Transpose Convolution

(30)

Input gives weight for filter

Sum where output overlaps

3 x 3 transpose convolution, stride 2 pad 1

Filter moves 2 pixels in the output for every one pixel in the input

Stride gives ratio between movement in output and input

Other names:

-Deconvolution (bad) -Upconvolution

-Fractionally strided convolution

-Backward strided convolution

Learnable Upsampling: Transpose Convolution

(31)

Learnable Upsampling: 1D Example

a b

x y z

ax ay

az + bx by

Input Filter

Output

Output contains copies of the filter weighted by the input, summing at where at overlaps in the output

Need to crop one

pixel from output to

make output exactly

2x input

(32)

Convolution as Matrix Multiplication (1D Example)

We can express convolution in

terms of a matrix multiplication

(33)

Convolution as Matrix Multiplication (1D Example)

We can express convolution in terms of a matrix multiplication

Convolution transpose multiplies by the

transpose of the same matrix:

(34)

Convolution as Matrix Multiplication (1D Example)

We can express convolution in

terms of a matrix multiplication

(35)

Convolution as Matrix Multiplication (1D Example)

We can express convolution in terms of a matrix multiplication

Convolution transpose multiplies by the

transpose of the same matrix:

(36)

Semantic Segmentation Idea: Fully Convolutional

Input:

3 x H x W Predictions:

Design network as a bunch of convolutional layers, with downsampling and upsampling inside the network!

High-res:

D x H/2 x W/2

High-res:

D x H/2 x W/2 Med-res:

D

2

x H/4 x W/4

Med-res:

D

2

x H/4 x W/4

Low-res:

D

3

x H/4 x W/4 Downsampling:

Pooling, strided convolution

Upsampling:

Unpooling or strided

transpose convolution

(37)

Aside: Multi-view 3D Reconstruction

(38)

Aside: Multi-view 3D Reconstruction

(39)

Aside: Multi-view 3D Reconstruction

(40)

2D Object Detection

Semantic Segmentation

2D Object Detection

GRASS, CAT, DOG, DOG, CAT

3D Object Detection

Car

(41)

Class Scores Cat: 0.9

Dog: 0.05 Car: 0.01 ...

Classification + Localization

This image is CC0 public domain

Vector:

4096 Fully

Connected:

4096 to 1000

Box

Coordinates (x, y, w, h) Fully

Connected:

4096 to 4

(42)

Class Scores Cat: 0.9

Dog: 0.05 Car: 0.01 ...

Classification + Localization

Vector:

4096 Fully

Connected:

4096 to 1000

Box

Coordinates Fully

Connected:

4096 to 4

Softmax Loss

Correct label:

Cat

This image is CC0 public domain

(43)

Class Scores Cat: 0.9

Dog: 0.05 Car: 0.01 ...

Classification + Localization

Vector:

4096 Fully

Connected:

4096 to 1000

Box

Coordinates (x, y, w, h) Fully

Connected:

4096 to 4

Softmax Loss

L2 Loss

Loss Correct label:

Cat

+

This image is CC0 public domain

Multitask Loss

(44)

Class Scores Cat: 0.9

Dog: 0.05 Car: 0.01 ...

Classification + Localization

Vector:

4096 Fully

Connected:

4096 to 1000

Box

Coordinates Fully

Connected:

4096 to 4

Softmax Loss

Loss Correct label:

Cat

+

This image is CC0 public domain

Often pretrained on ImageNet

(Transfer learning)

(45)

Object Detection as Regression?

CAT: (x, y, w, h)

DOG: (x, y, w, h) DOG: (x, y, w, h) CAT: (x, y, w, h)

DUCK: (x, y, w, h)

(46)

Object Detection as Regression?

CAT: (x, y, w, h)

DOG: (x, y, w, h) DOG: (x, y, w, h) CAT: (x, y, w, h)

4 numbers

16 numbers Each image needs a

different number of outputs!

(47)

Object Detection as Classification: Sliding Window

Dog? NO Cat? NO

Background? YES

Apply a CNN to many different crops of the

image, CNN classifies each crop as object

or background

(48)

Object Detection as Classification: Sliding Window

Dog? YES Cat? NO

Background? NO

Apply a CNN to many different crops of the

image, CNN classifies each crop as object

or background

(49)

Object Detection as Classification: Sliding Window

Dog? YES Cat? NO

Background? NO

Apply a CNN to many different crops of the

image, CNN classifies each crop as object

or background

(50)

Object Detection as Classification: Sliding Window

Dog? NO Cat? YES

Background? NO

Apply a CNN to many different crops of the

image, CNN classifies each crop as object

or background

(51)

Object Detection as Classification: Sliding Window

Dog? NO Cat? YES

Background? NO

Apply a CNN to many different crops of the image, CNN classifies each crop as object or background

Problem: Need to apply CNN to huge

(52)

Region Proposals / Selective Search

● Find “blobby” image regions that are likely to contain objects

● Relatively fast to run; e.g. Selective Search gives 2000 region

proposals in a few seconds on CPU

(53)

R-CNN

(54)

R-CNN

(55)

R-CNN

(56)

R-CNN

(57)

R-CNN

(58)

R-CNN

(59)

R-CNN: Problems

• Ad hoc training objectives

• Fine-tune network with softmax classifier (log loss)

• Train post-hoc linear SVMs (hinge loss)

• Train post-hoc bounding-box regressions (least squares)

• Training is slow (84h), takes a lot of disk space

• Inference (detection) is slow

• 47s / image with VGG16 [Simonyan & Zisserman. ICLR15]

• Fixed by SPP-net [He et al. ECCV14]

(60)

Fast R-CNN

(61)

Fast R-CNN

(62)

Fast R-CNN

(63)

Fast R-CNN

(64)

Fast R-CNN: RoI Pooling

Hi-res input image:

3 x 640 x 480 with region

Hi-res conv features:

512 x 20 x 15;

Fully-connected layers

Divide projected proposal into 7x7 grid, max-pool within each cell

RoI conv features:

512 x 7 x 7 for region proposal

Fully-connected layers expect low-res conv features:

CNN

Project proposal

onto features

(65)

Fast R-CNN

(66)

Fast R-CNN

(67)

Fast R-CNN

(Training)

(68)

Fast R-CNN

(Training)

(69)

R-CNN vs SPP vs Fast R-CNN

(70)

R-CNN vs SPP vs Fast R-CNN

Problem:

Runtime dominated

(71)

Faster R-CNN:

Make CNN do proposals!

Insert Region Proposal Network (RPN) to predict proposals from features Jointly train with 4 losses:

1. RPN classify object / not object 2. RPN regress box coordinates 3. Final classification score (object

classes)

4. Final box coordinates

(72)

Faster R-CNN:

Make CNN do proposals!

(73)

Mask R-CNN

RoI Align Conv

Classification Scores: C

Box coordinates (per class): 4 * C

CNN Conv

Predict a mask for

each of C classes

256 x 14 x 14 256 x 14 x 14

(74)

Mask R-CNN: Very Good Results!

(75)

Mask R-CNN

Also does pose

(76)

Detection without Proposals: YOLO / SSD

Divide image into grid Input image

Within each grid cell:

- Regress from each of the B base boxes to a final box with 5 numbers:

(dx, dy, dh, dw, confidence) - Predict scores for each of C

classes (including background as a class)

Output:

(77)

Detection without Proposals: YOLO / SSD

Divide image into grid 7 x 7

Input image 3 x H x W

Within each grid cell:

- Regress from each of the B base boxes to a final box with 5 numbers:

(dx, dy, dh, dw, confidence) - Predict scores for each of C

classes (including background as a class)

Output:

7 x 7 x (5 * B + C)

Go from input image to tensor of scores with one big convolutional network!

(78)

Object Detection: Lots of variables ...

Base Network VGG16

ResNet-101 Inception V2 Inception V3 Inception ResNet MobileNet

Object Detection architecture

Faster R-CNN R-FCN

SSD

Image Size

# Region Proposals

Takeaways

Faster R-CNN is slower but more accurate

SSD is much

faster but not as

accurate

(79)

Object Detection: Impact of Deep Learning

(80)

Open Source Frameworks

Lots of good implementations on GitHub!

TensorFlow Detection API:

https://github.com/tensorflow/models/tree/master/research/object_detection Faster RCNN, SSD, RFCN, Mask R-CNN

Caffe2 Detectron:

https://github.com/facebookresearch/Detectron

Mask R-CNN, RetinaNet, Faster R-CNN, RPN, Fast R-CNN, R-FCN

(81)

Aside: Object Detection + Captioning

= Dense Captioning

(82)

Aside: Object Detection + Captioning

= Dense Captioning

(83)
(84)

Aside: VisualGenome

(85)

Aside: Scene Graph Generation

(86)

3D Object Detection

Semantic Segmentation

2D Object Detection

GRASS, CAT, DOG, DOG, CAT

3D Object Detection

Car

(87)

Simplified Camera Model

camera

viewing frustrum

(88)

Simplified Camera Model

2D point 3D ray

camera

viewing frustrum

(89)

Simplified Camera Model

2D point 3D ray

camera

viewing frustrum

(90)

Scale & Distance Ambiguity

Image plane

(91)

2D point 3D ray

Simplified Camera Model

camera

viewing frustrum

(92)

3D Object Detection

(93)

3D Object Detection

(94)

3D Object Detection: Monocular Camera

Faster R-CNN

(95)

3D Object Detection: Monocular View

(96)

3D Object Detection: Camera + LiDAR

This image is CC0 public domain

(97)

3D Object Detection: Camera + LiDAR

(98)

3D Object Detection: Camera + LiDAR

(99)

RGB-Depth Camera

This image is CC0 public domain

(100)

RGB-Depth Camera

(101)

Point Cloud Voxelization

(x, y, z, r, g, b)

(102)

3D Object Detection: RGB-Depth Camera

R P N 3D Conv

More layers

3D NMS

3D region proposals

Voxelized RGB-D point cloud Object categories +

3D bounding boxes

(103)

Recap

Semantic Segmentation

2D Object Detection

GRASS, CAT, TREE, SKY

DOG, DOG, CAT

3D Object Detection

Car

(104)

Next time:

Visualizing CNN features

DeepDream + Style Transfer

References

Related documents