run_all.sh

SungchulCHA·2024년 2월 29일

AMD DL

목록 보기
10/12

CIFAR10

run_cifar10_training()

# ===========================================================================
# STEP3: Train ResNet18 CNNs on CIFAR10
# ===========================================================================
run_cifar10_training(){
# floating point model training
echo " "
echo "----------------------------------------------------------------------------------"
echo "[DB INFO STEP3A] CIFAR10 TRAINING (way 1)"
echo "----------------------------------------------------------------------------------"
echo " "
python ./code/train1_resnet18_cifar10.py --epochs 50 | tee ./build/log/train1_resnet18_cifar10.log
mv ./build/float/train1_best_chkpt.h5 ./build/float/train1_resnet18_cifar10_best.h5
mv ./build/float/train1_final.h5      ./build/float/train1_resnet18_cifar10_final.h5

echo " "
echo "----------------------------------------------------------------------------------"
echo "[DB INFO STEP3B] CIFAR10 TRAINING (way 2)"
echo "----------------------------------------------------------------------------------"
echo " "
python ./code/train2_resnet18_cifar10.py --epochs 50 | tee ./build/log/train2_resnet18_cifar10.log

}

code 폴더의 train1_resnet18_cifar10.py를 파이썬으로 실행, epochs에는 50을 주고,
해당 결과를 build/log 안의 train1_resnet18_cifar10.log 파일로 저장
build/float 안의
train1_best_chkpt.h5 모델을 train1_resnet18_cifar10_best.h5 모델로 이름 변경
train1_final.h5 모델을 train1_resnet18_cifar10_final.h5 모델로 이름 변경

code 폴더안의 train2_resnet18_cifar10.py를 파이썬으로 실행, epochs 50 주고,
결과는 build/log 안의 train2_resnet18_cifar10.log 파일로 저장

quantize_resnet18_cifar10()

# ===========================================================================
# STEP4: Vitis AI Quantization of ResNet18 on CIFAR10
# ===========================================================================
quantize_resnet18_cifar10(){
echo " "
echo "----------------------------------------------------------------------------------"
echo "[DB INFO STEP4A] QUANTIZE CIFAR10 TRAINED CNN1 MODELS"
echo "----------------------------------------------------------------------------------"
echo " "
echo "[DB INFO STEP4A-1] MODEL INSPECTION"
echo " "
python  ./code/inspect_resnet18_cifar10.py --float_file ./build/float/train1_resnet18_cifar10_final.h5
mv build/log/inspect_results.txt build/log/inspect_results_train1_resnet18_cifar10_final.txt
mv build/log/model.svg build/log/model_train1_resnet18_cifar10_final.svg
echo " "
echo "[DB INFO STEP4A-2] EFFECTIVE QUANTIZATION OF FINAL-CNN1 MODEL"
echo " "
python  ./code/vai_q_resnet18_cifar10.py   --float_file ./build/float/train1_resnet18_cifar10_final.h5 --quant_file ./build/quantized/q_train1_resnet18_cifar10_final.h5
echo " "
echo "[DB INFO STEP4A-3] EFFECTIVE QUANTIZATION OF BEST-CNN1 MODEL"
echo " "
python  ./code/vai_q_resnet18_cifar10.py   --float_file ./build/float/train1_resnet18_cifar10_best.h5  --quant_file ./build/quantized/q_train1_resnet18_cifar10_best.h5
echo " "
echo "----------------------------------------------------------------------------------"
echo "[DB INFO STEP4B] QUANTIZE CIFAR10 TRAINED CNN2 MODEL"
echo "----------------------------------------------------------------------------------"
echo " "
echo "[DB INFO STEP4B-1] MODEL INSPECTION"
echo " "
python  ./code/inspect_resnet18_cifar10.py --float_file ./build/float/train2_resnet18_cifar10_float.h5
mv build/log/inspect_results.txt build/log/inspect_results_train2_resnet18_cifar10_float.txt
mv build/log/model.svg           build/log/model_train2_resnet18_cifar10_float.svg
echo " "
echo "[DB INFO STEP4B-2] EFFECTIVE QUANTIZATION"
echo " "
python  ./code/vai_q_resnet18_cifar10.py   --float_file ./build/float/train2_resnet18_cifar10_float.h5 --quant_file ./build/quantized/q_train2_resnet18_cifar10.h5

}

