pythonlessons/TensorFlow-2.x-YOLOv3

Low mAP in custom trained model

MHaz95 opened this issue · 1 comments

Hi community!

I am facing the problem, that I am getting an overall mAP for two classes in a custom trained YoloV3 model from 0,518%. The first class I try to predict is cars (mAP = 1,036%), the scond class I try to predict is trucks (mAP = 0%).
I train the model with ~500 extracted frames from a video showing multiple cars and trucks driving on a highway. The images are splitted 80/20 into train and test images.
For training I am using a RTX3060 12Gb, CUDA11.4, Cudnn 8201 and Tensorflow 2.5.1.
While the training I am facing no errors. All .dll were successfully opened.

Befor trainig i created YoloCustom.txt (which shows "truck" and "car" as expected), YoloCustomTest.txt and YoloCustomTrain.txt using XML_to_YOLOv3.py which workes without showing any errors. After this step I configured the configs.py as the following:

`YOLO_TYPE = "yolov3" # yolov4 or yolov3
YOLO_FRAMEWORK = "tf" # "tf" or "trt"
YOLO_V3_WEIGHTS = "model_data/yolov3.weights"
YOLO_TRT_QUANTIZE_MODE = "INT8" # INT8, FP16, FP32
YOLO_CUSTOM_WEIGHTS = False # "checkpoints/yolov3_custom" # used in evaluate_mAP.py and custom model detection, if not using leave False
# YOLO_CUSTOM_WEIGHTS also used with TensorRT and custom model detection
YOLO_COCO_CLASSES = "model_data/coco/coco.names"
YOLO_STRIDES = [8, 16, 32]
YOLO_IOU_LOSS_THRESH = 0.5
YOLO_ANCHOR_PER_SCALE = 3
YOLO_MAX_BBOX_PER_SCALE = 100
YOLO_INPUT_SIZE = 416
if YOLO_TYPE == "yolov4":
YOLO_ANCHORS = [[[12, 16], [19, 36], [40, 28]],
[[36, 75], [76, 55], [72, 146]],
[[142,110], [192, 243], [459, 401]]]
if YOLO_TYPE == "yolov3":
YOLO_ANCHORS = [[[10, 13], [16, 30], [33, 23]],
[[30, 61], [62, 45], [59, 119]],
[[116, 90], [156, 198], [373, 326]]]

Train options
TRAIN_YOLO_TINY = False
TRAIN_SAVE_BEST_ONLY = True # saves only best model according validation loss (True recommended)
TRAIN_SAVE_CHECKPOINT = False # saves all best validated checkpoints in training process (may require a lot disk space) (False recommended)
TRAIN_CLASSES = "model_data/YoloCustom.txt"
TRAIN_ANNOT_PATH = "model_data/YoloCustomTrain.txt"
TRAIN_LOGDIR = "log"
TRAIN_CHECKPOINTS_FOLDER = "checkpoints"
TRAIN_MODEL_NAME = f"{YOLO_TYPE}_custom"
TRAIN_LOAD_IMAGES_TO_RAM = True # With True faster training, but need more RAM
TRAIN_BATCH_SIZE = 4
TRAIN_INPUT_SIZE = 416
TRAIN_DATA_AUG = True
TRAIN_TRANSFER = True
TRAIN_FROM_CHECKPOINT = False # "checkpoints/yolov3_custom"
TRAIN_LR_INIT = 1e-4
TRAIN_LR_END = 1e-6
TRAIN_WARMUP_EPOCHS = 2
TRAIN_EPOCHS = 200

TEST options
TEST_ANNOT_PATH = "model_data/YoloCustomTest.txt"
TEST_BATCH_SIZE = 4
TEST_INPUT_SIZE = 416
TEST_DATA_AUG = False
TEST_DECTECTED_IMAGE_PATH = ""
TEST_SCORE_THRESHOLD = 0.3
TEST_IOU_THRESHOLD = 0.45

if TRAIN_YOLO_TINY:
YOLO_STRIDES = [16, 32]
# YOLO_ANCHORS = [[[23, 27], [37, 58], [81, 82]], # this line can be uncommented for default coco weights
YOLO_ANCHORS = [[[10, 14], [23, 27], [37, 58]],
[[81, 82], [135, 169], [344, 319]]]`

With the configured configs.py I used train.py not changing anything with "python train.py".

Evaluating the model results in the following:
grafik

Have I done anything wrong or forgot any step? Am I training the model with not enough images?

Hey, yes , you need to increase the count of these images :)