Giter Site home page Giter Site logo

level2-3-cv-finalproject-cv-07's Introduction

군중 계수(Crowd Counting) 모델의 계산 효율성을 위한 경량 모델링

모델링 대상

  • Transformer 기반의 군중 계수 SOTA 모델인 PET(Point-Query Quadtree for Crowd Counting, Localization, and More)모델

데이터셋

제공사항

  • 베이스 라인으로서 학습된 군중 계수 모델과 해당 모델을 학습 시킨 데이터 셋 제공
  • 모델 정확도 측정을 위한 도구 제공
  • 추론 속도 측정을 위한 도구 제공

수행사항

  • 모델을 구성하는 레이어, 합성곱 블록 등을 수정하여 베이스 라인 모델의 성능을 유지하면서 CPU/GPU에서의 추론 속도 개선

접근방법

  • 모델을 학습시키는 방법이 아닌 주어진 모델에 대한 구조 변경만을 허용함

기간

24.02.26 ~ 24.03.27

프로젝트 목표

Transformer 기반의 군중 계수 SOTA 모델인 PET (Chengxin Liu et al., ICCV 2023)모델을 구성하는 레이어/블록을 재설계하여 모델의 정확도(MAE(Mean Absolute Error))을 최대한 유지하면서도, CPU/GPU에서의 추론 속도를 개선

프로젝트 팀 구성 및 역할

김한규 민하은 이하연 심유승 안채연 강동기
  • 강동기: backbone의 영향이 낮은 layer 구조 변경, transformer의 encoder, decoder구조 개선 (1x1convolution, batch norm, layer감소)
  • 김한규: transformer의 encoder layer 구조 개선(FastViT)
  • 민하은: vgg13_bn backbone 교체, transformer의 encoder layer 구조 개선(poolformer)
  • 심유승: Encoder 블록 재설계 - 블록개수 최적화, window size 최적화, FFN 조정
  • 안채연 : vgg11_bn backbone교체, transformer의 encoder layer 구조 개선 (depthwise)
  • 이하연: mobilenet backbone 교체, encoder progressive window size 변경, transformer의 encoder, decoder Parameters sharing, transformer의 encoder layer 구조 개선 (poolformer)

설치 및 실행

git clone https://github.com/boostcampaitech6/level2-3-cv-finalproject-cv-07.git
cd level2-3-cv-finalproject-cv-07
mkdir data
# https://paperswithcode.com/dataset/shanghaitech - ShanghaiTech A 데이터 다운로드 후 data 디렉토리에 넣기

pip install -r requirements.txt

# train 시
sh ./train.sh
# transformer 다른 메소드로 변경 시
# ./models/transformer/__init__.py 에 from .prog_win_transformer import build_encoder, build_decoder 해당 부분 변경

# eval 시
sh ./evel.sh

🛠️Methodology

Backbone 경량화

Untitled
  • Backbone 교체: mobilenet_v3, vgg11_bn, vgg13_bn
  • Backbone layer 제거: 비중이 낮은 Batchnorm layer를 선별, 제거

Encoder 경량화

  1. PoolFormer
image
  • PET의 Encoder에 self attention 연산을 pooling으로 대체
  • 연산을 효율적으로 계산, token mixer 역할 수행
  • cross-channel pooling을 사용해 여러 feature map 간 정보 통합
  1. Depthwise
스크린샷 2024-03-27 오후 12 30 54
  • Poolformer 사용 시 성능 하락 보완하기 위해 depthwise convolution 사용
  • 지연 시간 오버헤드 도입하지 않으면서 성능 향상
  1. Component 재설계
스크린샷 2024-03-27 오후 12 39 12
  • encoder block 개수 최적화
  • window size 최적화
  • FFN 조정

Encoder, Decoder 경량화

스크린샷 2024-03-27 오후 12 33 55
  • encoder, decoder의 linear layer, layer norm 간소화
  • Linear layer를 1x1 convolution으로 대체
  • Feed froward network 조정

TOP 3

Mae 측면

실험명 Best MAE Inference time
encoder reduction encoder layer X 2 + [(32,16),(8,4)] 약 6.22% 감소(50.49→47.35) 6.92ms 감소(63.95→57.03)
poolformer Enc win size  1/4 + attnX2-> poolingX2 약 0.30% 감소(50.13→49.98) 5.6ms 감소(63.95→58.35)
depthwise depthwise encoder layer 1개 [(8,4)] 약 0.02% 증가(52.39 → 52.4) 8.29ms 감소(65.62 → 57.33)

Inference 측면

실험명 Best MAE Inference time
encoder reduction encoder layer X 2 + [(32,16),(8,4)]• ffn 제거 약 1.78% 증가 (50.49→51.39) 9.19ms 감소 (63.95→54.76)
poolformer layer reduction + pooling(X2) [(32,16),(8,4)] 약 6.98% 증가 (50.13→53.63) 6.98ms 감소 (63.95→56.97)
depthwise depthX1_attnX1 약 2.04% 증가 (52.39 → 53.46) 9.27ms 감소 (63.95 → 54.68)