code 폴더 안의 inspect_resnet18_cifar10.py를 파이썬으로 실행,
float_file 인자에 build/float 안의 train1_resnet18_cifar10_final.h5 모델을 줌
build/log 안에서
inspect_results.txt 파일을 inspect_results_train1_resnet18_cifar10_final.txt 로 이름 변경
model.svg 파일을 model_train1_resnet18_cifar10_final.svg 파일로 이름 변경

code 폴더 안의
vai_q_resnet18_cifar10.py 실행,
float_file 인자로 train1_resnet18_cifar10_final.h5 입력
float_file 인자로 train1_resnet18_cifar10_best.h5를 주고 다시 실행

inspect_resnet18_cifar10.py
train2_resnet18_cifar10_float.h5를 float_file 인자로 주고 실행
build/log 안에서
inspect_results.txt 파일을 inspect_results_train2_resnet18_cifar10_float.txt 파일로 이름 변경
model.svg 파일을 model_train2_resnet18_cifar10_float.svg 파일로 이름 변경

vai_q_resnet18_cifar10.py 파일의 float_file 인자로
train2_resnet18_cifar10_float.h5 주고 실행

compile_resnet18_cifar10()

# ===========================================================================
# STEP5: Vitis AI Compile ResNet18 CIFAR10 for Target Board
# ===========================================================================
compile_resnet18_cifar10(){
#train1
echo " "
echo "----------------------------------------------------------------------------------"
echo "[DB INFO STEP5A] COMPILE CIFAR10 QUANTIZED CNN1 MODEL"
echo "----------------------------------------------------------------------------------"
echo " "
source ./scripts/run_compile.sh zcu102  q_train1_resnet18_cifar10_final.h5
source ./scripts/run_compile.sh vck190  q_train1_resnet18_cifar10_final.h5
source ./scripts/run_compile.sh vek280  q_train1_resnet18_cifar10_final.h5
source ./scripts/run_compile.sh vck5000 q_train1_resnet18_cifar10_final.h5
source ./scripts/run_compile.sh v70     q_train1_resnet18_cifar10_final.h5

mv   ./build/compiled_zcu102/zcu102_q_train1_resnet18_cifar10_final.h5.xmodel  ./target/cifar10/zcu102_train1_resnet18_cifar10.xmodel
mv   ./build/compiled_vck190/vck190_q_train1_resnet18_cifar10_final.h5.xmodel  ./target/cifar10/vck190_train1_resnet18_cifar10.xmodel
mv   ./build/compiled_vek280/vek280_q_train1_resnet18_cifar10_final.h5.xmodel  ./target/cifar10/vek280_train1_resnet18_cifar10.xmodel
mv   ./build/compiled_v70/v70_q_train1_resnet18_cifar10_final.h5.xmodel        ./target/cifar10/v70_train1_resnet18_cifar10.xmodel
mv ./build/compiled_vck5000/vck5000_q_train1_resnet18_cifar10_final.h5.xmodel  ./target/cifar10/vck5000_train1_resnet18_cifar10.xmodel

#train2
echo " "
echo "----------------------------------------------------------------------------------"
echo "[DB INFO STEP5B] COMPILE CIFAR10 QUANTIZED CNN2 MODEL"
echo "----------------------------------------------------------------------------------"
echo " "
source ./scripts/run_compile.sh zcu102  q_train2_resnet18_cifar10.h5
source ./scripts/run_compile.sh vck190  q_train2_resnet18_cifar10.h5
source ./scripts/run_compile.sh vek280  q_train2_resnet18_cifar10.h5
source ./scripts/run_compile.sh vck5000 q_train2_resnet18_cifar10.h5
source ./scripts/run_compile.sh v70     q_train2_resnet18_cifar10.h5

mv   ./build/compiled_zcu102/zcu102_q_train2_resnet18_cifar10.h5.xmodel  ./target/cifar10/zcu102_train2_resnet18_cifar10.xmodel
mv   ./build/compiled_vck190/vck190_q_train2_resnet18_cifar10.h5.xmodel  ./target/cifar10/vck190_train2_resnet18_cifar10.xmodel
mv   ./build/compiled_vek280/vek280_q_train2_resnet18_cifar10.h5.xmodel  ./target/cifar10/vek280_train2_resnet18_cifar10.xmodel
mv ./build/compiled_vck5000/vck5000_q_train2_resnet18_cifar10.h5.xmodel  ./target/cifar10/vck5000_train2_resnet18_cifar10.xmodel
mv         ./build/compiled_v70/v70_q_train2_resnet18_cifar10.h5.xmodel  ./target/cifar10/v70_train2_resnet18_cifar10.xmodel

}

