5.6.11 · D3 · Coding › Machine Learning (Aerospace Applications) › Convolutional neural networks — convolution operation, pooli
Yeh Convolutional neural networks — convolution & pooling ka worked-examples deep dive hai. Parent note ne tumhe formulas diye; yahan hum unhe har case class ke against stress-test karte hain — output ka har sign, har degenerate input, stride aur padding ka limiting behaviour, ek real aerospace word problem, aur ek exam twist.
Shuru karne se pehle, do formulas ka ek reminder jo neeche sab kuch support karta hai. Agar koi bhi symbol unfamiliar lage, parent dobara padho — lekin hum har ek ko jab aata hai tab re-explain karte hain.
Definition Ek symbol jis ki zaroorat baar baar padegi:
F
Poore document mein, F = ek convolution layer mein number of filters (jise number of output channels bhi kehte hain). Ek filter ek output feature map produce karta hai; F filters ko stack karne se F maps milte hain. Jab bhi neeche F dekho, isko padho "is layer mein kitne alag-alag chhote stamps image par slide karte hain."
Recall Teen parent-page facts jis par hum rely karte hain (taaki parent open na rakhna pade)
Parent ne common mistakes list ki thi; hum teen ko naam se cite karte hain. Seedhi baat mein:
Pooling ke zero learnable parameters hote hain — max/average ek fixed function hai, train nahi hoti.
Stride sirf ek speed knob nahi hai — bada s size formula ke through output ko directly shrink karta hai.
Conv parameters image size se independent hain — ye sirf F ( k 2 C + 1 ) par depend karte hain, kabhi W in par nahi.
Is topic ke har problem ka type in cells mein se kisi ek mein aata hai. Neeche ke examples is tarah choose kiye gaye hain ki milkar wo har row ko touch karte hain.
#
Case class
Isme tricky kya hai
Covered by
A
Padding size preserve karta hai (p aise choose ki W o u t = W in )
"same" convolution — kya arithmetic exact hai?
Ex 1
B
Non-divisible / floor kick karta hai
( W in − k + 2 p ) s ka multiple nahi → rounding down ek position lose karta hai
Ex 2
C
Negative output value
ek kernel jo S < 0 produce kare — signs matter karte hain, clipping nahi
Ex 3
D
Degenerate: 1 × 1 kernel, stride 1
kya convolution kuch "kar" bhi rahi hai?
Ex 4
E
Limiting stride: s = k (no overlap) & s > 1 shrink
stride kitna push kar sakta hai output ke 1 hit hone se pehle?
Ex 5
F
Multi-channel filter (depth par sum)
parameter count aur extra sum
Ex 6
G
Pooling: max vs average, ek shift ke saath invariance prove karne ke liye
kya max sach mein nahi hilta?
Ex 7
H
Real aerospace word problem (crack-detector sizing)
words → numbers → layer stack translate karo
Ex 8
I
Exam twist: ek unknown (p ya s ) solve karo target size se
formula invert karo
Ex 9
J
Zero/empty degenerate: kernel input se bada
W o u t ≤ 0 kab hota hai (invalid)?
Ex 10
Worked example "Same" convolution
Input W in = 32 , kernel k = 5 , stride s = 1 . p choose karo taaki output bhi 32 ho. Phir confirm karo.
Forecast: padding padhne se pehle guess karo. Bada kernel → zyada padding chahiye?
Equation set up karo. Hum chahte hain W o u t = W in = 32 . Formula mein s = 1 ke saath plug in karo:
32 = 1 32 − 5 + 2 p + 1.
Yeh step kyun? "Same" convolution requirement W o u t = W in se define hoti hai, isliye hum ise impose karke sirf unknown p ke liye solve karte hain.
p ke liye solve karo. + 1 subtract karo: 31 = 27 + 2 p ⇒ 2 p = 4 ⇒ p = 2 .
Yeh step kyun? Simple algebra — p isolate karo. Rule of thumb p = ( k − 1 ) /2 deta hai p = ( 5 − 1 ) /2 = 2 , jo match karta hai.
Verify: W o u t = ⌊( 32 − 5 + 2 ⋅ 2 ) /1 ⌋ + 1 = ⌊ 31 ⌋ + 1 = 32. ✓ Units: pixels in, pixels out, same count. Padding spatial size exactly preserve karta hai jab p = ( k − 1 ) /2 aur s = 1 ho.
Worked example Stride jo evenly divide nahi karta
Input W in = 7 , kernel k = 3 , padding p = 0 , stride s = 2 . W o u t nikalo aur exact kernel start positions list karo.
Forecast: ( 7 − 3 ) /2 = 2 … kya answer 2 hai, ya 3? Guess karo.
Numerator compute karo. W in − k + 2 p = 7 − 3 + 0 = 4 .
Yeh step kyun? Yeh last valid start index hai — kernel ka left edge itne se aage nahi ja sakta aur fit bhi rahe. Positions 0 , 1 , … , 4 tak chalti hain.
Stride se divide karo aur floor lagao. ⌊ 4/2 ⌋ = 2 , phir + 1 = 3 .
Yeh step kyun? s = 2 ke saath kernel sirf start indices 0 , 2 , 4 par land karta hai — har doosri position. Yeh 3 landings hain. + 1 position 0 ko count karta hai.
Check ke liye starts list karo. Starts = { 0 , 2 , 4 } . Start 6 par kernel columns 6 , 7 , 8 occupy karega — lekin last column index 6 hai, isliye 6 overflow karega. Confirm: 3 positions.
Yeh step kyun? Jab numerator s ka multiple nahi hota (e.g. W in ko 8 karo: numerator 5, ⌊ 5/2 ⌋ = 2 , phir bhi 3), floor silently leftover drop karta hai — yahi cell B ka trap hai.
Verify: ⌊( 7 − 3 + 0 ) /2 ⌋ + 1 = 2 + 1 = 3. ✓
Worked example Negative activation (abhi tak koi clipping nahi)
Parent ka diagonal-edge kernel lo aur ek fresh patch:
I = [ 0 9 5 0 ] , K = [ 1 0 0 − 1 ] , b = 0.
Kernel 2 × 2 hai, isliye ek single output value S ( 0 , 0 ) . Use compute karo.
Forecast: kya answer positive, zero, ya negative hoga?
Overlay karo aur multiply karo. S ( 0 , 0 ) = I ( 0 , 0 ) ⋅ 1 + I ( 0 , 1 ) ⋅ 0 + I ( 1 , 0 ) ⋅ 0 + I ( 1 , 1 ) ⋅ ( − 1 ) . I ( 0 , 0 ) = 0 , I ( 1 , 1 ) = 0 ke saath, yeh deta hai S = 0 ⋅ 1 + 0 ⋅ ( − 1 ) = 0 .
Yeh step kyun? Hum sum ∑ m ∑ n I K follow karte hain; sirf ( 0 , 0 ) aur ( 1 , 1 ) kernel entries nonzero hain.
Ab patch ka diagonal flip karo I ′ = [ 9 0 0 5 ] par: S ′ = 9 ⋅ 1 + 5 ⋅ ( − 1 ) = 9 − 5 = 4 (positive). Aur I ′′ = [ 2 0 0 8 ] : S ′′ = 2 − 8 = − 6 (negative ).
Yeh step kyun? Convolution output ek signed number hai. Negative S ka matlab "top-left diagonal ke saath bottom-right se dimmer hai." Kisi bhi activation (e.g. ReLU) se pehle, negatives real aur meaningful hote hain — prematurely clip mat karo.
Verify: S ′′ = 1 ⋅ 2 + ( − 1 ) ⋅ 8 = − 6. ✓ Sign correct: bottom-right (8 ) top-left (2 ) se bada hai, aur kernel bottom-right subtract karta hai, isliye output negative ho jaata hai.
1 × 1 convolution kuch karta hai?
Input W in = 6 , kernel k = 1 , p = 0 , s = 1 , single channel, kernel value K = [ 3 ] , bias b = 1 . W o u t kya hai aur layer per pixel kya compute karta hai?
Forecast: kya 1 × 1 conv sirf identity hai, ya kuch useful hai?
Output size. W o u t = ⌊( 6 − 1 + 0 ) /1 ⌋ + 1 = 5 + 1 = 6 . Size unchanged.
Yeh step kyun? k = 1 ke saath, window ek single cell hai jo har jagah fit ho jaati hai; koi shrinking nahi.
Yeh kya compute karta hai. S ( i , j ) = I ( i , j ) ⋅ 3 + 1 har pixel ke liye.
Yeh step kyun? Sum ∑ m , n ka sirf ek term hai. Isliye yeh per-pixel affine map hai — ek scale (× 3 ) plus shift (+ 1 ), har jagah identically apply hota hai.
Asli point (multi-channel). 1 × 1 kernel trivial nahi jab C channels hon: yeh har pixel par channels across learned mix ban jaata hai, F ( 1 ⋅ 1 ⋅ C + 1 ) parameters (yaad karo F = number of filters) — aerospace pipelines mein use hota hai physics fields ke stack ko cheaply fewer channels mein compress karne ke liye.
Yeh step kyun? Dikhata hai ki degenerate spatial case phir bhi depthwise kaam kar raha hai.
Verify: I = 4 wale pixel ke liye: S = 4 ⋅ 3 + 1 = 13. ✓ Size 6 ✓.
Worked example Stride kitna shrink kar sakta hai?
Input W in = 8 , kernel k = 2 , p = 0 . s = 1 , 2 , 4 , 8 ke liye W o u t compute karo.
Forecast: kis stride par output collapse hokar 1 ban jaata hai?
s = 1 : ⌊( 8 − 2 ) /1 ⌋ + 1 = 6 + 1 = 7 .
s = 2 : ⌊ 6/2 ⌋ + 1 = 3 + 1 = 4 . Non-overlapping windows begin — k = 2 , s = 2 ke saath har window new pixels touch karta hai.
s = 4 : ⌊ 6/4 ⌋ + 1 = 1 + 1 = 2 .
s = 8 : ⌊ 6/8 ⌋ + 1 = 0 + 1 = 1 . Sirf ek window — kernel sirf position 0 par land karta hai.
Yeh steps kyun? s badhane se output directly shrink hota hai (stride sirf ek speed knob nahi hai — upar wala recall box dekho). Limit W o u t = 1 hai: jab s > W in − k ho, kernel sirf index 0 par baith sakta hai, aur koi bada stride isse nahi badalta.
Verify: chaar answers hain 7 , 4 , 2 , 1. ✓ s mein monotonically non-increasing ✓, 1 par floored ✓.
Worked example Depth par sum + parameter count
C = 2 channels par ek single 2 × 2 filter, bias b = 0 . Input patch (pehle channel 0 phir channel 1) aur kernel slices:
I 0 = [ 1 3 2 4 ] , I 1 = [ 0 1 1 0 ] , K 0 = [ 1 0 0 1 ] , K 1 = [ 2 0 0 2 ] .
Single output value compute karo, phir F = 8 aise filters ke liye parameter count (yaad karo F = number of filters).
Forecast: do channels hone ke bawajood ek number nikalta hai — kyun ek?
Channel 0 convolve karo. ∑ I 0 ⊙ K 0 = 1 ⋅ 1 + 2 ⋅ 0 + 3 ⋅ 0 + 4 ⋅ 1 = 1 + 4 = 5 .
Yeh step kyun? Har channel apne khud ke kernel slice ke saath cross-correlate hota hai.
Channel 1 convolve karo. ∑ I 1 ⊙ K 1 = 0 ⋅ 2 + 1 ⋅ 0 + 1 ⋅ 0 + 0 ⋅ 2 = 0 .
Channels par sum + bias. S = 5 + 0 + b = 5 .
Yeh step kyun? Ek filter per position ek feature output karta hai; channel results add hote hain, depth C ko ek single scalar mein collapse karte hain. Isliye RGB ke 3 outputs per filter nahi aate.
Parameter count. F ( k 2 C + 1 ) = 8 ( 2 2 ⋅ 2 + 1 ) = 8 ( 8 + 1 ) = 72 .
Yeh step kyun? Har filter mein k 2 C weights plus 1 bias hota hai; image size se independent (recall box dekho).
Verify: output = 5 ✓; params = 72 ✓.
Worked example Max-pool vs average-pool, phir feature ko shift karo
S = 1 5 0 1 3 6 2 1 2 1 9 3 4 2 1 8 , 2 × 2 , s = 2.
Dono pools compute karo. Phir "6" ko uske window ke andar shift karo aur invariance test karne ke liye re-max-pool karo.
Forecast: shift par kaun react karega, max ya average?
Figure walkthrough (image ke bina bhi readable hai): figure top-left 2 × 2 window ki do copies dikhata hai. Left mein value 6 us window ke bottom-right cell mein hai; right mein 6 ek row upar move ho gayi hai (humne use 3 ke saath swap kiya). Dono copies mein highlighted accent-red cell window ka maximum hai, aur dono mein 6 read hota hai — maximum ki value identical hai chahe uski position badal gayi. Yeh invariance ka visual proof hai.
Charon windows ko max-pool karo. Top-left { 1 , 3 , 5 , 6 } → 6 ; top-right { 2 , 4 , 1 , 2 } → 4 ; bottom-left { 0 , 2 , 1 , 1 } → 2 ; bottom-right { 9 , 1 , 3 , 8 } → 9 . Isliye P ma x = [ 6 2 4 9 ] .
Yeh step kyun? Non-overlapping windows kyunki s = k = 2 ; max sabse strong "feature present?" signal rakhta hai.
Average-pool. Top-left ( 1 + 3 + 5 + 6 ) /4 = 3.75 ; top-right ( 2 + 4 + 1 + 2 ) /4 = 2.25 ; bottom-left ( 0 + 2 + 1 + 1 ) /4 = 1 ; bottom-right ( 9 + 1 + 3 + 8 ) /4 = 5.25 . P a v g = [ 3.75 1 2.25 5.25 ] .
Window ke andar shift karo (invariance test). Top-left window ka max cell ( 1 , 1 ) = 6 se cell ( 0 , 1 ) par move karo (3 aur 6 swap karo). Naya window { 1 , 6 , 5 , 3 } → max abhi bhi 6 . Yeh figure mein accent-red cell se match karta hai: maximum ki value nahi badli chahe position badal gayi.
Yeh step kyun? Yahi pooling ka poora point hai — local translation invariance . Ek pixel ka wobble max ko unchanged chhod deta hai, isliye network exact position ki chinta karna band kar deta hai.
Average ke saath contrast. { 1 , 6 , 5 , 3 } ka average abhi bhi 15/4 = 3.75 hai — yeh bhi unchanged, kyunki humne sirf wahi chaar numbers permute kiye. Lekin agar shift ek naya number window mein laata hai (e.g. neighbouring window se), max often survive karta hai jabki average change ho jaata hai. Isliye max standard invariance tool hai.
Verify: P ma x = [ 6 2 4 9 ] , P a v g = [ 3.75 1 2.25 5.25 ] , shifted-window max = 6 . ✓
Worked example Composite-panel crack detector size karna
Ek inspection camera 256 × 256 single-channel panel images deta hai (Image classification for aerospace inspection ). Tumhara pipeline hai:
Conv (k = 5 , p = 2 , s = 1 , F = 16 ) → MaxPool (2 × 2 , s = 2 ) → Conv (k = 3 , p = 1 , s = 1 , F = 32 ) → MaxPool (2 × 2 , s = 2 ). Yahan F phir se har conv ke filters (output channels) ki number hai.
Har stage ke baad spatial size aur har conv layer ke parameters nikalo.
Forecast: final spatial size guess karo — 64 se bada ya chhota?
Conv 1 size. ⌊( 256 − 5 + 2 ⋅ 2 ) /1 ⌋ + 1 = ⌊ 255 ⌋ + 1 = 256 . Kyun? p = ( k − 1 ) /2 = 2 "same" padding hai → size preserved. Output 256 × 256 × 16 .
Pool 1. ⌊( 256 − 2 + 0 ) /2 ⌋ + 1 = 127 + 1 = 128 . Har side half → 128 × 128 × 16 .
Conv 2. ⌊( 128 − 3 + 2 ⋅ 1 ) /1 ⌋ + 1 = 127 + 1 = 128 . Phir "same" (p = ( 3 − 1 ) /2 = 1 ). Output 128 × 128 × 32 .
Pool 2. ⌊( 128 − 2 ) /2 ⌋ + 1 = 63 + 1 = 64 . → 64 × 64 × 32 .
Parameters. Conv 1: F ( k 2 C + 1 ) = 16 ( 5 2 ⋅ 1 + 1 ) = 16 ⋅ 26 = 416 . Conv 2: 32 ( 3 2 ⋅ 16 + 1 ) = 32 ( 144 + 1 ) = 32 ⋅ 145 = 4640 . Pools: har ek 0 (pooling ke zero learnable parameters hote hain — recall box dekho).
Yeh step kyun? Yahi practical payoff hai — ek full crack-detector front-end ko sirf 416 + 4640 = 5056 weights chahiye, 256 × 256 image size se independent (conv parameters image size ke saath scale nahi karte). Fully-connected first layer ko ∼ 25 6 2 × 25 6 2 = 4.3 × 1 0 9 ki zaroorat hoti.
Verify: sizes 256 → 128 → 128 → 64 ✓; params 416 aur 4640 ✓.
Worked example Target output ke liye padding nikalo
Tumhe W in = 28 ko W o u t = 14 par map karna hai k = 3 , s = 2 use karke. Kaun sa integer p kaam karta hai?
Forecast: s = 2 ke saath hum roughly 28 ko half karke 14 karte hain — lekin kya arithmetic ko padding chahiye, ya floor already kar deta hai?
Formula invert karo. W o u t = ⌊( W in − k + 2 p ) / s ⌋ + 1 se start karo. Pehle floor drop karo (maan lo division exact hai): 14 − 1 = ( 28 − 3 + 2 p ) /2 ⇒ 13 ⋅ 2 = 25 + 2 p ⇒ 26 = 25 + 2 p ⇒ p = 0.5 .
Yeh step kyun? Unknown ke liye solve karna sirf algebra hai — lekin p ek integer hona chahiye (tum half pixel pad nahi kar sakte), isliye 0.5 exactly impossible hai. Fraction ek warning hai ki hume ab floor wapas laana hoga aur neighbouring integers p = 0 aur p = 1 test karne honge.
p = 0 test karo. ⌊( 28 − 3 + 0 ) /2 ⌋ + 1 = ⌊ 12.5 ⌋ + 1 = 12 + 1 = 13 . Target se ek kam.
Yeh step kyun? Floor restore hone ke saath, p = 0 target se kam ata hai, isliye reject.
p = 1 test karo. ⌊( 28 − 3 + 2 ) /2 ⌋ + 1 = ⌊ 13.5 ⌋ + 1 = 13 + 1 = 14 . ✓ p = 1 answer hai.
Yeh step kyun? Floor leftover half absorb kar leta hai (13.5 → 13 ), isliye integer p = 1 exactly target par land karta hai chahe "exact" solve ne fraction diya. Conclusion: size formula invert karte waqt fractional solve par kabhi trust mat karo — hamesha integer candidates ko floored formula ke against re-check karo.
Verify: ⌊( 28 − 3 + 2 ⋅ 1 ) /2 ⌋ + 1 = ⌊ 13.5 ⌋ + 1 = 14. ✓ p = 1 ke saath target hit.
Worked example Output kab exist nahi karta?
Input W in = 3 , kernel k = 5 , p = 0 , s = 1 . Kya valid convolution possible hai? Agar nahi, toh smallest padding nikalo jo use rescue kare.
Forecast: formula kya deta hai, aur kya output size zero ya negative ho sakta hai?
Plug in karo. W o u t = ⌊( 3 − 5 + 0 ) /1 ⌋ + 1 = ⌊ − 2 ⌋ + 1 = − 2 + 1 = − 1 .
Yeh step kyun? 5 × 5 kernel 3 × 3 image ke andar fit nahi ho sakta — numerator W in − k = − 2 negative ho jaata hai, aur formula non-positive number return karta hai.
Non-positive result interpret karo. W o u t ≤ 0 ka matlab hai koi valid kernel position exist nahi karti ; layer undefined hai, aur real libraries yahan ek shape error raise karte hain. Yeh poore topic ki degenerate boundary hai.
Yeh step kyun? Yeh tumhe woh precondition batata hai jo har pehle ka example silently satisfy kar raha tha: convolution ko kernel ke liye kam se kam ek jagah chahiye.
Rescue padding nikalo. Hume numerator non-negative chahiye: W in − k + 2 p ≥ 0 ⇒ 3 − 5 + 2 p ≥ 0 ⇒ 2 p ≥ 2 ⇒ p ≥ 1 . Smallest lo, p = 1 : W o u t = ⌊( 3 − 5 + 2 ) /1 ⌋ + 1 = 0 + 1 = 1 — ek valid output.
Yeh step kyun? Padding effective width W in + 2 p ko tab tak badhati hai jab tak kernel fit na ho jaye. General precondition hai W in + 2 p ≥ k .
Verify: unpadded − 1 deta hai (invalid) ✓; p = 1 ke saath 1 deta hai (valid) ✓.
Recall Scenario checklist
Kisi bhi conv/pool answer par trust karne se pehle, kaun si chaar cheezein sanity-check karte ho? ::: Output ka sign (pre-activation negative ho sakta hai), floor jab numerator stride se divisible na ho, yeh ki W in + 2 p ≥ k ho (warna invalid), aur yeh ki pooling ke zero parameters hote hain.
Stride 1 ke liye "Same" padding rule ::: p = ( k − 1 ) /2 , jo W o u t = W in banata hai.
Stride W o u t = 1 kab force karta hai? ::: Jab s > W in − k ho (p = 0 ke saath): kernel sirf position 0 par land karta hai.
F kya stand karta hai? ::: Conv layer mein filters ki number, yaani output channels/feature maps ki number jo woh produce karta hai.
Parent topic — yahan work kiye gaye formulas.
Padding and stride — Examples 1, 2, 5, 9, 10 sab iske edge cases hain.
Feature maps and receptive fields — yahan compute kiya gaya har W o u t ek feature-map dimension hai.
Translation equivariance vs invariance — Example 7 ka shift test invariance demo hai.
Image classification for aerospace inspection — Example 8 ek real detector size karta hai.
Fully-connected neural networks — Example 8 mein 4.3 × 1 0 9 comparison.
Backpropagation — poore document mein count kiye gaye shared weights train karta hai.