hhk7734 / tensorflow-yolov4

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

Unable to train on Custom Dataset #31

Closed Adeel-Intizar closed 3 years ago

Adeel-Intizar commented 3 years ago

error I wanted to train it on my custom dataset, but it is consistently raising an error "IndexError: index 224 is out of bounds for axis 1 with size 20" and this error is changing values but it is consistent

Any Help would be appreciated. Thanks

hhk7734 commented 3 years ago

Too little information. Can you share your script? and dataset files

why are validation_steps and steps_per_epoch zero?

hhk7734 commented 3 years ago

commit: fcea285ffa05845b6cd59e188921eff6f02186cb

If you use a converted-coco dataset, the data format is shown below.

000000000139.jpg 58,0.389578,0.416103,0.038594,0.163146 62,0.127641,0.505153,0.233312,0.222700 62,0.934195,0.583462,0.127109,0.184812 56,0.604656,0.632547,0.087500,0.241385 56,0.502508,0.627324,0.096609,0.231174 56,0.669195,0.618991,0.047141,0.190986 56,0.512797,0.528251,0.033719,0.027207 0,0.686445,0.531960,0.082891,0.323967 0,0.612484,0.446197,0.023625,0.083897 68,0.811859,0.501725,0.023031,0.037488 72,0.786320,0.536373,0.031703,0.254249 73,0.956156,0.771702,0.022406,0.107300 73,0.968250,0.778075,0.020125,0.109014 74,0.710555,0.310000,0.021828,0.051362 75,0.886562,0.831608,0.057313,0.210493 75,0.556945,0.516702,0.017766,0.052934 56,0.651664,0.528826,0.015047,0.029390 75,0.388047,0.478415,0.022219,0.041385 75,0.533836,0.487946,0.015203,0.039272 60,0.599984,0.647148,0.196188,0.208756
000000000285.jpg 21,0.501220,0.548094,0.997560,0.881156
000000000632.jpg 59,0.318570,0.768064,0.626922,0.431159 58,0.333984,0.378375,0.094969,0.191284 73,0.719164,0.435393,0.013391,0.073685 73,0.714562,0.558872,0.012531,0.070248 73,0.699094,0.657288,0.008313,0.082153 73,0.800039,0.433561,0.018984,0.076149 73,0.767578,0.441729,0.011687,0.058075 56,0.464344,0.567899,0.163625,0.181553 58,0.607195,0.587723,0.128922,0.296066 73,0.743086,0.434141,0.045828,0.074617 73,0.842531,0.556491,0.038125,0.083706 73,0.814734,0.435870,0.006375,0.070787 73,0.780359,0.143085,0.006375,0.056646 73,0.821438,0.240714,0.004375,0.078199 73,0.796336,0.328986,0.050922,0.013168 73,0.748336,0.520373,0.075859,0.025135 73,0.727953,0.559700,0.012875,0.068965 73,0.769531,0.402692,0.239063,0.627329
...
Adeel-Intizar commented 3 years ago