scripts 폴더의 run_compile.sh 에 첫 번째 인자로 <target board>,
두 번째 인자로 q_train1_resnet18_cifar10_final.h5 주고 실행

build 폴더 하위에 생성되는 compiled_<target board> 폴더에서
<target board>_q_train1_resnet18_cifar10_final.h5.xmodle 파일을
target/cifar10 에 <target board>_train1_resnet18_cifar10.xmodel 로 이동

똑같이 train2로 제작

prepare_cifar10_archives()

# ===========================================================================
# STEP6: prepare archive for TARGET ZCU102 runtime application for CIFAR10
# ===========================================================================
prepare_cifar10_archives() {
echo " "
echo "----------------------------------------------------------------------------------"
echo "[DB INFO STEP6] PREPARING CIFAR10 ARCHIVE FOR TARGET BOARDS"
echo "----------------------------------------------------------------------------------"
echo " "
cp -r target       ./build
cd ./build/dataset/cifar10
tar -cvf test.tar ./test > /dev/null
cp test.tar       ../../../build/target/cifar10/
rm test.tar
cd ../../../
rm -rf ./build/target/imagenet #unuseful at the moment
# zcu102
cp -r ./build/target/  ./build/target_zcu102  > /dev/null
rm -f ./build/target_zcu102/cifar10/vck*_cifar10.xmodel
rm -f ./build/target_zcu102/cifar10/vek*_cifar10.xmodel
rm -f ./build/target_zcu102/cifar10/v70*_cifar10.xmodel
# vck190
cp -r ./build/target/  ./build/target_vck190  > /dev/null
rm -f ./build/target_vck190/cifar10/zcu1*_cifar10.xmodel
rm -f ./build/target_vck190/cifar10/vek2*_cifar10.xmodel
rm -f ./build/target_vck190/cifar10/vck5*_cifar10.xmodel
rm -f ./build/target_vck190/cifar10/v70*_cifar10.xmodel
# vek280
cp -r ./build/target   ./build/target_vek280  > /dev/null
rm -f ./build/target_vek280/cifar10/zcu*_cifar10.xmodel
rm -f ./build/target_vek280/cifar10/vck*_cifar10.xmodel
rm -f ./build/target_vek280/cifar10/v70*_cifar10.xmodel
# vck5000
cp -r ./build/target/  ./build/target_vck5000  > /dev/null
rm -f ./build/target_vck5000/cifar10/zcu1*_cifar10.xmodel
rm -f ./build/target_vck5000/cifar10/vek2*_cifar10.xmodel
rm -f ./build/target_vck5000/cifar10/vck1*_cifar10.xmodel
rm -f ./build/target_vck5000/cifar10/v70*_cifar10.xmodel
# v70
cp -r ./build/target/  ./build/target_v70  > /dev/null
rm -f ./build/target_v70/cifar10/zcu1*_cifar10.xmodel
rm -f ./build/target_v70/cifar10/vek2*_cifar10.xmodel
rm -f ./build/target_v70/cifar10/vck*_cifar10.xmodel

echo " Complete "
}

-r : recursive. 재귀적으로 반복
/home/tony/Desktop/Vitis-AI/tutorials/RESNET18/files 경로의 target 폴더 전체를 build로 copy
build/dataset/cifar10 으로 이동 후
test.tar 를 test 폴더로 압축 해제 + dev/null/에도 압축 해제
test.tar 압축 파일을 build/target/cifar10 으로 copy
build/dataset/cifar10 에 있는 test.tar 삭제
build/target/imagenet 폴더의 하위 폴더까지 전체 삭제

build 하위의 target 폴더를 target_<target board> 로 바꿔서 하나 더 만듦, dev/null에도 생성
새로 만든 build/target_<target board> 폴더 하위에 cifar10/<target board>_cifar10.xmodel 파일 삭제


ImageNet

prepare_imagenet_test_images()

 =================================================================================================
