WongKinYiu / yolor

implementation of paper - You Only Learn One Representation: Unified Network for Multiple Tasks (https://arxiv.org/abs/2105.04206)
GNU General Public License v3.0
1.99k stars 518 forks source link

使用YOLOR训练自己的数据集(txt标注格式)报错 #10

Open Wanghe1997 opened 3 years ago

Wanghe1997 commented 3 years ago

运行train.py,报错:Exception: Dataset not found 我想请问,YOLOR是否支持txt标注的数据集直接进行训练? 还是必须要先转成json或者xml的标注格式才能用? README文件并未说明。也就是说,我是否要先把自己的数据集变成COCO数据集的格式才可以使用YOLOR,还是说可以向YOLOV5那样,使用txt标注的数据集直接训练呢? 谢谢

Wanghe1997 commented 3 years ago

后来,我使用coco128进行测试,配置好coco128.yaml,执行train.py,报错为: WARNING: Dataset not found, nonexistent paths: ['G:\datasets_models\origin_models\coco128\images\val2017'] 因此最终提示:Exception: Dataset not found.

理论上正确的路径应为:G:\datasets_models\origin_models\yoloR\coco128\images\val2017 为什么会漏掉中间的yoloR文件夹名字呢?是不是你们生成路径的代码有问题呢?

Wanghe1997 commented 3 years ago

我是在windows10环境下跑的代码

WongKinYiu commented 3 years ago

可以請您提供您的 coco128.yaml 和 train.txt 嗎

預設路徑:

/coco128 ..../your_data

/yolor ..../your_code

Wanghe1997 commented 3 years ago

可以請您提供您的 coco128.yaml 和 train.txt 嗎

預設路徑:

/coco128 ..../your_data

/yolor ..../your_code

我可以将相关的文件发送到你的邮箱吗?您帮我看看,这样方便些。谢谢

Wanghe1997 commented 3 years ago

coco128文件夹目录

/coco128 ..../annotations(空,无任何文件) ..../images ......../train2017(里面是128张.jpg图片) ......../val2017(空,无任何文件) ..../labels ......../train2017(里面是128张图片各自的.txt标注文件) ......../val2017(空,无任何文件)

coco128.yaml文件代码

/yoloR ./data/coco128.yaml code: train: ../coco128/images/train2017/ val: ../coco128/images/val2017/

test: ../coco/test-dev2017.txt

number of classes

nc: 80

class names

names: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush']

train.py参数部分的代码:

parser.add_argument('--weights', type=str, default='yolor_p6.pt', help='initial weights path') parser.add_argument('--cfg', type=str, default='cfg/yolor_p6.cfg', help='model.yaml path') parser.add_argument('--data', type=str, default='data/coco128.yaml', help='data.yaml path') parser.add_argument('--hyp', type=str, default='data/hyp.scratch.1280.yaml', help='hyperparameters path') parser.add_argument('--epochs', type=int, default=1000) parser.add_argument('--batch-size', type=int, default=8, help='total batch size for all GPUs') parser.add_argument('--img-size', nargs='+', type=int, default=[1280, 1280], help='[train, test] image sizes') parser.add_argument('--rect', action='store_true', help='rectangular training') parser.add_argument('--resume', nargs='?', const=True, default=False, help='resume most recent training') parser.add_argument('--nosave', action='store_true', help='only save final checkpoint') parser.add_argument('--notest', action='store_true', help='only test final epoch') parser.add_argument('--noautoanchor', action='store_true', help='disable autoanchor check') parser.add_argument('--evolve', action='store_true', help='evolve hyperparameters') parser.add_argument('--bucket', type=str, default='', help='gsutil bucket') parser.add_argument('--cache-images', action='store_true', help='cache images for faster training') parser.add_argument('--image-weights', action='store_true', help='use weighted image selection for training') parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu') parser.add_argument('--multi-scale', action='store_true', help='vary img-size +/- 50%%') parser.add_argument('--single-cls', action='store_true', help='train as single-class dataset') parser.add_argument('--adam', action='store_true', help='use torch.optim.Adam() optimizer') parser.add_argument('--sync-bn', action='store_true', help='use SyncBatchNorm, only available in DDP mode') parser.add_argument('--local_rank', type=int, default=-1, help='DDP parameter, do not modify') parser.add_argument('--log-imgs', type=int, default=16, help='number of images for W&B logging, max 100') parser.add_argument('--workers', type=int, default=8, help='maximum number of dataloader workers') parser.add_argument('--project', default='runs/train', help='save to project/name') parser.add_argument('--name', default='exp', help='save to project/name') parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') opt = parser.parse_args()

