import{s as ot,n as st,o as rt}from"../chunks/scheduler.7bc62968.js";import{S as lt,i as ht,g as s,s as a,r as h,A as mt,h as r,f as n,c as o,j as it,u as m,x as l,k as at,y as ft,a as i,v as f,d as c,t as p,w as u}from"../chunks/index.2f8492b0.js";import{H as d,E as ct}from"../chunks/getInferenceSnippets.6109a300.js";function pt(qe){let g,Q,Z,ee,v,te,$,ne,y,Ee=`Recently, the breakthrough of Vision Transformers (ViTs) quickly superseded pure CNN models as the new state-of-the-art for image recognition.
Intriguingly, research has found that CNNs could adopt a significant portion of the design choices in Vision Transformers.
ConvNext represents a significant improvement to pure convolution models by incorporating techniques inspired by ViTs and achieving results comparable to ViTs in accuracy and scalability.`,ie,x,ae,w,Ae=`The author of the ConvNeXT paper starts building the model with a regular ResNet (ResNet-50), then modernizes and improves the architecture step-by-step to imitate the hierarchical structure of Vision Transformers.
The key improvements are:`,oe,C,Ue="<li>Training techniques</li> <li>Macro design</li> <li>ResNeXt-ify</li> <li>Inverted Bottleneck</li> <li>Large Kernel Sizes</li> <li>Micro Design</li>",se,b,De=`We will go through each of the key improvements.
These designs are not novel in itself. However, you can learn how researchers adapt and modify designs systematically to improve existing models.
To show the effectiveness of each improvement, we will compare the model’s accuracy before and after the modification on ImageNet-1K.`,re,T,Be='<img src="https://huggingface.co/datasets/hf-vision/course-assets/resolve/main/block_comparison.png" alt="Block Comparison"/>',le,N,he,_,Ve=`The researchers first discerned that, while architectural design choices are crucial, the quality of the training procedure also plays a pivotal role in influencing performance outcomes.
Inspired by DeiT and Swin Transformers, ConvNext closely adapts their training techniques. Some of the notable changes are:`,me,k,Fe="<li>Epochs: Extending the epochs from the original 90 epochs to 300 epochs.</li> <li>Optimizer: Using AdamW optimizer instead of Adam optimizer, which differs in how it handles weight decay.</li> <li>Mixup (generates a weighted combination of random image pairs), Cutmix (cuts part of an image and replace it with a patch from another image), RandAugment (applies a series of random augmentations such as rotation, translation, and shear), and Random Erasing (randomly selects a rectangle region in an image and erases its pixels with random values) to increase training data.</li> <li>Regularization: Using Stochastic Depth and Label Smoothing as regularization techniques.</li>",fe,L,Xe="Modifying these training procedures has improved ResNet-50’s accuracy from 76.1% to 78.8%.",ce,M,pe,P,je=`Macro design refers to the high-level structural decisions and considerations made in a system or model, such as the arrangement of layers, the distribution of computational load across different stages, and the overall structure.
Examining Swin Transformers’ macro network, the authors have identified two noteworthy design considerations that benefit the performance of ConvNext.`,ue,z,de,H,Oe=`The stage compute ratio refers to the distribution of computational load among the stages of a neural network model.
ResNet-50 has four main stages with (3, 4, 6, 3) blocks, which means it has a compute ratio of 3:4:6:3.
To follow Swin Transformer’s compute ratio of 1:1:3:1, the researchers adjusted the number of blocks on each stage of the ResNet from (3, 4, 6, 3) to (3, 3, 9, 3) instead.
Changing the stage compute ratio improves the model accuracy from 78.8% to 79.4%.`,ge,R,ve,S,Ke=`Typically, at the start of ResNet’s architecture, the input is fed to a stem 7×7 convolution layer with stride 2, followed by a max pool, used to downsample the image by a factor of 4.
However, the authors discovered that substituting the stem with a convolutional layer featuring a 4×4 kernel size and a stride of 4 is more effective, effectively convolving them through non-overlapping 4x4 patches.
Patchify serves the same purpose of downsampling the image by a factor of 4 while reducing the number of layers.
This Patchifying step slightly improves the model accuracy from 79.4% to 79.5%.`,$e,I,ye,q,Ge=`ConvNext also adopts the idea of ResNeXt, explained in the previous section.
ResNeXt demonstrates an improved trade-off between the number of floating-point operations (FLOPs) and accuracy compared to a standard ResNet.
By using depthwise convolution and 1 × 1 convolutions, we would have the separation of spatial and channel mixing - a characteristic also found in vision Transformers.
Using depthwise convolutions reduces the number of FLOPS and the accuracy.
However, by increasing the channels from 64 to 96, the accuracy is higher than the original ResNet-50 while maintaining a similar number of FLOPs.
This modification improves the model accuracy from 79.5% to 80.5%.`,xe,E,we,A,We=`One common idea in every Transformer block is the usage of an inverted bottleneck, where the hidden layers are much bigger than the input dimension.
This idea has also been used and popularized in Computer Vision by MobileNetV2.
ConvNext adopts this idea, having input layers with 96 channels and increasing the hidden layers to 384 channels.
By using this technique, it improves the model accuracy from 80.5% to 80.6%.`,Ce,U,Ye='<img src="https://huggingface.co/datasets/hf-vision/course-assets/resolve/main/inverted_bottleneck.png" alt="Inverted Bottleneck Comparison"/>',be,D,Te,B,Ze=`A key factor contributing to the exceptional performance of Vision Transformer is its non-local self-attention, allowing for a broader receptive field of image features.
In Swin Transformers, the attention block window size is set to at least 7×7, surpassing the 3x3 kernel size of ResNext.
However, before adjusting the kernel size, it is necessary to reposition the depthwise convolution layer, as shown in the image below.
This repositioning enables the 1x1 layers to efficiently handle computational tasks, while the depthwise convolution layer functions as a more non-local receptor.
With this, the network can harness the advantages of incorporating bigger kernel-sized convolutions.
Implementing a 7x7 kernel size maintains the accuracy at 80.6% but reduces the overall FLOPs efficiency of the model.`,Ne,V,Je='<img src="https://huggingface.co/datasets/hf-vision/course-assets/resolve/main/depthwise_moveup.png" alt="Moving up the Depth Conv Layer"/>',_e,F,ke,X,Qe=`In addition to the modifications stated, the author adds some micro-design changes to the model.
Mico design refers to low-level structural decisions such as the choice of activation functions and layer details.
Some of the notable micro changes are:`,Le,j,et=`<li>Activation: Replacing ReLU activation with GELU (Gaussian Error Linear Unit) and eliminating all GELU layers from the residual block except for one between two 1×1 layers.</li> <li>Normalization: Fewer normalization layers by removing two BatchNorm layers and substituting BatchNorm with LayerNorm, leaving only one LayerNorm layer before the conv 1 × 1 layers.</li> <li>Downsampling Layer: Add a separate downsample layer in between ResNet stages
These final modifications improve the ConvNext accuracy from 80.6% to 82.0%.
The final ConvNext model exceeds Swin Transformer’s accuracy of 81.3%.</li>`,Me,O,Pe,K,tt='You can go to <a href="https://huggingface.co/docs/transformers/model_doc/convnext" rel="nofollow">this HuggingFace documentation</a> to learn how to integrate the ConvNext pipeline into your code.',ze,G,He,W,nt=`The paper “A ConvNet for the 2020s” proposed the ConvNext architecture in 2022 by a team of researchers from Facebook AI Research, including Zhuang Liu, Hanzi Mao, Chao-Yuan Wu, Christoph Feichtenhofer, Trevor Darrell, and Saining Xie.
The paper can be found <a href="https://arxiv.org/abs/2201.03545" rel="nofollow">here</a> and the GitHub repo can be found <a href="https://github.com/facebookresearch/ConvNeXt" rel="nofollow">here</a>.`,Re,Y,Se,J,Ie;return v=new d({props:{title:"ConvNext - A ConvNet for the 2020s (2022)",local:"convnext---a-convnet-for-the-2020s-2022",headingTag:"h1"}}),$=new d({props:{title:"Introduction",local:"introduction",headingTag:"h2"}}),x=new d({props:{title:"Key Improvements",local:"key-improvements",headingTag:"h2"}}),N=new d({props:{title:"Training Techniques",local:"training-techniques",headingTag:"h2"}}),M=new d({props:{title:"Macro Design",local:"macro-design",headingTag:"h2"}}),z=new d({props:{title:"The stage compute ratio",local:"the-stage-compute-ratio",headingTag:"h3"}}),R=new d({props:{title:"Changing stem to Patchify",local:"changing-stem-to-patchify",headingTag:"h3"}}),I=new d({props:{title:"ResNeXt-ify",local:"resnext-ify",headingTag:"h2"}}),E=new d({props:{title:"Inverted Bottleneck",local:"inverted-bottleneck",headingTag:"h2"}}),D=new d({props:{title:"Large Kernel Sizes",local:"large-kernel-sizes",headingTag:"h2"}}),F=new d({props:{title:"Micro Design",local:"micro-design",headingTag:"h2"}}),O=new d({props:{title:"Model Code",local:"model-code",headingTag:"h2"}}),G=new d({props:{title:"References",local:"references",headingTag:"h2"}}),Y=new ct({props:{source:"https://github.com/huggingface/computer-vision-course/blob/main/chapters/en/unit2/cnns/convnext.mdx"}}),{c(){g=s("meta"),Q=a(),Z=s("p"),ee=a(),h(v.$$.fragment),te=a(),h($.$$.fragment),ne=a(),y=s("p"),y.textContent=Ee,ie=a(),h(x.$$.fragment),ae=a(),w=s("p"),w.textContent=Ae,oe=a(),C=s("ul"),C.innerHTML=Ue,se=a(),b=s("p"),b.textContent=De,re=a(),T=s("p"),T.innerHTML=Be,le=a(),h(N.$$.fragment),he=a(),_=s("p"),_.textContent=Ve,me=a(),k=s("ul"),k.innerHTML=Fe,fe=a(),L=s("p"),L.textContent=Xe,ce=a(),h(M.$$.fragment),pe=a(),P=s("p"),P.textContent=je,ue=a(),h(z.$$.fragment),de=a(),H=s("p"),H.textContent=Oe,ge=a(),h(R.$$.fragment),ve=a(),S=s("p"),S.textContent=Ke,$e=a(),h(I.$$.fragment),ye=a(),q=s("p"),q.textContent=Ge,xe=a(),h(E.$$.fragment),we=a(),A=s("p"),A.textContent=We,Ce=a(),U=s("p"),U.innerHTML=Ye,be=a(),h(D.$$.fragment),Te=a(),B=s("p"),B.textContent=Ze,Ne=a(),V=s("p"),V.innerHTML=Je,_e=a(),h(F.$$.fragment),ke=a(),X=s("p"),X.textContent=Qe,Le=a(),j=s("ul"),j.innerHTML=et,Me=a(),h(O.$$.fragment),Pe=a(),K=s("p"),K.innerHTML=tt,ze=a(),h(G.$$.fragment),He=a(),W=s("p"),W.innerHTML=nt,Re=a(),h(Y.$$.fragment),Se=a(),J=s("p"),this.h()},l(e){const t=mt("svelte-u9bgzb",document.head);g=r(t,"META",{name:!0,content:!0}),t.forEach(n),Q=o(e),Z=r(e,"P",{}),it(Z).forEach(n),ee=o(e),m(v.$$.fragment,e),te=o(e),m($.$$.fragment,e),ne=o(e),y=r(e,"P",{"data-svelte-h":!0}),l(y)!=="svelte-1xbb17w"&&(y.textContent=Ee),ie=o(e),m(x.$$.fragment,e),ae=o(e),w=r(e,"P",{"data-svelte-h":!0}),l(w)!=="svelte-3zp0ah"&&(w.textContent=Ae),oe=o(e),C=r(e,"UL",{"data-svelte-h":!0}),l(C)!=="svelte-1surxjp"&&(C.innerHTML=Ue),se=o(e),b=r(e,"P",{"data-svelte-h":!0}),l(b)!=="svelte-1xn2fwb"&&(b.textContent=De),re=o(e),T=r(e,"P",{"data-svelte-h":!0}),l(T)!=="svelte-hpkh9n"&&(T.innerHTML=Be),le=o(e),m(N.$$.fragment,e),he=o(e),_=r(e,"P",{"data-svelte-h":!0}),l(_)!=="svelte-x3eulp"&&(_.textContent=Ve),me=o(e),k=r(e,"UL",{"data-svelte-h":!0}),l(k)!=="svelte-1p5xkp1"&&(k.innerHTML=Fe),fe=o(e),L=r(e,"P",{"data-svelte-h":!0}),l(L)!=="svelte-2ffe9x"&&(L.textContent=Xe),ce=o(e),m(M.$$.fragment,e),pe=o(e),P=r(e,"P",{"data-svelte-h":!0}),l(P)!=="svelte-jme7tz"&&(P.textContent=je),ue=o(e),m(z.$$.fragment,e),de=o(e),H=r(e,"P",{"data-svelte-h":!0}),l(H)!=="svelte-164n12x"&&(H.textContent=Oe),ge=o(e),m(R.$$.fragment,e),ve=o(e),S=r(e,"P",{"data-svelte-h":!0}),l(S)!=="svelte-q3frac"&&(S.textContent=Ke),$e=o(e),m(I.$$.fragment,e),ye=o(e),q=r(e,"P",{"data-svelte-h":!0}),l(q)!=="svelte-19t3tih"&&(q.textContent=Ge),xe=o(e),m(E.$$.fragment,e),we=o(e),A=r(e,"P",{"data-svelte-h":!0}),l(A)!=="svelte-f2hrwg"&&(A.textContent=We),Ce=o(e),U=r(e,"P",{"data-svelte-h":!0}),l(U)!=="svelte-1xhu8a2"&&(U.innerHTML=Ye),be=o(e),m(D.$$.fragment,e),Te=o(e),B=r(e,"P",{"data-svelte-h":!0}),l(B)!=="svelte-odbjli"&&(B.textContent=Ze),Ne=o(e),V=r(e,"P",{"data-svelte-h":!0}),l(V)!=="svelte-1vjwuxs"&&(V.innerHTML=Je),_e=o(e),m(F.$$.fragment,e),ke=o(e),X=r(e,"P",{"data-svelte-h":!0}),l(X)!=="svelte-1t3cn42"&&(X.textContent=Qe),Le=o(e),j=r(e,"UL",{"data-svelte-h":!0}),l(j)!=="svelte-1404rzr"&&(j.innerHTML=et),Me=o(e),m(O.$$.fragment,e),Pe=o(e),K=r(e,"P",{"data-svelte-h":!0}),l(K)!=="svelte-1dfpi5t"&&(K.innerHTML=tt),ze=o(e),m(G.$$.fragment,e),He=o(e),W=r(e,"P",{"data-svelte-h":!0}),l(W)!=="svelte-15wicxb"&&(W.innerHTML=nt),Re=o(e),m(Y.$$.fragment,e),Se=o(e),J=r(e,"P",{}),it(J).forEach(n),this.h()},h(){at(g,"name","hf:doc:metadata"),at(g,"content",ut)},m(e,t){ft(document.head,g),i(e,Q,t),i(e,Z,t),i(e,ee,t),f(v,e,t),i(e,te,t),f($,e,t),i(e,ne,t),i(e,y,t),i(e,ie,t),f(x,e,t),i(e,ae,t),i(e,w,t),i(e,oe,t),i(e,C,t),i(e,se,t),i(e,b,t),i(e,re,t),i(e,T,t),i(e,le,t),f(N,e,t),i(e,he,t),i(e,_,t),i(e,me,t),i(e,k,t),i(e,fe,t),i(e,L,t),i(e,ce,t),f(M,e,t),i(e,pe,t),i(e,P,t),i(e,ue,t),f(z,e,t),i(e,de,t),i(e,H,t),i(e,ge,t),f(R,e,t),i(e,ve,t),i(e,S,t),i(e,$e,t),f(I,e,t),i(e,ye,t),i(e,q,t),i(e,xe,t),f(E,e,t),i(e,we,t),i(e,A,t),i(e,Ce,t),i(e,U,t),i(e,be,t),f(D,e,t),i(e,Te,t),i(e,B,t),i(e,Ne,t),i(e,V,t),i(e,_e,t),f(F,e,t),i(e,ke,t),i(e,X,t),i(e,Le,t),i(e,j,t),i(e,Me,t),f(O,e,t),i(e,Pe,t),i(e,K,t),i(e,ze,t),f(G,e,t),i(e,He,t),i(e,W,t),i(e,Re,t),f(Y,e,t),i(e,Se,t),i(e,J,t),Ie=!0},p:st,i(e){Ie||(c(v.$$.fragment,e),c($.$$.fragment,e),c(x.$$.fragment,e),c(N.$$.fragment,e),c(M.$$.fragment,e),c(z.$$.fragment,e),c(R.$$.fragment,e),c(I.$$.fragment,e),c(E.$$.fragment,e),c(D.$$.fragment,e),c(F.$$.fragment,e),c(O.$$.fragment,e),c(G.$$.fragment,e),c(Y.$$.fragment,e),Ie=!0)},o(e){p(v.$$.fragment,e),p($.$$.fragment,e),p(x.$$.fragment,e),p(N.$$.fragment,e),p(M.$$.fragment,e),p(z.$$.fragment,e),p(R.$$.fragment,e),p(I.$$.fragment,e),p(E.$$.fragment,e),p(D.$$.fragment,e),p(F.$$.fragment,e),p(O.$$.fragment,e),p(G.$$.fragment,e),p(Y.$$.fragment,e),Ie=!1},d(e){e&&(n(Q),n(Z),n(ee),n(te),n(ne),n(y),n(ie),n(ae),n(w),n(oe),n(C),n(se),n(b),n(re),n(T),n(le),n(he),n(_),n(me),n(k),n(fe),n(L),n(ce),n(pe),n(P),n(ue),n(de),n(H),n(ge),n(ve),n(S),n($e),n(ye),n(q),n(xe),n(we),n(A),n(Ce),n(U),n(be),n(Te),n(B),n(Ne),n(V),n(_e),n(ke),n(X),n(Le),n(j),n(Me),n(Pe),n(K),n(ze),n(He),n(W),n(Re),n(Se),n(J)),n(g),u(v,e),u($,e),u(x,e),u(N,e),u(M,e),u(z,e),u(R,e),u(I,e),u(E,e),u(D,e),u(F,e),u(O,e),u(G,e),u(Y,e)}}}const ut='{"title":"ConvNext - A ConvNet for the 2020s (2022)","local":"convnext---a-convnet-for-the-2020s-2022","sections":[{"title":"Introduction","local":"introduction","sections":[],"depth":2},{"title":"Key Improvements","local":"key-improvements","sections":[],"depth":2},{"title":"Training Techniques","local":"training-techniques","sections":[],"depth":2},{"title":"Macro Design","local":"macro-design","sections":[{"title":"The stage compute ratio","local":"the-stage-compute-ratio","sections":[],"depth":3},{"title":"Changing stem to Patchify","local":"changing-stem-to-patchify","sections":[],"depth":3}],"depth":2},{"title":"ResNeXt-ify","local":"resnext-ify","sections":[],"depth":2},{"title":"Inverted Bottleneck","local":"inverted-bottleneck","sections":[],"depth":2},{"title":"Large Kernel Sizes","local":"large-kernel-sizes","sections":[],"depth":2},{"title":"Micro Design","local":"micro-design","sections":[],"depth":2},{"title":"Model Code","local":"model-code","sections":[],"depth":2},{"title":"References","local":"references","sections":[],"depth":2}],"depth":1}';function dt(qe){return rt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class yt extends lt{constructor(g){super(),ht(this,g,dt,pt,ot,{})}}export{yt as component};