# STEP7 (1): prepare imagenet test images: you must have downloaded ILSVRC2012_img_val.tar already
# =================================================================================================
ARCHIVE=./files/modelzoo/ImageNet/ILSVRC2012_img_val.tar
prepare_imagenet_test_images(){

if [ -f "$ARCHIVE" ]; then
  echo "ERROR! $ARCHIVE does exist: you have to download it"
else
  cd ./modelzoo/ImageNet/
  mkdir -p val_dataset
  # expand the archive
  echo "expanding ILSVRC2012_img_val.tar archive"
  tar -xvf ILSVRC2012_img_val.tar -C ./val_dataset > /dev/null
  ls -l ./val_dataset | wc
  python3 imagenet_val_dataset.py
  cd ../..
  # copy the archive to the ``target/imagenet`` folder
  cp ./modelzoo/ImageNet/val_dataset.zip ./target/imagenet
  cd ./target/imagenet/
  unzip -o -q val_dataset.zip #unzip forcing overwrite in quiet mode
  cd ../../
fi
}

ARCHIVE 변수에 ILSVRC2012_img_val.tar 파일 경로 설정

if문 구조

if [ 조건 ]; then
# 조건이 참일 때 실행할 명령어들
else
# 조건이 거짓일 때 실행할 명령어들
fi

-f : 파일이 존재하며 정규 파일이면 true 반환, 없으면 false 반한
파일이 없으면,
modelzoo/ImageNet 에 가서 val_dataset 폴더 생성
-p : 중간 경로가 없으면 해당 경로의 폴더들도 생성
val_dataset 폴더로 ILSVRC2012_img_val.tar 파일 압축 헤제 + /dev/null 에도 생성
ls -l : val_dataset 을 long format으로 나타내는데,
wc : 단어, 라인, 문자 수 등을 세어서 해당 부분만 출력
imagenet_val_dataset.py 를 python3로 실행
modelzoo/ImageNet/val_dataset.zip 파일을 target/imagenet 폴더로 copy 후 해당 디렉토리로 이동
unzip -o -q : overwrite, quiet. 에러 메세지만 출력

quantize_resnet50_imagenet()

# ===========================================================================
# STEP7 (2): Vitis AI Quantization of ResNet50 on ImageNet
# ===========================================================================
quantize_resnet50_imagenet(){
echo " "
echo "----------------------------------------------------------------------------------"
echo "[DB INFO STEP7] IMAGENET RESNET50: EVALUATE & QUANTIZE"
echo "YOU SHOULD HAVE ALREADY DOWNLOADED tf2_resnet50_3.5.zip ARCHIVE"
echo "----------------------------------------------------------------------------------"
echo " "
DIRECTORY1=./files/modelzoo/tf2_resnet50_3.5

if [ -d "$DIRECTORY1" ]; then
    echo "ERROR! $DIRECTORY1 does exist: cannot evaluate ResNet50 CNN!"
else
    python  ./code/eval_resnet50.py
fi
}

DIRECTORY1 변수에 tf2_resnet50_3.5 모델 위치 넣고
-d : 디렉토리가 존재하면 true, 없으면 false 반환
없으면 code 안에 eval_resnet50.py 파일 python으로 실행

quantize_resnet18_imagenet()

# ===========================================================================
# STEP8: Vitis AI Quantization of ResNet18 on ImageNet
# ===========================================================================
quantize_resnet18_imagenet(){
echo " "
echo "----------------------------------------------------------------------------------"
echo "[DB INFO STEP8] IMAGENET RESNET18: EVALUATE & QUANTIZE"
echo "----------------------------------------------------------------------------------"
echo " "
python  ./code/eval_resnet18.py
}

code 안에 eval_resnet18.py 실행

compile_resnet50_imagenet()