然后,python train.py 之后就报错上述的错误了

WongKinYiu commented 3 years ago

https://github.com/WongKinYiu/yolor/issues/10#issuecomment-846379761 從您這裡的說明, 我感覺您的資料是

/yolor ..../your_code ..../coco128

估計把coco128往上一層放就可以了

Wanghe1997 commented 3 years ago

#10 (comment) 從您這裡的說明, 我感覺您的資料是

/yolor ..../your_code ..../coco128

估計把coco128往上一層放就可以了

确实,我把coco128作为yolor的子文件夹了。必须将coco128作为yolor的同级文件夹才行吗?为什么是这样呢?

WongKinYiu commented 3 years ago

您的 coco128.yaml 裡面的路徑就是往上一層找 然後應該要指向.txt檔, 而不是指向資料夾

train: ../coco128/images/train2017/
val: ../coco128/images/val2017/
Wanghe1997 commented 3 years ago

您的 coco128.yaml 裡面的路徑就是往上一層找 然後應該要指向.txt檔, 而不是指向資料夾

train: ../coco128/images/train2017/
val: ../coco128/images/val2017/

您项目里自带的coco.yaml文件里有这么一句注释的话:train and val datasets (image directory or *.txt file with image paths)。这个意思不是说指向图片文件夹或者.txt file都行吗?

WongKinYiu commented 3 years ago

可以試試看

Wanghe1997 commented 3 years ago

#10 (comment) 從您這裡的說明, 我感覺您的資料是

/yolor ..../your_code ..../coco128

估計把coco128往上一層放就可以了

不不不,我仔细琢磨了一下。您理解错了。我的路径应该没错的。项目文件是这样: /yolor ..../data/coco128.yaml(coco128.yaml位于data文件夹中) ..../coco128

所以我在coco128.yaml中: train: ../coco128/images/train2017/ val: ../coco128/images/val2017/ 应该是没问题的,因为coco128是和data同级的文件夹,而coco128.yaml在data文件夹中。但是这样运行还是报错。我觉得应该是train.py里设置路径的代码有问题?

WongKinYiu commented 3 years ago

對應的是 train.py 所在的目錄

您如果不想把它往上移, 就把 coco128.yaml 改成

train: ./coco128/images/train2017/
val: ./coco128/images/val2017/
Wanghe1997 commented 3 years ago

對應的是 train.py 所在的目錄

您如果不想把它往上移, 就把 coco128.yaml 改成

train: ./coco128/images/train2017/
val: ./coco128/images/val2017/

按照您的建议修改后,报错变为:Exception: Error loading data from ./coco128/images/val2017/: No images found 这个文件夹确实是空的,因为所有图片我都放在train2017下了,全部当作train数据集。 如果我注释掉coco128.yaml中val: ./coco128/images/val2017/这一行,则报错变为: File "G:/datasets_models/origin_models/yoloR/train.py", line 71, in train test_path = data_dict['val'] KeyError: 'val'

你们的代码是必须将数据集分成train和val,且val文件夹不为空才能跑吗?如果我不想设置val,全部当作train集去训练,应该怎么改呢?

WongKinYiu commented 3 years ago
train: ./coco128/images/train2017/
val: ./coco128/images/train2017/
Wanghe1997 commented 3 years ago
train: ./coco128/images/train2017/
val: ./coco128/images/train2017/

