Tianxiaomo / pytorch-YOLOv4

PyTorch ,ONNX and TensorRT implementation of YOLOv4
Apache License 2.0
4.47k stars 1.49k forks source link

对于没有目标物体的图像,这种怎么放进训练集,ValuerError:Could not couvert string to float:'' #473

Open martinkeith opened 3 years ago

martinkeith commented 3 years ago

我在使用自己的数据集进行训练时,将没有目标的图像也加入进训练集,但是执行时会报错: dataset.py: class Yolo_dataset(Dataset): def init(self, lable_path, cfg, train=True): super(Yolo_dataset, self).init() if cfg.mixup == 2: print("cutmix=1 - isn't supported for Detector") raise elif cfg.mixup == 2 and cfg.letter_box: print("Combination: letter_box=1 & mosaic=1 - isn't supported, use only 1 of these parameters") raise

    self.cfg = cfg
    self.train = train

    truth = {}
    f = open(lable_path, 'r', encoding='utf-8')
    for line in f.readlines():
        data = line.split(" ")
        truth[data[0]] = []
        for i in data[1:]:
            truth[data[0]].append([int(float(j)) for j in i.split(',')])

由于train.txt的格式是image_name x1,y1,x2,y2,id,因此,对于没有目标的图像,这行变成了image_name 所以这里会报错。 我的理解是:训练集中应该存在无目标的图像。但这显然与作者的想法不一致,请问大家对于这种问题是怎么处理的??

rak7045 commented 2 years ago

Hello, Do you resolve this problem? I am also trying to train on my own dataset. I have prepared dataset in the following way:

image path x1,y1, class_id x2,y2, class_id C:\Users\ravi\Desktop\data\aerial view 1st collection\outputsout_bbox\002818.png 0.1917,0.5083,0.0364,0.0251,3 0.7015, 0.4184,0.0781,0.0389,0 0.5087, 0.8376,0.112,0.2885,1 0.1653, 0.5426,0.1219,0.0673,0

Do we need to give full path or 002818.png is enough?

I got the same error initially then I changed "truth[data[0]].append([int(float(j)) for j in i.split(',')])" to truth[data[0]].append([j for j in i.split(',')]). I have removed int ( float( ) ).

Then I got the following error: colab error

My command line is in the following way> !python train.py -l 0.001 -g 4 -pretrained ./yolov4.conv.137.pth -classes 4 -dir "/content/gdrive/MyDrive/yolo_v4_present/pytorch-YOLOv4-master/data/outputsout_rgb" -train_label_path "/content/gdrive/MyDrive/yolo_v4_present/pytorch-YOLOv4-master/data/train.txt"

Correct me if I am doing anything wrong? Could you pleases help me resolving the error?

natbutter commented 2 years ago

I had the same issue, and it was related to spaces in filenames within train.txt.