# ===========================================================================
# STEP9: Vitis AI Compile ResNet50 Imagenet Target Board
# ===========================================================================
compile_resnet50_imagenet(){
#train1
echo " "
echo "----------------------------------------------------------------------------------"
echo "[DB INFO STEP9] COMPILE IMAGENET QUANTIZED RESNET50"
echo "----------------------------------------------------------------------------------"
echo " "
source ./scripts/run_compile.sh zcu102  q_resnet50_imagenet.h5
source ./scripts/run_compile.sh vck190  q_resnet50_imagenet.h5
source ./scripts/run_compile.sh vek280  q_resnet50_imagenet.h5
source ./scripts/run_compile.sh vck5000 q_resnet50_imagenet.h5
source ./scripts/run_compile.sh v70     q_resnet50_imagenet.h5
mv   ./build/compiled_zcu102/zcu102_q_resnet50_imagenet.h5.xmodel  ./target/imagenet/zcu102_resnet50_imagenet.xmodel
mv   ./build/compiled_vck190/vck190_q_resnet50_imagenet.h5.xmodel  ./target/imagenet/vck190_resnet50_imagenet.xmodel
mv   ./build/compiled_vek280/vek280_q_resnet50_imagenet.h5.xmodel  ./target/imagenet/vek280_resnet50_imagenet.xmodel
mv ./build/compiled_vck5000/vck5000_q_resnet50_imagenet.h5.xmodel  ./target/imagenet/vck5000_resnet50_imagenet.xmodel
mv     ./build/compiled_v70/v70_q_resnet50_imagenet.h5.xmodel      ./target/imagenet/v70_resnet50_imagenet.xmodel
}

scripts 폴더의 run_compile.sh 스크립트 실행하는데 첫 번째 인자로 <target board>,
두 번째 인자로 q_resnet50_imagenet.h5 파일 전달

build 폴더에 compiled_<target board> 경로에 있는 <target board>_q_resnet50_imagenet.h5.xmodel 파일을
target/imagenet 경로에 <target board>_resnet50_imagenet.xmodel 파일로 이동

compile_resnet18_imagenet()

# ===========================================================================
# STEP10: Vitis AI Compile ResNet18 Imagenet Target Board
# ===========================================================================
compile_resnet18_imagenet(){
#train1
echo " "
echo "----------------------------------------------------------------------------------"
echo "[DB INFO STEP10] COMPILE IMAGENET QUANTIZED RESNET18"
echo "----------------------------------------------------------------------------------"
echo " "
source ./scripts/run_compile.sh zcu102  q_resnet18_imagenet.h5
source ./scripts/run_compile.sh vck190  q_resnet18_imagenet.h5
source ./scripts/run_compile.sh vek280  q_resnet18_imagenet.h5
source ./scripts/run_compile.sh vck5000 q_resnet18_imagenet.h5
source ./scripts/run_compile.sh v70     q_resnet18_imagenet.h5
mv   ./build/compiled_zcu102/zcu102_q_resnet18_imagenet.h5.xmodel  ./target/imagenet/zcu102_resnet18_imagenet.xmodel
mv   ./build/compiled_vck190/vck190_q_resnet18_imagenet.h5.xmodel  ./target/imagenet/vck190_resnet18_imagenet.xmodel
mv   ./build/compiled_vek280/vek280_q_resnet18_imagenet.h5.xmodel  ./target/imagenet/vek280_resnet18_imagenet.xmodel
mv ./build/compiled_vck5000/vck5000_q_resnet18_imagenet.h5.xmodel  ./target/imagenet/vck5000_resnet18_imagenet.xmodel
mv         ./build/compiled_v70/v70_q_resnet18_imagenet.h5.xmodel  ./target/imagenet/v70_resnet18_imagenet.xmodel
}

resnet18 파일들 가지고 동일하게 실행

prepare_imagenet_archives()

