ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.1k stars 16.18k forks source link

Unrecognized arguments: --data dataset.yaml #7504

Closed lamsongianm closed 2 years ago

lamsongianm commented 2 years ago

Search before asking

Question

Hi everyone, when I train the model, the system shows the error, please help to fix it, thanks.

(behavior_detection) ronaldlam@ronaldlam-VirtualBox:~/PycharmProjects/behavior_detection/yolov5$ python train.py --img 320 --batch 16 --epochs 3 --data dataset.yaml --weights yolov5s.pt usage: train.py [-h] [--weights WEIGHTS] [--cfg CFG] [--training_data TRAINING_DATA] [--hyp HYP] [--epochs EPOCHS] [--batch-size BATCH_SIZE] [--imgsz IMGSZ] [--rect] [--resume [RESUME]] [--nosave] [--noval] [--noautoanchor] [--evolve [EVOLVE]] [--bucket BUCKET] [--cache [CACHE]] [--image-weights] [--device DEVICE] [--multi-scale] [--single-cls] [--optimizer {SGD,Adam,AdamW}] [--sync-bn] [--workers WORKERS] [--project PROJECT] [--name NAME] [--exist-ok] [--quad] [--cos-lr] [--label-smoothing LABEL_SMOOTHING] [--patience PATIENCE] [--freeze FREEZE [FREEZE ...]] [--save-period SAVE_PERIOD] [--local_rank LOCAL_RANK] [--entity ENTITY] [--upload_dataset [UPLOAD_DATASET]] [--bbox_interval BBOX_INTERVAL] [--artifact_alias ARTIFACT_ALIAS] train.py: error: unrecognized arguments: --data dataset.yaml

Additional

No response

github-actions[bot] commented 2 years ago

👋 Hello @lamsongianm, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on macOS, Windows, and Ubuntu every 24 hours and on every commit.

glenn-jocher commented 2 years ago

@lamsongianm i.e. python train.py --data coco128.yaml

lamsongianm commented 2 years ago

@glenn-jocher Hello, I am training my model, therefore, I create a new yaml file for training

WechatIMG1395
glenn-jocher commented 2 years ago

@lamsongianm 👋 Hello! Thanks for asking about YOLOv5 🚀 dataset formatting. To train correctly your data must be in YOLOv5 format. Please see our Train Custom Data tutorial for full documentation on dataset setup and all steps required to start training your first model. A few excerpts from the tutorial:

1.1 Create dataset.yaml

COCO128 is an example small tutorial dataset composed of the first 128 images in COCO train2017. These same 128 images are used for both training and validation to verify our training pipeline is capable of overfitting. data/coco128.yaml, shown below, is the dataset config file that defines 1) the dataset root directory path and relative paths to train / val / test image directories (or *.txt files with image paths), 2) the number of classes nc and 3) a list of class names:

# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ../datasets/coco128  # dataset root dir
train: images/train2017  # train images (relative to 'path') 128 images
val: images/train2017  # val images (relative to 'path') 128 images
test:  # test images (optional)

# Classes
nc: 80  # number of classes
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' ]  # class names

1.2 Create Labels

After using a tool like Roboflow Annotate to label your images, export your labels to YOLO format, with one *.txt file per image (if no objects in image, no *.txt file is required). The *.txt file specifications are:

Image Labels

The label file corresponding to the above image contains 2 persons (class 0) and a tie (class 27):

1.3 Organize Directories

Organize your train and val images and labels according to the example below. YOLOv5 assumes /coco128 is inside a /datasets directory next to the /yolov5 directory. YOLOv5 locates labels automatically for each image by replacing the last instance of /images/ in each image path with /labels/. For example:

../datasets/coco128/images/im0.jpg  # image
../datasets/coco128/labels/im0.txt  # label

Good luck 🍀 and let us know if you have any other questions!

lamsongianm commented 2 years ago

@glenn-jocher Hello, I try fixing the problem, but the system shows the same error.

WechatIMG1398 WechatIMG1399