최종 모델

pet_A our_model

  1. encoder layer를 4개에서 2개로 감소
  2. Encoder window size를 [(32,16),(16,8)] 에서 [(32,16),(8,4)]로 변경
  3. 인코더 및 디코더에서 FFN을 제거
실험명 Best MAE Inference time
encoder reduction encoder layer X 2 + [(32,16),(8,4)] + ffn 제거 약 1.78% 증가 (50.49→51.39) 9.19ms 감소 (63.95→54.76)

mae 측면에서 성능하락이 1.78% 수준이며 inference time은 9.19ms 대폭 감소하였기에

mae와 inference time 측면 모두에서 top 3의 수준을 기록하였다.

mae : 51.39 inference time 54.76ms로 최종 모델로 선정 되었다.

Citataion

If you find this work helpful for your research, please consider citing:

@InProceedings{liu2023pet,
  title={Point-Query Quadtree for Crowd Counting, Localization, and More},
  author={Liu, Chengxin and Lu, Hao and Cao, Zhiguo and Liu, Tongliang},
  booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV)},
  year={2023}
}

References

  1. Liu, Chengxin, et al. "Point-query quadtree for crowd counting, localization, and more."
  2. Yanyu Li, Ju Hu, et al. "Rethinking Vision Transformers for MobileNet Size and Speed."
  3. Howard, Andrew, et al. "Searching for mobilenetv3."
  4. Liu, Chengxin, et al. "Point-query quadtree for crowd counting, localization, and more."
  5. Yu, Weihao, et al. "MetaFormer Is Actually What You Need for Vision"
  6. Li, Yanyu, et al. "Efficientformer: Vision transformers at mobilenet speed."

level2-3-cv-finalproject-cv-07's People

Contributors

hayeonlee88 avatar haeun1 avatar chyeon01 avatar dorianyellow avatar kimhankyu avatar github-classroom[bot] avatar

Forkers

hayeonlee88

level2-3-cv-finalproject-cv-07's Issues

:bug: fix : init.sh 실행시 commit template 설정 오류

증상

  • init.sh 스크립트 실행시 key가 -global을 포함하지 않는다는 에러가 발생합니다.
  • global과 wait 앞을 아래와 같이 수정해주세요.
git config --global commit.template ./.commit_template
git config --global core.editor "code --wait"

재현 방법

init.sh 스크립트를 실행합니다.

bash init.sh

스크린샷

스크린샷 2024-02-29 오후 5 25 32

기대하는 결과

  • commit template 설정이 완료되고, pre-commit 설정이 완료됩니다.

로그

error: key does not contain a section: —global
error: key does not contain a section: —global
Fin git config
Requirement already satisfied: pre-commit in /opt/conda/lib/python3.10/site-packages (3.6.2)
Requirement already satisfied: cfgv>=2.0.0 in /opt/conda/lib/python3.10/site-packages (from pre-commit) (3.4.0)
Requirement already satisfied: identify>=1.0.0 in /opt/conda/lib/python3.10/site-packages (from pre-commit) (2.5.35)
Requirement already satisfied: nodeenv>=0.11.1 in /opt/conda/lib/python3.10/site-packages (from pre-commit) (1.8.0)
Requirement already satisfied: pyyaml>=5.1 in /opt/conda/lib/python3.10/site-packages (from pre-commit) (6.0)
Requirement already satisfied: virtualenv>=20.10.0 in /opt/conda/lib/python3.10/site-packages (from pre-commit) (20.25.0)
Requirement already satisfied: setuptools in /opt/conda/lib/python3.10/site-packages (from nodeenv>=0.11.1->pre-commit) (60.2.0)
Requirement already satisfied: distlib<1,>=0.3.7 in /opt/conda/lib/python3.10/site-packages (from virtualenv>=20.10.0->pre-commit) (0.3.8)
Requirement already satisfied: filelock<4,>=3.12.2 in /opt/conda/lib/python3.10/site-packages (from virtualenv>=20.10.0->pre-commit) (3.13.1)
Requirement already satisfied: platformdirs<5,>=3.9.1 in /opt/conda/lib/python3.10/site-packages (from virtualenv>=20.10.0->pre-commit) (4.2.0)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[https://github.com/pre-commit/pre-commit-hooks] already up to date!
[https://github.com/psf/black] already up to date!
pre-commit installed at .git/hooks/pre-commit

:sparkles: feat : Depthwise 추가

내용

  • 기존 Transformer encoder에 사용되는 self-attn을 depthwise로 부분 또는 전체를 교체하여 사용할 수 있도록 구현
  • Poolformer로 교체한 실험과 같이 reshape을 적용

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.