# ===========================================================================
# STEP11: prepare archive for TARGET runtime application for ImageNet
# ===========================================================================
prepare_imagenet_archives() {
echo " "
echo "----------------------------------------------------------------------------------"
echo "[DB INFO STEP11] PREPARING IMAGENET ARCHIVE FOR TARGET BOARDS"
echo "----------------------------------------------------------------------------------"
echo " "
if [ -d "./build/target" ]; then
  ### CIFAR10 was running before this and you have to do nothing
  echo "./build/target exists already ..."
else
  ### CIFAR10 was not called before this and you have to build some folders
  echo "./build/target does not exists ..."
  mkdir -p ./build/target
  mkdir -p ./build/target_vck190
  mkdir -p ./build/target_vck5000
  mkdir -p ./build/target_vek280
  mkdir -p ./build/target_zcu102
  mkdir -p ./build/target_v70
fi
cp -r ./target/imagenet ./build/target/
# zcu102
cp -r ./build/target/imagenet ./build/target_zcu102/
rm -f ./build/target_zcu102/imagenet/vck*_imagenet.xmodel
rm -f ./build/target_zcu102/imagenet/vek*_imagenet.xmodel
# vck190
cp -r ./build/target/imagenet ./build/target_vck190/
rm -f ./build/target_vck190/imagenet/zcu1*_imagenet.xmodel
rm -f ./build/target_vck190/imagenet/vek2*_imagenet.xmodel
rm -f ./build/target_vck190/imagenet/vck5*_imagenet.xmodel
# vek280
cp -r ./build/target/imagenet ./build/target_vek280/
rm -f ./build/target_vek280/imagenet/zcu*_imagenet.xmodel
rm -f ./build/target_vek280/imagenet/vck*_imagenet.xmodel
# vck5000
cp -r ./build/target/imagenet ./build/target_vck5000/
rm -f ./build/target_vck5000/imagenet/zcu1*_imagenet.xmodel
rm -f ./build/target_vck5000/imagenet/vek2*_imagenet.xmodel
rm -f ./build/target_vck5000/imagenet/vck1*_imagenet.xmodel
# v700
cp -r ./build/target/imagenet ./build/target_v70/
rm -f ./build/target_v70/imagenet/zcu1*_imagenet.xmodel
rm -f ./build/target_v70/imagenet/vek2*_imagenet.xmodel
rm -f ./build/target_v70/imagenet/vck*_imagenet.xmodel

# prerare tar files
cd ./build
tar -cvf  target_zcu102.tar  ./target_zcu102 > /dev/null
tar -cvf  target_vck190.tar  ./target_vck190 > /dev/null
tar -cvf  target_vek280.tar  ./target_vek280 > /dev/null
tar -cvf  target_vck5000.tar ./target_vck5000 > /dev/null
tar -cvf  target_v70.tar     ./target_v70 > /dev/null
#rm -r target
cd ..
}

build/target 디렉토리 있는지 확인하고 없으면,
build/target, build/target_<target board> 폴더를 중간 폴더까지 생성

target/imagenet 의 하위폴더까지 build/target 으로 복사
build/target/imagenet 의 하위 폴더까지 build/target_<target board> 로 복사
build/target_<target board>/imagenet/<dpu>*_imagenet.xmodel 삭제

target boarddpu
zcu102vck, vek
vck190zcu1, vek2, vck5
vek280zcu, vck
vck5000zcu1, vek2, vck1
v700zcu1, vek2, vck

build 로 가서
<target board>.tar 파일을 <target board> 폴더로 압축 해제, /dev/null 에도 같이

다시 위치 원상복귀 (/home/tony/Desktop/Vitis-AI/tutorials/RESNET18/files)


쩌리(?) 들

run_patch()

# ===========================================================================
# patch
# ===========================================================================
run_patch(){
tar -xvf patch.tar.gz
cd patch
source ./run_patch.sh
cd ..
}

patch.tar.gz 파일을 압축 해제 ← -zxvf 로 해야 할듯
patch 로 이동, run_patch.sh 실행

prepare_logfile()

# ===========================================================================
# remove redundant information from host logfile
# ===========================================================================
LOG_FILENAME=$2
prepare_logfile(){
  #cat  logfile_resnet18_cifar10.txt logfile3_resnet18_cifar10.txt > logfile0_resnet18_cifar10.txt
  #mv logfile0_resnet18_cifar10.txt logfile_resnet18_cifar10.txt
  dos2unix -f ${LOG_FILENAME} #logfile_run_all_7apr2023.txt
  cat ${LOG_FILENAME}  | grep -v "loss: " | tee prova1.txt
  cat prova1.txt | grep -v "100%|" | tee prova2.txt
  cat prova2.txt | grep -v "ETA: " | tee prova3.txt
  cat ./doc/header.txt prova3.txt > logfile_host.txt
  rm -f prova*.txt
}

$2 : 스크립트에 전달되는 두 번재 인자
cat : concatenate. 파일을 연결 또는 파일을 출력
> : redirection. 명령어의 출력을 파일에 작성
dos2unix : 윈도우 파일의 줄바꿈 형식을 유닉스나 리눅스 용으로 변경
grep : 특정 파일에서 지정한 문자열이나 정규표현식을 포함한 행을 출력해주는 명령어 따로 정리할 것
tee : 표준 출력하면서 파일에도 작성
'|' : pipe. 명령어의 결과를 다른 명령어로 전달

analyze_graphs()