(behavior_detection) ron@VirtualBox:~/PycharmProjects/behavior_detection/yolov5$ python train.py --img 320 --batch 16 --epochs 3 --data dataset.yaml --weights yolov5s.pt usage: train.py [-h] [--weights WEIGHTS] [--cfg CFG] [--training_data TRAINING_DATA] [--hyp HYP] [--epochs EPOCHS] [--batch-size BATCH_SIZE] [--imgsz IMGSZ] [--rect] [--resume [RESUME]] [--nosave] [--noval] [--noautoanchor] [--evolve [EVOLVE]] [--bucket BUCKET] [--cache [CACHE]] [--image-weights] [--device DEVICE] [--multi-scale] [--single-cls] [--optimizer {SGD,Adam,AdamW}] [--sync-bn] [--workers WORKERS] [--project PROJECT] [--name NAME] [--exist-ok] [--quad] [--cos-lr] [--label-smoothing LABEL_SMOOTHING] [--patience PATIENCE] [--freeze FREEZE [FREEZE ...]] [--save-period SAVE_PERIOD] [--local_rank LOCAL_RANK] [--entity ENTITY] [--upload_dataset [UPLOAD_DATASET]] [--bbox_interval BBOX_INTERVAL] [--artifact_alias ARTIFACT_ALIAS] train.py: error: unrecognized arguments: --data dataset.yaml

geduardo commented 2 years ago

Hi @lamsongianm could you solve it? I'm having the same issue

lamsongianm commented 2 years ago

@geduardo I just reinstall the yolov5.....

Robotatron commented 1 year ago

@geduardo I just reinstall the yolov5.....

And did it help?

I have a similar issue - error: unrecognized arguments: –-name

I dont see what is wrong python segment/train.py --img 640 --batch 16 --epochs 300 --data data/coco128-seg.yaml --weights '' --cfg yolov5s.yaml –-name 02-yolo5-s-hyp-high --hyp hyp.scratch-high.yaml

geduardo commented 1 year ago

@geduardo I just reinstall the yolov5.....

And did it help?

I have a similar issue - error: unrecognized arguments: –-name

I dont see what is wrong python segment/train.py --img 640 --batch 16 --epochs 300 --data data/coco128-seg.yaml --weights '' --cfg yolov5s.yaml –-name 02-yolo5-s-hyp-high --hyp hyp.scratch-high.yaml

@Robotatron it looks like you are using a long dash for --name... That's why it's not recognizing the argument

varadtechx commented 1 year ago

Don't leave gaps anywhere between the dash and the arguments. Probably this should solve it. !python train.py --device 0 --batch-size 16 --epochs 100 --img 640 640 --data data/custom_data.yml --hyp data/hyp.scratch.custom.yml --cfg cfg/training/yolov7x-custom.yml --weights yolov7x.pt --name yolov7x-custom.yml

glenn-jocher commented 10 months ago

@varadtechx That's correct 👍. Ensure there are no extra spaces between the dashes and the argument names. This should resolve the issue with the unrecognized arguments. For example, instead of --name or –-name, use --name. Let me know if you need further assistance!

KamranUmer commented 7 months ago

what should be the follow for inference in YOLONAS: I tried the following command but it doesn't works and give me the error.

python inference.py -n 2 --data Rdataset/data.yaml --model yolo_nas_l --weight /average_model.pth --source /test.png --conf 0.5 --save

Error: usage: inference.py [-h] -n NUM [-m {yolo_nas_s,yolo_nas_m,yolo_nas_l}] -w WEIGHT -s SOURCE [-c CONF] [--save] [--hide] inference.py: error: unrecognized arguments: --data Rdataset/data.yaml

KamranUmer commented 7 months ago

Screenshot (507)

This is my directory looks like while the dataset and data.yaml files are at Rdataset directory.

How to resolve this error Please.

glenn-jocher commented 7 months ago

@KamranUmer it appears there's a misunderstanding regarding the usage of the inference.py script for YOLONAS. Based on the error message you've shared, the script does not accept a --data argument, which is why you're encountering the "unrecognized arguments" error.

For YOLONAS inference, you typically need to specify the number of networks (-n), the model type (-m), the weights file (-w), the source file or directory (-s), the confidence threshold (-c), and whether to save the output (--save). The --data argument is not used in this context as it's more relevant for training scenarios where dataset configuration is necessary.

Given your command:

python inference.py -n 2 --data Rdataset/data.yaml --model yolo_nas_l --weight /average_model.pth --source /test.png --conf 0.5 --save

You should remove the --data Rdataset/data.yaml part since it's not recognized by inference.py. Your revised command should look something like this:

python inference.py -n 2 -m yolo_nas_l -w /average_model.pth -s /test.png -c 0.5 --save

Make sure the paths to your weights file (-w) and source image (-s) are correct. If /average_model.pth and /test.png are meant to be relative paths from the current directory, you might need to remove the leading slash to avoid pointing to the root directory of your filesystem.

If you have further questions or encounter more issues, feel free to ask!