-
Notifications
You must be signed in to change notification settings - Fork 207
/
Lecture 12 _ Visualizing and Understanding.srt
4684 lines (3697 loc) · 112 KB
/
Lecture 12 _ Visualizing and Understanding.srt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1
00:00:10,512 --> 00:00:15,376
- Good morning.
So, it's 12:03 so, I want to get started.
2
00:00:15,376 --> 00:00:18,014
Welcome to Lecture 12, of CS-231N.
3
00:00:18,014 --> 00:00:21,840
Today we are going to talk about Visualizing
and Understanding convolutional networks.
4
00:00:21,840 --> 00:00:25,270
This is always a super fun lecture to give
because we get to look a lot of pretty pictures.
5
00:00:25,270 --> 00:00:28,375
So, it's, it's one of my favorites.
6
00:00:28,375 --> 00:00:30,354
As usual a couple administrative things.
7
00:00:30,354 --> 00:00:39,544
So, hopefully your projects are all going well, because as a reminder your milestones
are due on Canvas tonight. It is Canvas, right? Okay, so want to double check, yeah.
8
00:00:39,545 --> 00:00:43,590
Due on Canvas tonight, we are working on
furiously grading your midterms.
9
00:00:43,590 --> 00:00:49,537
So, we'll hope to have those midterms grades
to you back by on grade scope this week.
10
00:00:49,537 --> 00:00:54,987
So, I know that was little confusion, you all got registration
email's for grade scope probably in the last week.
11
00:00:54,988 --> 00:00:57,372
Something like that, we start
couple of questions on piazo.
12
00:00:57,372 --> 00:00:59,530
So, we've decided to use grade
scope to grade the midterms.
13
00:00:59,530 --> 00:01:02,973
So, don't be confused, if you
get some emails about that.
14
00:01:02,973 --> 00:01:05,047
Another reminder is that assignment three
15
00:01:05,047 --> 00:01:07,412
was released last week on Friday.
16
00:01:07,412 --> 00:01:11,088
It will be due, a week from
this Friday, on the 26th.
17
00:01:11,088 --> 00:01:12,595
This is, an assignment three,
18
00:01:12,595 --> 00:01:14,444
is almost entirely brand new this year.
19
00:01:14,444 --> 00:01:17,152
So, it we apologize for taking
a little bit longer than
20
00:01:17,152 --> 00:01:18,847
expected to get it out.
21
00:01:18,847 --> 00:01:20,272
But I think it's super cool.
22
00:01:20,272 --> 00:01:22,644
A lot of that stuff, we'll
talk about in today's lecture.
23
00:01:22,644 --> 00:01:25,283
You'll actually be implementing
on your assignment.
24
00:01:25,283 --> 00:01:27,188
And for the assignment, you'll
get the choice of either
25
00:01:27,188 --> 00:01:29,575
Pi torch or tensure flow.
26
00:01:29,575 --> 00:01:30,921
To work through these different examples.
27
00:01:30,921 --> 00:01:34,512
So, we hope that's really
useful experience for you guys.
28
00:01:34,512 --> 00:01:35,822
We also saw a lot of activity
29
00:01:35,822 --> 00:01:37,273
on HyperQuest over the weekend.
30
00:01:37,273 --> 00:01:39,084
So that's, that's really awesome.
31
00:01:39,084 --> 00:01:40,549
The leader board went up yesterday.
32
00:01:40,549 --> 00:01:42,568
It seems like you guys are
really trying to battle it out
33
00:01:42,568 --> 00:01:44,227
to show off your deep learning
34
00:01:44,227 --> 00:01:46,063
neural network training skills.
35
00:01:46,063 --> 00:01:47,402
So that's super cool.
36
00:01:47,402 --> 00:01:50,087
And we because due to the high interest
37
00:01:50,087 --> 00:01:52,811
in HyperQuest and due to
the conflicts with the,
38
00:01:52,811 --> 00:01:55,118
with the Milestones submission time.
39
00:01:55,118 --> 00:01:56,808
We decided to extend the deadline
40
00:01:56,808 --> 00:01:58,591
for extra credit through Sunday.
41
00:01:58,591 --> 00:02:02,279
So, anyone who does at
least 12 runs on HyperQuest
42
00:02:02,279 --> 00:02:04,773
by Sunday will get little bit
of extra credit in the class.
43
00:02:04,773 --> 00:02:07,394
Also those of you who are,
at the top of leader board
44
00:02:07,394 --> 00:02:09,175
doing really well, will
get may be little bit
45
00:02:09,175 --> 00:02:11,200
extra, extra credit.
46
00:02:11,200 --> 00:02:13,081
So, I thanks for
participating we got lot of
47
00:02:13,081 --> 00:02:15,935
interest and that was really cool.
48
00:02:15,935 --> 00:02:17,844
Final reminder is about
the poster session.
49
00:02:17,844 --> 00:02:21,445
So, we have the poster
session will be on June 6th.
50
00:02:21,445 --> 00:02:22,872
That date is finalized,
51
00:02:22,872 --> 00:02:24,940
I think that, I don't
remember the exact time.
52
00:02:24,940 --> 00:02:25,932
But it is June 6th.
53
00:02:25,932 --> 00:02:27,141
So that, we have some questions
54
00:02:27,141 --> 00:02:29,310
about when exactly that poster session is
55
00:02:29,310 --> 00:02:30,297
for those of you who are traveling
56
00:02:30,297 --> 00:02:31,897
at the end of quarter
or starting internships
57
00:02:31,897 --> 00:02:33,247
or something like that.
58
00:02:33,247 --> 00:02:35,497
So, it will be June 6th.
59
00:02:35,497 --> 00:02:37,210
Any questions on the admin notes.
60
00:02:39,241 --> 00:02:41,171
No, totally clear.
61
00:02:41,171 --> 00:02:42,578
So, last time we talked.
62
00:02:42,578 --> 00:02:44,254
So, last time we had a pretty
63
00:02:44,254 --> 00:02:46,259
jam packed lecture, when we
talked about lot of different
64
00:02:46,259 --> 00:02:48,161
computer vision tasks, as a reminder.
65
00:02:48,161 --> 00:02:49,955
We talked about semantic segmentation
66
00:02:49,955 --> 00:02:52,035
which is this problem, where
you want to sign labels
67
00:02:52,035 --> 00:02:54,318
to every pixel in the input image.
68
00:02:54,318 --> 00:02:56,131
But does not differentiate the
69
00:02:56,131 --> 00:02:58,225
object instances in those images.
70
00:02:58,225 --> 00:03:00,773
We talked about classification
plus localization.
71
00:03:00,773 --> 00:03:02,558
Where in addition to a class label
72
00:03:02,558 --> 00:03:04,059
you also want to draw a box
73
00:03:04,059 --> 00:03:06,539
or perhaps several boxes in the image.
74
00:03:06,539 --> 00:03:08,041
Where the distinction here is that,
75
00:03:08,041 --> 00:03:10,130
in a classification
plus localization setup.
76
00:03:10,130 --> 00:03:12,594
You have some fix number of
objects that you are looking for
77
00:03:12,594 --> 00:03:14,424
So, we also saw that this type of paradigm
78
00:03:14,424 --> 00:03:16,785
can be applied to the things
like pose recognition.
79
00:03:16,785 --> 00:03:18,836
Where you want to regress to
different numbers of joints
80
00:03:18,836 --> 00:03:20,222
in the human body.
81
00:03:20,222 --> 00:03:22,235
We also talked about the object detection
82
00:03:22,235 --> 00:03:23,976
where you start with some fixed
83
00:03:23,976 --> 00:03:25,851
set of category labels
that you are interested in.
84
00:03:25,851 --> 00:03:27,102
Like dogs and cats.
85
00:03:27,102 --> 00:03:29,460
And then the task is
to draw a boxes around
86
00:03:29,460 --> 00:03:31,196
every instance of those objects
87
00:03:31,196 --> 00:03:32,769
that appear in the input image.
88
00:03:32,769 --> 00:03:35,303
And object detection
is really distinct from
89
00:03:35,303 --> 00:03:37,063
classification plus localization
90
00:03:37,063 --> 00:03:38,783
because with object
detection, we don't know
91
00:03:38,783 --> 00:03:40,629
ahead of time, how many object instances
92
00:03:40,629 --> 00:03:42,298
we're looking for in the image.
93
00:03:42,298 --> 00:03:44,272
And we saw that there's
this whole family of methods
94
00:03:44,272 --> 00:03:48,100
based on RCNN, Fast RCNN and faster RCNN,
95
00:03:48,100 --> 00:03:49,916
as well as the single
shot detection methods
96
00:03:49,916 --> 00:03:52,588
for addressing this problem
of object detection.
97
00:03:52,588 --> 00:03:55,026
Then finally we talked
pretty briefly about
98
00:03:55,026 --> 00:03:57,722
instance segmentation,
which is kind of combining
99
00:03:57,722 --> 00:04:01,164
aspects of a semantic
segmentation and object detection
100
00:04:01,164 --> 00:04:03,308
where the goal is to
detect all the instances
101
00:04:03,308 --> 00:04:04,934
of the categories we care about,
102
00:04:04,934 --> 00:04:07,997
as well as label the pixels
belonging to each instance.
103
00:04:07,997 --> 00:04:11,339
So, in this case, we
detected two dogs and one cat
104
00:04:11,339 --> 00:04:13,093
and for each of those instances we wanted
105
00:04:13,093 --> 00:04:14,887
to label all the pixels.
106
00:04:14,887 --> 00:04:17,437
So, these are we kind of
covered a lot last lecture
107
00:04:17,437 --> 00:04:19,509
but those are really interesting
and exciting problems
108
00:04:19,509 --> 00:04:21,284
that you guys might consider to
109
00:04:21,284 --> 00:04:23,810
using in parts of your projects.
110
00:04:23,810 --> 00:04:25,645
But today we are going to
shift gears a little bit
111
00:04:25,645 --> 00:04:27,081
and ask another question.
112
00:04:27,081 --> 00:04:28,702
Which is, what's really going on
113
00:04:28,702 --> 00:04:30,578
inside convolutional networks.
114
00:04:30,578 --> 00:04:32,445
We've seen by this point in the class
115
00:04:32,445 --> 00:04:34,120
how to train convolutional networks.
116
00:04:34,120 --> 00:04:35,916
How to stitch up different
types of architectures
117
00:04:35,916 --> 00:04:37,503
to attack different problems.
118
00:04:37,503 --> 00:04:39,860
But one question that you
might have had in your mind,
119
00:04:39,860 --> 00:04:42,653
is what exactly is going
on inside these networks?
120
00:04:42,653 --> 00:04:44,081
How did they do the things that they do?
121
00:04:44,081 --> 00:04:46,444
What kinds of features
are they looking for?
122
00:04:46,444 --> 00:04:48,612
And all this source of related questions.
123
00:04:48,612 --> 00:04:51,043
So, so far we've sort of seen
124
00:04:51,043 --> 00:04:53,399
ConvNets as a little bit of a black box.
125
00:04:53,399 --> 00:04:55,635
Where some input image of raw pixels
126
00:04:55,635 --> 00:04:57,100
is coming in on one side.
127
00:04:57,100 --> 00:04:58,816
It goes to the many layers of convulsion
128
00:04:58,816 --> 00:05:01,170
and pooling in different
sorts of transformations.
129
00:05:01,170 --> 00:05:04,547
And on the outside, we end up
with some set of class scores
130
00:05:04,547 --> 00:05:07,363
or some types of understandable
interpretable output.
131
00:05:07,363 --> 00:05:09,865
Such as class scores or
bounding box positions
132
00:05:09,865 --> 00:05:12,342
or labeled pixels or something like that.
133
00:05:12,342 --> 00:05:13,307
But the question is.
134
00:05:13,307 --> 00:05:15,933
What are all these other
layers in the middle doing?
135
00:05:15,933 --> 00:05:17,685
What kinds of things in the input image
136
00:05:17,685 --> 00:05:18,567
are they looking for?
137
00:05:18,567 --> 00:05:20,857
And can we try again intuition for.
138
00:05:20,857 --> 00:05:22,023
How ConvNets are working?
139
00:05:22,023 --> 00:05:24,364
What types of things in the
image they are looking for?
140
00:05:24,364 --> 00:05:25,867
And what kinds of techniques do we have
141
00:05:25,867 --> 00:05:29,327
for analyzing this
internals of the network?
142
00:05:29,327 --> 00:05:32,667
So, one relatively simple
thing is the first layer.
143
00:05:32,667 --> 00:05:34,522
So, we've seen, we've
talked about this before.
144
00:05:34,522 --> 00:05:37,508
But recalled that, the
first convolutional layer
145
00:05:37,508 --> 00:05:39,819
consists of a filters that,
146
00:05:39,819 --> 00:05:41,492
so, for example in AlexNet.
147
00:05:41,492 --> 00:05:43,262
The first convolutional layer consists
148
00:05:43,262 --> 00:05:45,193
of a number of convolutional filters.
149
00:05:45,193 --> 00:05:49,230
Each convolutional of filter
has shape 3 by 11 by 11.
150
00:05:49,230 --> 00:05:51,228
And these convolutional filters gets slid
151
00:05:51,228 --> 00:05:52,268
over the input image.
152
00:05:52,268 --> 00:05:54,947
We take inner products between
some chunk of the image.
153
00:05:54,947 --> 00:05:56,909
And the weights of the
convolutional filter.
154
00:05:56,909 --> 00:05:58,689
And that gives us our output of the
155
00:05:58,689 --> 00:06:01,729
at, at after that first
convolutional layer.
156
00:06:01,729 --> 00:06:05,074
So, in AlexNet then we
have 64 of these filters.
157
00:06:05,074 --> 00:06:06,947
But now in the first layer
because we are taking
158
00:06:06,947 --> 00:06:08,780
in a direct inner product
between the weights
159
00:06:08,780 --> 00:06:10,175
of the convolutional layer
160
00:06:10,175 --> 00:06:11,682
and the pixels of the image.
161
00:06:11,682 --> 00:06:14,548
We can get some since for what
these filters are looking for
162
00:06:14,548 --> 00:06:17,697
by simply visualizing the
learned weights of these filters
163
00:06:17,697 --> 00:06:19,458
as images themselves.
164
00:06:19,458 --> 00:06:22,576
So, for each of those
11 by 11 by 3 filters
165
00:06:22,576 --> 00:06:25,027
in AlexNet, we can just
visualize that filter
166
00:06:25,027 --> 00:06:28,461
as a little 11 by 11 image
with a three channels
167
00:06:28,461 --> 00:06:30,201
give you the red, green and blue values.
168
00:06:30,201 --> 00:06:32,051
And then because there
are 64 of these filters
169
00:06:32,051 --> 00:06:35,305
we just visualize 64
little 11 by 11 images.
170
00:06:35,305 --> 00:06:38,047
And we can repeat... So
we have shown here at the.
171
00:06:38,047 --> 00:06:40,982
So, these are filters taken
from the prechain models,
172
00:06:40,982 --> 00:06:42,509
in the pi torch model zoo.
173
00:06:42,509 --> 00:06:44,739
And we are looking at the
convolutional filters.
174
00:06:44,739 --> 00:06:45,985
The weights of the convolutional filters.
175
00:06:45,985 --> 00:06:48,313
at the first layer of AlexNet, ResNet-18,
176
00:06:48,313 --> 00:06:51,065
ResNet-101 and DenseNet-121.
177
00:06:51,065 --> 00:06:53,753
And you can see, kind
of what all these layers
178
00:06:53,753 --> 00:06:55,553
what this filters looking for.
179
00:06:55,553 --> 00:06:59,015
You see the lot of things
looking for oriented edges.
180
00:06:59,015 --> 00:07:01,052
Likes bars of light and dark.
181
00:07:01,052 --> 00:07:04,487
At various angles, in various
angles and various positions
182
00:07:04,487 --> 00:07:07,200
in the input, we can see opposing colors.
183
00:07:07,200 --> 00:07:09,475
Like this are green and pink.
184
00:07:09,475 --> 00:07:12,732
opposing colors or this orange
and blue opposing colors.
185
00:07:12,732 --> 00:07:14,893
So, this, this kind of
connects back to what we
186
00:07:14,893 --> 00:07:16,221
talked about with Hugh and Wiesel.
187
00:07:16,221 --> 00:07:17,907
All the way in the first lecture.
188
00:07:17,907 --> 00:07:19,716
That remember the human visual system
189
00:07:19,716 --> 00:07:22,271
is known to the detect
things like oriented edges.
190
00:07:22,271 --> 00:07:24,978
At the very early layers
of the human visual system.
191
00:07:24,978 --> 00:07:26,946
And it turns out of that
these convolutional networks
192
00:07:26,946 --> 00:07:29,136
tend to do something, somewhat similar.
193
00:07:29,136 --> 00:07:31,566
At their first convolutional
layers as well.
194
00:07:31,566 --> 00:07:33,153
And what's kind of interesting is that
195
00:07:33,153 --> 00:07:35,631
pretty much no matter what type
of architecture you hook up
196
00:07:35,631 --> 00:07:37,920
or whatever type of training
data you are train it on.
197
00:07:37,920 --> 00:07:40,594
You almost always get
the first layers of your.
198
00:07:40,594 --> 00:07:42,736
The first convolutional
weights of any pretty much
199
00:07:42,736 --> 00:07:44,990
any convolutional network
looking at images.
200
00:07:44,990 --> 00:07:46,389
Ends up looking something like this
201
00:07:46,389 --> 00:07:48,676
with oriented edges and opposing colors.
202
00:07:48,676 --> 00:07:51,539
Looking at that input image.
203
00:07:51,539 --> 00:07:53,696
But this really only, sorry
what was that question?
204
00:08:04,215 --> 00:08:06,118
Yes, these are showing the learned weights
205
00:08:06,118 --> 00:08:07,592
of the first convolutional layer.
206
00:08:15,766 --> 00:08:16,826
Oh, so that the question is.
207
00:08:16,826 --> 00:08:18,998
Why does visualizing the
weights of the filters?
208
00:08:18,998 --> 00:08:21,318
Tell you what the filter is looking for.
209
00:08:21,318 --> 00:08:23,945
So this intuition comes from
sort of template matching
210
00:08:23,945 --> 00:08:25,045
and inner products.
211
00:08:25,045 --> 00:08:28,389
That if you imagine you have
some, some template vector.
212
00:08:28,389 --> 00:08:31,125
And then you imagine you
compute a scaler output
213
00:08:31,125 --> 00:08:33,272
by taking inner product
between your template vector
214
00:08:33,272 --> 00:08:35,044
and some arbitrary piece of data.
215
00:08:35,044 --> 00:08:38,321
Then, the input which
maximizes that activation.
216
00:08:38,321 --> 00:08:40,289
Under a norm constraint on the input
217
00:08:40,289 --> 00:08:43,062
is exactly when those
two vectors match up.
218
00:08:43,062 --> 00:08:45,564
So, in that since that,
when, whenever you're taking
219
00:08:45,564 --> 00:08:48,066
inner products, the thing
causes an inner product
220
00:08:48,066 --> 00:08:49,736
to excite maximally
221
00:08:49,736 --> 00:08:52,506
is a copy of the thing you are
taking an inner product with.
222
00:08:52,506 --> 00:08:55,060
So, that, that's why we can
actually visualize these weights
223
00:08:55,060 --> 00:08:56,323
and that, why that shows us,
224