import{s as Ve,n as Fe,o as Xe}from"../chunks/scheduler.7bc62968.js";import{S as Ke,i as Oe,g as s,s as a,r as h,A as je,h as r,f as i,c as o,j as Ee,u as c,x as l,k as Be,y as Ge,a as n,v as m,d as f,t as p,w as u}from"../chunks/index.2f8492b0.js";import{H as d}from"../chunks/Heading.14fb2476.js";function We(Ce){let g,j,K,G,v,W,$,Y,y,Ne=`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.`,Z,w,J,x,ke=`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:`,Q,T,Le=`<li>Training Techniques</li> <li>Macro Design</li> <li>ResNeXt-ify</li> <li>Inverted Bottleneck</li> <li>Large Kernel Sizes</li> <li>Micro Design
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.
<a href="https://huggingface.co/datasets/hf-vision/course-assets/resolve/main/block_comparison.png" rel="nofollow">Block Comparison</a></li>`,ee,b,te,C,_e=`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:`,ie,N,Me=`<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>Regularization: Using Stochastic Depth and Label Smoothing as regularization techniques.</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.
Modifying these training procedures has improved ResNet-50’s accuracy from 76.1% to 78.8%.</li> <li>Regularization: Using Stochastic Depth and Label Smoothing as regularization techniques.
Modifying these training procedures has improved ResNet-50’s accuracy from 76.1% to 78.8%.</li>`,ne,k,ae,L,ze=`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.`,oe,_,se,M,Re=`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%.`,re,z,le,R,Pe=`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%.`,he,P,ce,H,He=`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%.`,me,S,fe,I,Se=`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%.
<a href="https://huggingface.co/datasets/hf-vision/course-assets/resolve/main/inverted_bottleneck.png" rel="nofollow">Inverted Bottleneck Comparison</a>`,pe,q,ue,A,Ie=`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.
<a href="https://huggingface.co/datasets/hf-vision/course-assets/resolve/main/depthwise_moveup.png" rel="nofollow">Moving up the Depth Conv Layer</a>`,de,D,ge,U,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:`,ve,E,Ae=`<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>`,$e,B,ye,V,De='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.',we,F,xe,X,Ue=`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>.`,Te,O,be;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"}}),w=new d({props:{title:"Key Improvements",local:"key-improvements",headingTag:"h2"}}),b=new d({props:{title:"Training Techniques",local:"training-techniques",headingTag:"h2"}}),k=new d({props:{title:"Macro Design",local:"macro-design",headingTag:"h2"}}),_=new d({props:{title:"The stage compute ratio",local:"the-stage-compute-ratio",headingTag:"h3"}}),z=new d({props:{title:"Changing stem to Patchify",local:"changing-stem-to-patchify",headingTag:"h3"}}),P=new d({props:{title:"ResNeXt-ify",local:"resnext-ify",headingTag:"h2"}}),S=new d({props:{title:"Inverted Bottleneck",local:"inverted-bottleneck",headingTag:"h2"}}),q=new d({props:{title:"Large Kernel Sizes",local:"large-kernel-sizes",headingTag:"h2"}}),D=new d({props:{title:"Micro Design",local:"micro-design",headingTag:"h2"}}),B=new d({props:{title:"Model Code",local:"model-code",headingTag:"h2"}}),F=new d({props:{title:"References",local:"references",headingTag:"h2"}}),{c(){g=s("meta"),j=a(),K=s("p"),G=a(),h(v.$$.fragment),W=a(),h($.$$.fragment),Y=a(),y=s("p"),y.textContent=Ne,Z=a(),h(w.$$.fragment),J=a(),x=s("p"),x.textContent=ke,Q=a(),T=s("ul"),T.innerHTML=Le,ee=a(),h(b.$$.fragment),te=a(),C=s("p"),C.textContent=_e,ie=a(),N=s("ul"),N.innerHTML=Me,ne=a(),h(k.$$.fragment),ae=a(),L=s("p"),L.textContent=ze,oe=a(),h(_.$$.fragment),se=a(),M=s("p"),M.textContent=Re,re=a(),h(z.$$.fragment),le=a(),R=s("p"),R.textContent=Pe,he=a(),h(P.$$.fragment),ce=a(),H=s("p"),H.textContent=He,me=a(),h(S.$$.fragment),fe=a(),I=s("p"),I.innerHTML=Se,pe=a(),h(q.$$.fragment),ue=a(),A=s("p"),A.innerHTML=Ie,de=a(),h(D.$$.fragment),ge=a(),U=s("p"),U.textContent=qe,ve=a(),E=s("ul"),E.innerHTML=Ae,$e=a(),h(B.$$.fragment),ye=a(),V=s("p"),V.innerHTML=De,we=a(),h(F.$$.fragment),xe=a(),X=s("p"),X.innerHTML=Ue,Te=a(),O=s("p"),this.h()},l(e){const t=je("svelte-u9bgzb",document.head);g=r(t,"META",{name:!0,content:!0}),t.forEach(i),j=o(e),K=r(e,"P",{}),Ee(K).forEach(i),G=o(e),c(v.$$.fragment,e),W=o(e),c($.$$.fragment,e),Y=o(e),y=r(e,"P",{"data-svelte-h":!0}),l(y)!=="svelte-1xbb17w"&&(y.textContent=Ne),Z=o(e),c(w.$$.fragment,e),J=o(e),x=r(e,"P",{"data-svelte-h":!0}),l(x)!=="svelte-3zp0ah"&&(x.textContent=ke),Q=o(e),T=r(e,"UL",{"data-svelte-h":!0}),l(T)!=="svelte-1s2tcwi"&&(T.innerHTML=Le),ee=o(e),c(b.$$.fragment,e),te=o(e),C=r(e,"P",{"data-svelte-h":!0}),l(C)!=="svelte-x3eulp"&&(C.textContent=_e),ie=o(e),N=r(e,"UL",{"data-svelte-h":!0}),l(N)!=="svelte-2xgspu"&&(N.innerHTML=Me),ne=o(e),c(k.$$.fragment,e),ae=o(e),L=r(e,"P",{"data-svelte-h":!0}),l(L)!=="svelte-jme7tz"&&(L.textContent=ze),oe=o(e),c(_.$$.fragment,e),se=o(e),M=r(e,"P",{"data-svelte-h":!0}),l(M)!=="svelte-164n12x"&&(M.textContent=Re),re=o(e),c(z.$$.fragment,e),le=o(e),R=r(e,"P",{"data-svelte-h":!0}),l(R)!=="svelte-q3frac"&&(R.textContent=Pe),he=o(e),c(P.$$.fragment,e),ce=o(e),H=r(e,"P",{"data-svelte-h":!0}),l(H)!=="svelte-19t3tih"&&(H.textContent=He),me=o(e),c(S.$$.fragment,e),fe=o(e),I=r(e,"P",{"data-svelte-h":!0}),l(I)!=="svelte-k33cxv"&&(I.innerHTML=Se),pe=o(e),c(q.$$.fragment,e),ue=o(e),A=r(e,"P",{"data-svelte-h":!0}),l(A)!=="svelte-1aitck5"&&(A.innerHTML=Ie),de=o(e),c(D.$$.fragment,e),ge=o(e),U=r(e,"P",{"data-svelte-h":!0}),l(U)!=="svelte-1t3cn42"&&(U.textContent=qe),ve=o(e),E=r(e,"UL",{"data-svelte-h":!0}),l(E)!=="svelte-1404rzr"&&(E.innerHTML=Ae),$e=o(e),c(B.$$.fragment,e),ye=o(e),V=r(e,"P",{"data-svelte-h":!0}),l(V)!=="svelte-1dfpi5t"&&(V.innerHTML=De),we=o(e),c(F.$$.fragment,e),xe=o(e),X=r(e,"P",{"data-svelte-h":!0}),l(X)!=="svelte-15wicxb"&&(X.innerHTML=Ue),Te=o(e),O=r(e,"P",{}),Ee(O).forEach(i),this.h()},h(){Be(g,"name","hf:doc:metadata"),Be(g,"content",Ye)},m(e,t){Ge(document.head,g),n(e,j,t),n(e,K,t),n(e,G,t),m(v,e,t),n(e,W,t),m($,e,t),n(e,Y,t),n(e,y,t),n(e,Z,t),m(w,e,t),n(e,J,t),n(e,x,t),n(e,Q,t),n(e,T,t),n(e,ee,t),m(b,e,t),n(e,te,t),n(e,C,t),n(e,ie,t),n(e,N,t),n(e,ne,t),m(k,e,t),n(e,ae,t),n(e,L,t),n(e,oe,t),m(_,e,t),n(e,se,t),n(e,M,t),n(e,re,t),m(z,e,t),n(e,le,t),n(e,R,t),n(e,he,t),m(P,e,t),n(e,ce,t),n(e,H,t),n(e,me,t),m(S,e,t),n(e,fe,t),n(e,I,t),n(e,pe,t),m(q,e,t),n(e,ue,t),n(e,A,t),n(e,de,t),m(D,e,t),n(e,ge,t),n(e,U,t),n(e,ve,t),n(e,E,t),n(e,$e,t),m(B,e,t),n(e,ye,t),n(e,V,t),n(e,we,t),m(F,e,t),n(e,xe,t),n(e,X,t),n(e,Te,t),n(e,O,t),be=!0},p:Fe,i(e){be||(f(v.$$.fragment,e),f($.$$.fragment,e),f(w.$$.fragment,e),f(b.$$.fragment,e),f(k.$$.fragment,e),f(_.$$.fragment,e),f(z.$$.fragment,e),f(P.$$.fragment,e),f(S.$$.fragment,e),f(q.$$.fragment,e),f(D.$$.fragment,e),f(B.$$.fragment,e),f(F.$$.fragment,e),be=!0)},o(e){p(v.$$.fragment,e),p($.$$.fragment,e),p(w.$$.fragment,e),p(b.$$.fragment,e),p(k.$$.fragment,e),p(_.$$.fragment,e),p(z.$$.fragment,e),p(P.$$.fragment,e),p(S.$$.fragment,e),p(q.$$.fragment,e),p(D.$$.fragment,e),p(B.$$.fragment,e),p(F.$$.fragment,e),be=!1},d(e){e&&(i(j),i(K),i(G),i(W),i(Y),i(y),i(Z),i(J),i(x),i(Q),i(T),i(ee),i(te),i(C),i(ie),i(N),i(ne),i(ae),i(L),i(oe),i(se),i(M),i(re),i(le),i(R),i(he),i(ce),i(H),i(me),i(fe),i(I),i(pe),i(ue),i(A),i(de),i(ge),i(U),i(ve),i(E),i($e),i(ye),i(V),i(we),i(xe),i(X),i(Te),i(O)),i(g),u(v,e),u($,e),u(w,e),u(b,e),u(k,e),u(_,e),u(z,e),u(P,e),u(S,e),u(q,e),u(D,e),u(B,e),u(F,e)}}}const Ye='{"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 Ze(Ce){return Xe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class tt extends Ke{constructor(g){super(),Oe(this,g,Ze,We,Ve,{})}}export{tt as component};
