hhk7734 / tensorflow-yolov4

YOLOv4 Implemented in Tensorflow 2.
MIT License
136 stars 75 forks source link

Apparent differences between results from cpu and edgetpu #92

Open tino926 opened 2 years ago

tino926 commented 2 years ago

Hi, thanks for your wonderful work. However, I have got very different results from cpu and edgetpu. In the following image, left one is the result using cpu, and the right one is the result using edgetpu. Untitled

These are the scripts I've used:

  1. convert weight to tflite and quantize:
    
    from yolov4.tf import YOLOv4, YOLODataset, save_as_tflite

yolo = YOLOv4()

yolo.config.parse_names("test/coco.names") yolo.config.parse_cfg("config/yolov4-tiny-relu-tpu.cfg")

yolo.make_model() yolo.load_weights( "/home/hhk7734/NN/yolov4-tiny-relu.weights", weights_type="yolo" )

dataset = YOLODataset( config=yolo.config, dataset_list="/home/hhk7734/NN/val2017.txt", image_path_prefix="/home/hhk7734/NN/val2017", training=False, )

save_as_tflite( model=yolo.model, tflite_path="yolov4-tiny-relu-int8.tflite", quantization="full_int8", dataset=dataset, )


2. convert to edgetpu model:
`edgetpu_compiler -sa yolov4-tiny-relu-int8.tflite`

3. inference on cpu:
```python
import cv2

from yolov4.tflite import YOLOv4

yolo = YOLOv4()

yolo.config.parse_names("test/coco.names")
yolo.config.parse_cfg("config/yolov4-tiny-relu-tpu.cfg")

yolo.summary()

yolo.load_tflite("yolov4-tiny-relu-int8.tflite")

yolo.inference("test/kite.jpg")
  1. inference on edgetpu:
    
    import cv2

from yolov4.tflite import YOLOv4

yolo = YOLOv4()

yolo.config.parse_names("test/coco.names") yolo.config.parse_cfg("config/yolov4-tiny-relu-tpu.cfg")

yolo.summary()

yolo.load_tflite("yolov4-tiny-relu-int8_edgetpu.tflite")

yolo.inference("test/kite.jpg")

hhk7734 commented 2 years ago

Oh,,, I don't know about that.