Skip to content

Commit 30b11ec

Browse files
committed
update README.md, added conda env config
1 parent 3f64987 commit 30b11ec

File tree

4 files changed

+5152
-4959
lines changed

4 files changed

+5152
-4959
lines changed

README.md

+28-6
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
YOLOv4, YOLOv4-tiny Implemented in Tensorflow 2.0.
55
Convert YOLO v4, YOLOv3, YOLO tiny .weights to .pb, .tflite and trt format for tensorflow, tensorflow lite, tensorRT.
66

7-
Download yolov4.weights file: https://drive.google.com/open?id=1cewMfusmPjYWbrnuJRuKhPMwRe_b9PaT
7+
Download yolov4.weights file: https://github.com/AlexeyAB/darknet?tab=readme-ov-file#how-to-evaluate-fps-of-yolov4-on-gpu
88

99

1010
### Prerequisites
11-
* Tensorflow 2.3.0rc0
11+
* Tensorflow 2.12
12+
You can install a conda environment to run the scripts in this repo by using the `conda-env` yaml file.
13+
```bash
14+
# Navigate to the folder where you cloned the repo and from there run:
15+
conda env create --name my_env --file conda-env.yml
16+
```
1217

1318
### Performance
1419
<p align="center"><img src="data/performance.png" width="640"\></p>
@@ -51,13 +56,30 @@ python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoin
5156
# yolov4 quantize float16
5257
python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416-fp16.tflite --quantize_mode float16
5358

54-
# yolov4 quantize int8
55-
python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416-int8.tflite --quantize_mode int8 --dataset ./coco_dataset/coco/val207.txt
56-
5759
# Run demo tflite model
5860
python detect.py --weights ./checkpoints/yolov4-416.tflite --size 416 --model yolov4 --image ./data/kite.jpg --framework tflite
5961
```
60-
Yolov4 and Yolov4-tiny int8 quantization have some issues. I will try to fix that. You can try Yolov3 and Yolov3-tiny int8 quantization
62+
#### Additional steps for int8 quantization
63+
Since int8 quantization requires a subset of the dataset as "representative data" to tune the quantization to, you first have to do some preprocessing of the dataset. In this case we use the Coco dataset. You can simply follow these steps:
64+
```bash
65+
# We'll store the dataset in data/dataset
66+
cd data
67+
mkdir dataset
68+
cd dataset
69+
# Download the dataset
70+
source ../../scripts/get_coco_dataset_2017.sh
71+
# Create a pickle representation for the dataset
72+
python ../../scripts/coco_convert.py --input ./coco/annotations/instances_val2017.json --output val2017.pkl
73+
# Convert the annotations to txt (used when converting to tflite)
74+
python coco_annotation.py --coco_path ./coco
75+
```
76+
77+
Now you can proceed to quantize yolo to int8 parameters (assumes you're back to the root directory of the repo).
78+
```bash
79+
# yolov4 quantize int8
80+
python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416-int8.tflite --quantize_mode int8 --dataset ./data/dataset/val2017.txt
81+
```
82+
6183
### Convert to TensorRT
6284
```bash# yolov3
6385
python save_model.py --weights ./data/yolov3.weights --output ./checkpoints/yolov3.tf --input_size 416 --model yolov3