Thank you for your reply, I have attached the files “script.txt” contains my script which I used in google colab, and “train.txt and val.txt” contains dataset info From: Hyeonki Hongmailto:notifications@github.com Sent: Saturday, October 17, 2020 9:58 PM To: hhk7734/tensorflow-yolov4mailto:tensorflow-yolov4@noreply.github.com Cc: Adeelmailto:kingadeel2017@outlook.com; Authormailto:author@noreply.github.com Subject: Re: [hhk7734/tensorflow-yolov4] Unable to train on Custom Dataset (#31)

Too little information. Can you share your script? and dataset files

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/hhk7734/tensorflow-yolov4/issues/31#issuecomment-711046391, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ANLR5QT7N2SV2YVRFWPJ2OLSLHEJRANCNFSM4SUOAUBQ.

image_0001.jpg 0,49,30,349,137 image_0002.jpg 0,59,35,342,153 image_0003.jpg 0,47,36,331,135 image_0004.jpg 0,47,24,342,141 image_0005.jpg 0,48,18,339,146 image_0006.jpg 0,48,24,344,126 image_0007.jpg 0,49,23,344,122 image_0008.jpg 0,51,29,344,119 image_0009.jpg 0,50,29,344,137 image_0010.jpg 0,55,32,335,106 image_0011.jpg 0,58,35,344,130 image_0012.jpg 0,49,25,344,122 image_0013.jpg 0,48,31,344,146 image_0014.jpg 0,55,37,349,121 image_0015.jpg 0,61,39,353,163 image_0016.jpg 0,59,54,327,137 image_0017.jpg 0,62,37,347,143 image_0018.jpg 0,57,33,348,147 image_0019.jpg 0,51,33,341,146 image_0020.jpg 0,45,31,345,165 image_0021.jpg 0,48,28,347,129 image_0022.jpg 0,49,30,344,130 image_0023.jpg 0,50,23,341,121 image_0024.jpg 0,48,25,344,106 image_0025.jpg 0,56,31,342,140 image_0026.jpg 0,59,30,337,127 image_0027.jpg 0,53,25,348,123 image_0028.jpg 0,54,29,346,114 image_0029.jpg 0,56,29,348,119 image_0030.jpg 0,47,15,354,161 image_0031.jpg 0,58,41,347,197 image_0032.jpg 0,50,29,342,119 image_0033.jpg 0,49,29,339,133 image_0034.jpg 0,58,28,340,122 image_0035.jpg 0,49,17,332,128 image_0036.jpg 0,49,6,347,166 image_0037.jpg 0,51,33,345,138 image_0038.jpg 0,47,4,347,106 image_0039.jpg 0,46,20,335,147 image_0040.jpg 0,47,29,344,146 image_0041.jpg 0,48,30,335,138 image_0042.jpg 0,52,31,336,154 image_0043.jpg 0,61,39,337,128 image_0044.jpg 0,63,29,333,132 image_0045.jpg 0,44,35,339,156 image_0046.jpg 0,61,24,346,148 image_0047.jpg 0,58,24,336,151 image_0048.jpg 0,54,29,332,124 image_0049.jpg 0,57,39,347,175 image_0050.jpg 0,61,42,338,126 image_0051.jpg 0,52,32,344,174 image_0052.jpg 0,57,23,347,143 image_0053.jpg 0,52,42,345,137 image_0054.jpg 0,63,43,324,169 image_0055.jpg 0,53,27,344,115 image_0056.jpg 0,71,28,326,116 image_0057.jpg 0,49,52,332,141 image_0058.jpg 0,39,39,342,149 image_0059.jpg 0,53,5,341,180 image_0060.jpg 0,54,17,339,127 image_0061.jpg 0,51,46,336,122 image_0062.jpg 0,55,43,346,126 image_0063.jpg 0,46,31,342,124 image_0064.jpg 0,46,37,342,140 image_0065.jpg 0,50,30,345,125 image_0066.jpg 0,52,39,344,109 image_0067.jpg 0,44,25,343,150 image_0068.jpg 0,49,30,339,144 image_0069.jpg 0,59,32,343,147 image_0070.jpg 0,58,34,345,156 image_0071.jpg 0,54,42,360,152 image_0072.jpg 0,59,78,341,171 image_0073.jpg 0,48,30,295,111 image_0074.jpg 0,51,27,346,100 image_0075.jpg 0,66,32,357,112 image_0076.jpg 0,49,33,342,147 image_0077.jpg 0,40,27,347,128 image_0078.jpg 0,46,23,337,159 image_0079.jpg 0,54,29,338,133 image_0080.jpg 0,55,32,341,139 ! git clone https://github.com/hhk7734/tensorflow-yolov4.git

from tensorflow.keras import callbacks, optimizers from yolov4.tf import YOLOv4, SaveWeightsCallback

yolo = YOLOv4(tiny=True) yolo.classes = "coco.names" yolo.input_size = 608 yolo.batch_size = 32

yolo.make_model() yolo.load_weights( "/content/drive/My Drive/Colab Notebooks/yolo weights/yolov4-tiny.conv.29", weights_type="yolo" )

train_data_set = yolo.load_dataset( "train.txt", image_path_prefix="images", label_smoothing=0.05 ) val_data_set = yolo.load_dataset( "val.txt", image_path_prefix="images", training=False )

epochs = 400 lr = 1e-4

optimizer = optimizers.Adam(learning_rate=lr) yolo.compile(optimizer=optimizer, loss_iou_type="ciou")

def lr_scheduler(epoch): if epoch < int(epochs 0.5): return lr if epoch < int(epochs 0.8): return lr 0.5 if epoch < int(epochs 0.9): return lr 0.1 return lr 0.01

_callbacks = [ callbacks.LearningRateScheduler(lr_scheduler), callbacks.TerminateOnNaN(), callbacks.TensorBoard( log_dir="./logs", ), SaveWeightsCallback( yolo=yolo, dir_path="./trained", weights_type="yolo", epoch_per_save=10 ), ]

yolo.fit( train_data_set, epochs=epochs, callbacks=_callbacks, validation_data=val_data_set, validation_steps=50, validation_freq=5, steps_per_epoch=100, )

hhk7734 commented 3 years ago

You should modify train.txt and val.txt. center_x, center_y, width and height are between 0.0 and 1.0.

For example, Suppose the image width and height are 600 and 500 image_0001.jpg 0,49,30,349,137 -> image_0001.jpg 0,49/600,30/500,349/600,137/500 -> image_0001.jpg 0,0.0817,0.06,0.58167,0.274

Adeel-Intizar commented 3 years ago

Thank you for your help..

wmcnally commented 3 years ago

@hhk7734 @Adeel-Intizar Just to confirm, should the xy positions in the dataset .txt file refer to the center of the bounding box or the top left corner of the bounding box? Thanks.

wmcnally commented 3 years ago

Nevermind, I confirmed that the xy positions in the dataset .txt file refer to the center of the bounding box.