出现另外一个报错: Traceback (most recent call last): File "G:/datasets_models/origin_models/yoloR/train.py", line 564, in train(hyp, opt, device, tb_writer, wandb) File "G:/datasets_models/origin_models/yoloR/train.py", line 287, in train pred = model(imgs) # forward File "D:\Software\Anaconda3\envs\YOLOR\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl result = self.forward(*input, kwargs) File "G:\datasets_models\origin_models\yoloR\models\models.py", line 543, in forward return self.forward_once(x) File "G:\datasets_models\origin_models\yoloR\models\models.py", line 604, in forward_once x = module(x) File "D:\Software\Anaconda3\envs\YOLOR\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl result = self.forward(*input, *kwargs) File "D:\Software\Anaconda3\envs\YOLOR\lib\site-packages\torch\nn\modules\container.py", line 119, in forward input = module(input) File "D:\Software\Anaconda3\envs\YOLOR\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl result = self.forward(input, kwargs) File "D:\Software\Anaconda3\envs\YOLOR\lib\site-packages\torch\nn\modules\conv.py", line 399, in forward return self._conv_forward(input, self.weight, self.bias) File "D:\Software\Anaconda3\envs\YOLOR\lib\site-packages\torch\nn\modules\conv.py", line 395, in _conv_forward return F.conv2d(input, weight, bias, self.stride, RuntimeError: cuDNN error: CUDNN_STATUS_INTERNAL_ERROR

这个错误应该怎么解决呢?我本机Anaconda虚拟环境中,torch==1.8.1 cudatoolkit==10.2.89

Wanghe1997 commented 3 years ago
train: ./coco128/images/train2017/
val: ./coco128/images/train2017/

找到原因了,是显存超了。我把batch-size调小再试试。前面那个路径的问题还是有些疑惑。我在设置coco128.yaml的时候是以coco128.yaml所在路径为基准去找图片的,但是好像应该是以train.py所在的路径为标准去找图片。为什么是这样呢?是不是因为执行的是train.py,而train.py调用了coco128.yaml,所以应该以train.py所在的路径去找图片文件夹?

Wanghe1997 commented 3 years ago

你好,我现在已经用自己的数据集训练到850轮了,一共1000轮。我想看训练过程中的PR、loss、acc这些曲线应该怎么看呢?可以用tensorboard看吗?这方面的指令在哪里可以找到教程?我还是个新手,谢谢你的答复。如果你能给我总结一下就最好了,谢谢

WongKinYiu commented 3 years ago

tensorboard 可以.

Wanghe1997 commented 3 years ago

tensorboard 可以.

嗯嗯,是不是tensorboard --logdir=文件夹路径(runs下包含events.out文件的路径)?

Wanghe1997 commented 3 years ago

作者,请问您可以告诉我test.py相对于train.py,它的作用和区别在哪呢?比如就上述我的提问来说,我使用train.py训练coco128数据集,目的是训练,训练过程中展示每一轮epoch的准确率、召回率、mAP等指标。那如果我换成test.py去test coco128数据集,目的是什么呢?区别在哪?可能问的有些拗口,总的来说就是我没有理解test.py和train.py的作用有什么区别。 除此之外,还有个tune.py,这个文件的作用又是什么呢?谢谢

WongKinYiu commented 3 years ago

训练过程中展示每一轮epoch的准确率、召回率、mAP等指标 就是 call test.py 進行.

Wanghe1997 commented 3 years ago

训练过程中展示每一轮epoch的准确率、召回率、mAP等指标 就是 call test.py 進行.

可是,我只运行train.py训练数据集,过程中就已经展示准确率、召回率、mAP这些指标了。您的意思是执行train.py的过程中,程序会调用test.py进行指标的计算? 还有tune.py的作用又是什么呢?

WongKinYiu commented 3 years ago

https://github.com/WongKinYiu/yolor/issues/2

Mobu59 commented 2 years ago

您好,我刚开始使用yolor准备开始训练自己的数据集,想请问一下数据集的格式应该是怎么样的,我看coco.yaml里面是train: ../coco/train2007.txt #118k images 这个txt文件的格式是图像路径,以及bbox的xywh吗?