KR260으로 ResNet18 돌려보기

KiJungKong·2024년 6월 30일
0
post-thumbnail

ImageNet Dataset으로 사전 학습된 ResNet18을 CIFAR10 Dataset으로 fine-tune하고 또 quantization해서 kr260으로 컴파일해야된다

이하 내용은 quantization까지 끝마친 확장자가 h5인 모델 파일이 존재할 경우를 상정하여 kr260용으로 컴파일 해서 실행하는것까지만 서술한다.

참고: 4 Test PYNQ DPU with Python or C++ VART APIs

vitis-ai에 접속한다.

❯ vitis-ai # aliased to cd /home/kiyoshi/works/AMD/Vitis-AI; ./docker_run.sh xilinx/vitis-ai-tensorflow2-gpu:latest

==========
== CUDA ==
==========

CUDA Version 11.8.0

Container image Copyright (c) 2016-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.

This container image and its contents are governed by the NVIDIA Deep Learning Container License.
By pulling and using the container, you accept the terms and conditions of this license:
https://developer.nvidia.com/ngc/nvidia-deep-learning-container-license

A copy of this license is made available in this container at /NGC-DL-CONTAINER-LICENSE for your convenience.

Setting up 유저 이름 's environment in the Docker container...
usermod: no changes
Running as vitis-ai-user with ID 0 and group 0


==========================================

__      ___ _   _                   _____
\ \    / (_) | (_)            /\   |_   _|
 \ \  / / _| |_ _ ___ ______ /  \    | |
  \ \/ / | | __| / __|______/ /\ \   | |
   \  /  | | |_| \__ \     / ____ \ _| |_
    \/   |_|\__|_|___/    /_/    \_\_____|

==========================================

Docker Image Version: 3.5.0.001-cc6f2308a   (GPU)
Vitis AI Git Hash: cc6f2308a
Build Date: 2024-01-13
WorkFlow: tf2

vitis-ai-user@유저 이름:/workspace$

Kria-RoboticsAI 레포지토리를 git clone 한다.

git clone https://github.com/amd/Kria-RoboticsAI.git
cd Kria-RoboticsAI/files/cifar10_tf2

cifar10 테스트 이미지를 다운로드하는 파이썬 스크립트를 실행한다.

conda activate vitis-ai-tensorflow2
python cifar10_generate_images.py

모델을 컴파일하는 쉘 스크립트도 실행한다.

bash -x ./vitisai_compile.sh  kr260  ./quantized/q_resnet18_cifar10.h5     ./compiled   kr260_cifar10_tf2_resnet18

kr260에 접속한 후 vitis-ai의 공유 폴더인 /workspace가 실제로 위치하는 WSL내에서의 경로를 고려하여 cifar10_tf2폴더를 kria로 다운받는다.

scp -r -P 31000 {이름}@{호스트이름 또는 ip}:~/works/AMD/Vitis-AI/Kria-RoboticsAI/files/cifar10_tf2 .

실행한다.

pynq-venv # aliased to source /etc/profile.d/pynq_venv.sh
python app_cifar10_tf2_resnet18.py

실행하면 이런 에러가 발생한다

ResNet18 CNN (pre-trained with ImageNet Dataset) fine-tuned to CIFAR10 Dataset, in TensorFlow2

shapeIn   : (1, 32, 32, 3)
shapeOut  : (1, 1, 1, 10)
outputSize: 10
Classifying 5000 CIFAR10 pictures ...
WARNING: Logging before InitGoogleLogging() is written to STDERR
W0630 04:35:03.450374  6294 dpu_runner_base_imp.cpp:676] CHECK fingerprint fail ! model_fingerprint 0x101000056010407 dpu_fingerprint 0x101000016010407
F0630 04:35:03.450474  6294 dpu_runner_base_imp.cpp:648] fingerprint check failure.
*** Check failure stack trace: ***
[1]    6294 abort (core dumped)  python app_cifar10_tf2_resnet18.py

model_fingerprint와 dpu_fingerprint와 일치하지 않아서 생기는 문제이다.

이를 해결하기 위해서는 /opt/vitis-ai/compiler/arch/dpu이름/kv260(kr260과 자매품이라 호환됨) 안에 있는 arch.json을 수정해도 되는데 귀찮으니 새로운 kr260.json을 만들고 (참고: https://github.com/Xilinx/Vitis-AI/issues/263)

kr260.json의 내용

{
  "fingerprint": "0x101000016010407"
}

vai_c_tensorflow2를 이와 같이 매개변수를 넣어 실행한다.

vai_c_tensorflow2 \
  --model ./quantized/q_resnet18_cifar10.h5 \
  --arch  ./kr260.json \
  --output_dir ./compiled\
  --net_name kr260_cifar10_tf2_resnet18 \
  2>&1 | tee log

그리고 kr260에 이전에 설명한 방법대로 다시 다운로드 받아서 실행하면

❯ python app_cifar10_tf2_resnet18.py

ResNet18 CNN (pre-trained with ImageNet Dataset) fine-tuned to CIFAR10 Dataset, in TensorFlow2

shapeIn   : (1, 32, 32, 3)
shapeOut  : (1, 1, 1, 10)
outputSize: 10
Classifying 5000 CIFAR10 pictures ...
  Execution time: 13.3660s
      Throughput: 374.0843FPS
Overall accuracy: 0.8486
number of top1 false predictions  757
number of top1 right predictions  4243
top1 accuracy = 0.8486

다음과 같은 결과가 나온다.

profile
공기정

0개의 댓글

관련 채용 정보