conda-env.yml

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
name: yolo_tf
2+
channels:
3+
- defaults
4+
dependencies:
5+
- _libgcc_mutex=0.1=main
6+
- _openmp_mutex=5.1=1_gnu
7+
- _tflow_select=2.3.0=mkl
8+
- abseil-cpp=20211102.0=hd4dd3e8_0
9+
- absl-py=1.4.0=py311h06a4308_0
10+
- aiohttp=3.9.3=py311h5eee18b_0
11+
- aiosignal=1.2.0=pyhd3eb1b0_0
12+
- astunparse=1.6.3=py_0
13+
- attrs=23.1.0=py311h06a4308_0
14+
- blas=1.0=mkl
15+
- blinker=1.6.2=py311h06a4308_0
16+
- brotli=1.0.9=h5eee18b_7
17+
- brotli-bin=1.0.9=h5eee18b_7
18+
- brotli-python=1.0.9=py311h6a678d5_7
19+
- bzip2=1.0.8=h7b6447c_0
20+
- c-ares=1.19.1=h5eee18b_0
21+
- ca-certificates=2023.12.12=h06a4308_0
22+
- cachetools=4.2.2=pyhd3eb1b0_0
23+
- certifi=2024.2.2=py311h06a4308_0
24+
- cffi=1.16.0=py311h5eee18b_0
25+
- charset-normalizer=2.0.4=pyhd3eb1b0_0
26+
- click=8.1.7=py311h06a4308_0
27+
- contourpy=1.2.0=py311hdb19cb5_0
28+
- cryptography=41.0.3=py311h130f0dd_0
29+
- cycler=0.11.0=pyhd3eb1b0_0
30+
- cyrus-sasl=2.1.28=h9c0eb46_1
31+
- dbus=1.13.18=hb2f20db_0
32+
- expat=2.5.0=h6a678d5_0
33+
- flatbuffers=2.0.0=h2531618_0
34+
- fontconfig=2.14.1=h4c34cd2_2
35+
- fonttools=4.25.0=pyhd3eb1b0_0
36+
- freetype=2.12.1=h4a9f257_0
37+
- frozenlist=1.4.0=py311h5eee18b_0
38+
- gast=0.4.0=pyhd3eb1b0_0
39+
- giflib=5.2.1=h5eee18b_3
40+
- glib=2.78.4=h6a678d5_0
41+
- glib-tools=2.78.4=h6a678d5_0
42+
- google-auth=2.22.0=py311h06a4308_0
43+
- google-auth-oauthlib=0.5.2=py311h06a4308_0
44+
- google-pasta=0.2.0=pyhd3eb1b0_0
45+
- grpc-cpp=1.48.2=h5bf31a4_0
46+
- grpcio=1.48.2=py311h5bf31a4_0
47+
- gst-plugins-base=1.14.1=h6a678d5_1
48+
- gstreamer=1.14.1=h5eee18b_1
49+
- h5py=3.9.0=py311hdd6beaf_0
50+
- hdf5=1.12.1=h70be1eb_2
51+
- icu=58.2=he6710b0_3
52+
- idna=3.4=py311h06a4308_0
53+
- intel-openmp=2023.1.0=hdb19cb5_46306
54+
- jpeg=9e=h5eee18b_1
55+
- keras=2.12.0=py311h06a4308_0
56+
- keras-preprocessing=1.1.2=pyhd3eb1b0_0
57+
- kiwisolver=1.4.4=py311h6a678d5_0
58+
- krb5=1.20.1=h568e23c_1
59+
- lcms2=2.12=h3be6417_0
60+
- ld_impl_linux-64=2.38=h1181459_1
61+
- lerc=3.0=h295c915_0
62+
- libbrotlicommon=1.0.9=h5eee18b_7
63+
- libbrotlidec=1.0.9=h5eee18b_7
64+
- libbrotlienc=1.0.9=h5eee18b_7
65+
- libclang=14.0.6=default_hc6dbbc7_1
66+
- libclang13=14.0.6=default_he11475f_1
67+
- libcups=2.4.2=ha637b67_0
68+
- libcurl=8.2.1=h91b91d3_0
69+
- libdeflate=1.17=h5eee18b_1
70+
- libedit=3.1.20230828=h5eee18b_0
71+
- libev=4.33=h7f8727e_1
72+
- libffi=3.4.4=h6a678d5_0
73+
- libgcc-ng=11.2.0=h1234567_1
74+
- libgfortran-ng=11.2.0=h00389a5_1
75+
- libgfortran5=11.2.0=h1234567_1
76+
- libglib=2.78.4=hdc74915_0
77+
- libgomp=11.2.0=h1234567_1
78+
- libiconv=1.16=h7f8727e_2
79+
- libllvm14=14.0.6=hdb19cb5_3
80+
- libnghttp2=1.52.0=ha637b67_1
81+
- libpng=1.6.39=h5eee18b_0
82+
- libpq=12.15=h37d81fd_1
83+
- libprotobuf=3.20.3=he621ea3_0
84+
- libssh2=1.10.0=h37d81fd_2
85+
- libstdcxx-ng=11.2.0=h1234567_1
86+
- libtiff=4.5.1=h6a678d5_0
87+
- libuuid=1.41.5=h5eee18b_0
88+
- libwebp-base=1.3.2=h5eee18b_0
89+
- libxcb=1.15=h7f8727e_0
90+
- libxkbcommon=1.0.1=h5eee18b_1
91+
- libxml2=2.10.4=hcbfbd50_0
92+
- libxslt=1.1.37=h2085143_0
93+
- lxml=4.9.3=py311hdbbb534_0
94+
- lz4-c=1.9.4=h6a678d5_0
95+
- markdown=3.4.1=py311h06a4308_0
96+
- markupsafe=2.1.3=py311h5eee18b_0
97+
- matplotlib=3.8.0=py311h06a4308_0
98+
- matplotlib-base=3.8.0=py311ha02d727_0
99+
- mkl=2023.1.0=h213fc3f_46344
100+
- mkl-service=2.4.0=py311h5eee18b_1
101+
- mkl_fft=1.3.8=py311h5eee18b_0
102+
- mkl_random=1.2.4=py311hdb19cb5_0
103+
- multidict=6.0.4=py311h5eee18b_0
104+
- munkres=1.1.4=py_0
105+
- mysql=5.7.24=he378463_2
106+
- ncurses=6.4=h6a678d5_0
107+
- numpy=1.23.5=py311h08b1b3b_1
108+
- numpy-base=1.23.5=py311hf175353_1
109+
- oauthlib=3.2.2=py311h06a4308_0
110+
- openjpeg=2.4.0=h3ad879b_0
111+
- openssl=1.1.1w=h7f8727e_0
112+
- opt_einsum=3.3.0=pyhd3eb1b0_1
113+
- packaging=23.1=py311h06a4308_0
114+
- pcre2=10.42=hebb0a14_0
115+
- pillow=10.2.0=py311h5eee18b_0
116+
- pip=23.3.1=py311h06a4308_0
117+
- ply=3.11=py311h06a4308_0
118+
- protobuf=3.20.3=py311h6a678d5_0
119+
- pyasn1=0.4.8=pyhd3eb1b0_0
120+
- pyasn1-modules=0.2.8=py_0
121+
- pycparser=2.21=pyhd3eb1b0_0
122+
- pyjwt=2.4.0=py311h06a4308_0
123+
- pyopenssl=23.2.0=py311h06a4308_0
124+
- pyparsing=3.0.9=py311h06a4308_0
125+
- pyqt=5.15.10=py311h6a678d5_0
126+
- pyqt5-sip=12.13.0=py311h5eee18b_0
127+
- pysocks=1.7.1=py311h06a4308_0
128+
- python=3.11.5=h7a1cb2a_0
129+
- python-dateutil=2.8.2=pyhd3eb1b0_0
130+
- python-flatbuffers=2.0=pyhd3eb1b0_0
131+
- qt-main=5.15.2=h5b8104b_9
132+
- re2=2022.04.01=h295c915_0
133+
- readline=8.2=h5eee18b_0
134+
- requests=2.31.0=py311h06a4308_1
135+
- requests-oauthlib=1.3.0=py_0
136+
- rsa=4.7.2=pyhd3eb1b0_1
137+
- scipy=1.11.4=py311h08b1b3b_0
138+
- setuptools=68.2.2=py311h06a4308_0
139+
- sip=6.7.12=py311h6a678d5_0
140+
- six=1.16.0=pyhd3eb1b0_1
141+
- snappy=1.1.10=h6a678d5_1
142+
- sqlite=3.41.2=h5eee18b_0
143+
- tbb=2021.8.0=hdb19cb5_0
144+
- tensorboard=2.12.1=py311h06a4308_0
145+
- tensorboard-data-server=0.7.0=py311h52d8a92_0
146+
- tensorboard-plugin-wit=1.6.0=py_0
147+
- tensorflow=2.12.0=mkl_py311h34a0fa1_0
148+
- tensorflow-base=2.12.0=mkl_py311he5f8e37_0
149+
- tensorflow-estimator=2.12.0=py311h06a4308_0
150+
- termcolor=2.1.0=py311h06a4308_0
151+
- tk=8.6.12=h1ccaba5_0
152+
- tornado=6.3.3=py311h5eee18b_0
153+
- tqdm=4.65.0=py311h92b7b1e_0
154+
- typing_extensions=4.9.0=py311h06a4308_1
155+
- tzdata=2023d=h04d1e81_0
156+
- urllib3=1.26.18=py311h06a4308_0
157+
- werkzeug=2.3.8=py311h06a4308_0
158+
- wheel=0.41.2=py311h06a4308_0
159+
- wrapt=1.14.1=py311h5eee18b_0
160+
- xz=5.4.5=h5eee18b_0
161+
- yarl=1.9.3=py311h5eee18b_0
162+
- zlib=1.2.13=h5eee18b_0
163+
- zstd=1.5.5=hc292b87_0
164+
- pip:
165+
- easydict==1.12
166+
- opencv-python==4.9.0.80

0 commit comments

Comments
 (0)