analyze_graphs(){
echo "----------------------------------------------------------------------------------"
echo "ANALYZING GRAPHS FOR ZCU102"
echo "----------------------------------------------------------------------------------"
source ./scripts/analyze_subgraphs.sh zcu102 q_train1_resnet18_cifar10_final.h5
}

scripts 폴더의 analyze_subgraphs.sh 스크립트 실행, q_train1_resnet18_cifar10_final.h5 를 첫 번째 인자로 입력

run_clean_dos2unix()

# ===========================================================================
# STEP1: clean and dos2unix
# ===========================================================================
run_clean_dos2unix(){
echo " "
echo "----------------------------------------------------------------------------------"
echo "[DB INFO STEP1]  CLEANING ALL FOLDERS"
echo "----------------------------------------------------------------------------------"
echo " "
source ./scripts/clean_all.sh
}

scripts 폴더의 clean_all.sh 스크립트 실행

remove_imagenet_test_images()

# ===========================================================================
# remove imagenet test images
# ===========================================================================
remove_imagenet_test_images(){
  cd ./target/imagenet/
  rm -r ./val_dataset
  rm ./words.txt
  rm ./val.txt
  cd ../../
}

target/imagenet 으로 가서 val_dataset.zip 파일 압축 해제하면 나오는 모든 파일 삭제

main_cifar10()

# ===========================================================================
# main for CIFAR10
# ===========================================================================
# do not change the order of the following commands

main_cifar10(){
  echo " "
  echo " "
  pip install image-classifiers
  #cifar10_dataset            # 2
  #run_cifar10_training       # 3
  quantize_resnet18_cifar10   # 4
  compile_resnet18_cifar10    # 5
  ### if you want to cross compile the application for target from host side,
  ### which is not nexessary being compiled also on the target board,
  ### just uncomment next three lines
  #cd target
  #source ./cifar10/run_all_cifar10_target.sh compile_cif10
  #cd ..
  prepare_cifar10_archives    # 6
  echo " "
  echo " "
}

image-classifiers package 설치하고
quantize_resnet18_cifar10
compile_resnet18_cifar10
prepare_cifar10_archives
실행

main_imagenet()

# ===========================================================================
# main for ImageNet
# ===========================================================================
# do not change the order of the following commands

main_imagenet(){
    echo " "
    echo "----------------------------------------------------------------------------------"
    echo "[DB INFO] NOW WORKING ON THE IMAGENET EXAMPLES"
    echo "----------------------------------------------------------------------------------"
    echo " "
    # patch for my code (do not touch it!)
    cp modelzoo/ImageNet/*.txt ./target/imagenet/

  prepare_imagenet_test_images
  ### uncomment next line if you are interested into ResNet50
  quantize_resnet50_imagenet    # 7
  quantize_resnet18_imagenet      # 8
  ### uncomment next line if you are interested into ResNet50
  compile_resnet50_imagenet     # 9
  compile_resnet18_imagenet       #10
  ### if you want to cross compile the application for target from host side,
  ### which is not nexessary being compiled also on the target board,
  ### just uncomment next three lines
  #cd target
  #source ./imagenet/run_all_imagenet_target.sh compile_resnet
  #cd ..
  remove_imagenet_test_images
  prepare_imagenet_archives
  echo " "
  echo " "
}

modelzoo/Imagenet 폴더 안의 모든 txt 파일 $rarr; class? index? 를 target/imagenet으로 복사
prepare_imagenet_test_images
quantize_resnet50_imagenet
quantize_resnet18_imagenet
compile_resnet50_imagenet
compile_resnet18_imagenet
remove_imagenet_test_images
prepare_imagenet_archives
실행

main_all()

# ===========================================================================
# main for all
# ===========================================================================

# do not change the order of the following commands
main_all(){
  run_patch
  ### next line is commented: you should run it only once
  #run_clean_dos2unix  # step  1
  main_cifar10         # steps 2 to  6
  main_imagenet        # steps 7 to 11
}

run_patch
main_cifar10
main_imagenet
실행

인자 전달

# ===========================================================================
# DO NOT REMOVE THE FOLLOWING LINE
# ===========================================================================

"$@"

스크립트에 전달된 모든 인자들을 공백이나 특수문자 포함하여 나타내는 변수
스크립트가 실행될 때 전달된 모든 명령행 인수를 그대로 유지하면서 다른 명령어에 전달할 때 사용

profile
Myongji UNIV. B.S. in Electronic Engineering

0개의 댓글