Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: WindowsPath('.') has an empty name #66

Closed
cvhrnkmp opened this issue Dec 6, 2024 · 4 comments
Closed

ValueError: WindowsPath('.') has an empty name #66

cvhrnkmp opened this issue Dec 6, 2024 · 4 comments

Comments

@cvhrnkmp
Copy link

cvhrnkmp commented Dec 6, 2024

Hello guys,

I got the following error after I run the following command:

Command

python train.py --data Dataset --model m-doclayout --epoch 5 --image-size 1600 --project first_shot --device cpu

ERROR

Traceback (most recent call last):
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\train.py", line 63, in <module>
    results = model.train(
              ^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\engine\model.py", line 660, in train
    self.trainer.train()
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\engine\trainer.py", line 214, in train
    self._do_train(world_size)
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\engine\trainer.py", line 328, in _do_train
    self._setup_train(world_size)
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\engine\trainer.py", line 292, in _setup_train
    self.train_loader = self.get_dataloader(self.trainset, batch_size=batch_size, rank=RANK, mode="train")
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\models\yolo\detect\train.py", line 52, in get_dataloader
    dataset = self.build_dataset(dataset_path, mode, batch_size)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\models\yolo\detect\train.py", line 46, in build_dataset
    return build_yolo_dataset(self.args, img_path, batch, self.data, mode=mode, rect=mode == "val", stride=gs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\data\build.py", line 113, in build_yolo_dataset
    return YOLODataset(
           ^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\data\dataset.py", line 43, in __init__
    super().__init__(*args, **kwargs)
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\data\base.py", line 77, in __init__
    self.labels = self.get_labels()
                  ^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\data\dataset.py", line 140, in get_labels
    cache_path = Path(self.label_files[0]).parent.with_suffix(".cache")
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\pathlib.py", line 694, in with_suffix
    raise ValueError("%r has an empty name" % (self,))
ValueError: WindowsPath('.') has an empty name

Why do I get the above error and how can I avoid it?

Best regards
Christian

Appendix:

The folder structure is:

./DocLayout-YOLO-main
├── layout_data
│   ├── Dataset
│        ├── images
│        ├── labels
│        ├── val.txt
│        ├── text.txt
│        └── train.txt
├── Dataset.yaml
└── train.py

The Dataset.yaml is the config file and looks like this:

# Ultralytics YOLO 🚀, AGPL-3.0 license
# COCO 2017 dataset https://cocodataset.org by Microsoft
# Documentation: https://docs.doclayout_yolo.com/datasets/detect/coco/
# Example usage: yolo train data=coco.yaml
# parent
# ├── doclayout_yolo
# └── datasets
#     └── coco  ← downloads here (20.1 GB)

# 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: ./Dataset  # dataset root dir
train: ./train.txt # train images (relative to 'path') 118287 images
val: ./val.txt # val images (relative to 'path') 5000 images
test: ./test.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794

# Classes
names:
    0: 'figure'
    1: 'paragraph'
    2: 'section title'
    3: 'sub section title'
    4: 'subsub section title'
    5: 'table'

The settings.yaml in Ultraytics is set as follows:

settings_version: 0.0.4
datasets_dir: C:\Users\Programming\Documents\DocLayout-YOLO-main\layout_data
weights_dir: <Path_to_weights>\weights
runs_dir: <Path_to_runs>\runs
uuid: 4ba298c8490b48eee0c6ce4e5fcc68f485c9ae144b377321d03ec0fcd42d63dc
sync: true
api_key: ''
openai_api_key: ''
clearml: true
comet: true
dvc: true
hub: true
mlflow: true
neptune: true
raytune: true
tensorboard: true
wandb: true
@JulioZhao97
Copy link
Collaborator

@cvhrnkmp Hello!
It seems that the erorr is because WINDOWS not support current file path structure, for example, in our provided datasets, the label file in train.txt begins with ., such as ./layout_data/doclaynet/images/xxx.jpg. From traceback information it seems that Path(self.label_files[0]) is not supported in WINDOWS?

  1. Could you please print self.label_files[0] in
File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\data\dataset.py", line 140, in get_labels
    cache_path = Path(self.label_files[0]).parent.with_suffix(".cache")
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

where the error occurs and see this variable self.label_files[0]?

  1. What dataset are you using? Is your custom dataset? Could you please change relative path in train.txt to resolute path and give it a try? Meanwhile, the dataset yaml file Dataset.yaml should be placed under doclayout_yolo/cfg/datasets/.

@cvhrnkmp
Copy link
Author

cvhrnkmp commented Dec 9, 2024

@JulioZhao97 Hello

  1. The following is stored in self.label_files[0]:

    self.label_files[0]: 37b4ef0c-page_4.txt

  2. It's a custom dataset prepared with label-studio and exported as COCO-format. I edit the Dataset.yaml to the following:

# Ultralytics YOLO 🚀, AGPL-3.0 license
# COCO 2017 dataset https://cocodataset.org by Microsoft
# Documentation: https://docs.doclayout_yolo.com/datasets/detect/coco/
# Example usage: yolo train data=coco.yaml
# parent
# ├── doclayout_yolo
# └── datasets
#     └── coco  ← downloads here (20.1 GB)

# 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: ./Dataset  # dataset root dir
train: C:\Users\Programming\Documents\DocLayout-YOLO-main\layout_data\Dataset\train.txt 
val: ./val.txt # val images (relative to 'path') 5000 images
test: ./test.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794

# Classes
names:
    0: 'figure'
    1: 'paragraph'
    2: 'section title'
    3: 'sub section title'
    4: 'subsub section title'
    5: 'table'

I also try to write the path with / --> C:/Users/Programming/Documents/DocLayout-YOLO-main/layout_data/Dataset/train.txt
Further, I put Dataset.yaml in the doclayout_yolo/cfg/datasets/ folder. But I got the same error:

TensorBoard: Start with 'tensorboard --logdir first_shot\yolov10m-doclayout_Dataset_epoch5_imgsz1600_bs16_pretrain_None27', view at http://localhost:6006/
Freezing layer 'model.23.dfl.conv.weight'
C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\engine\trainer.py:277: FutureWarning: `torch.cuda.amp.GradScaler(args...)` is deprecated. Please use `torch.amp.GradScaler('cuda', args...)` instead.
  self.scaler = torch.cuda.amp.GradScaler(enabled=self.amp)
self.label_files[0]:  37b4ef0c-page_4.txt
.
Traceback (most recent call last):
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\train.py", line 63, in <module>
    results = model.train(
              ^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\engine\model.py", line 660, in train
    self.trainer.train()
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\engine\trainer.py", line 214, in train
    self._do_train(world_size)
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\engine\trainer.py", line 328, in _do_train
    self._setup_train(world_size)
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\engine\trainer.py", line 292, in _setup_train
    self.train_loader = self.get_dataloader(self.trainset, batch_size=batch_size, rank=RANK, mode="train")
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\models\yolo\detect\train.py", line 52, in get_dataloader
    dataset = self.build_dataset(dataset_path, mode, batch_size)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\models\yolo\detect\train.py", line 46, in build_dataset
    return build_yolo_dataset(self.args, img_path, batch, self.data, mode=mode, rect=mode == "val", stride=gs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\data\build.py", line 113, in build_yolo_dataset
    return YOLODataset(
           ^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\data\dataset.py", line 43, in __init__
    super().__init__(*args, **kwargs)
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\data\base.py", line 77, in __init__
    self.labels = self.get_labels()
                  ^^^^^^^^^^^^^^^^^
  File "C:\Users\Programming\Documents\DocLayout-YOLO-main\doclayout_yolo\data\dataset.py", line 140, in get_labels
    cache_path = Path(self.label_files[0]).parent.with_suffix(".cache")
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\pathlib.py", line 694, in with_suffix
    raise ValueError("%r has an empty name" % (self,))
ValueError: WindowsPath('.') has an empty name```

@JulioZhao97
Copy link
Collaborator

@cvhrnkmp Did you try using absolute path in train.txt, which means image path in train.txt mush be absolute path?

@cvhrnkmp
Copy link
Author

cvhrnkmp commented Dec 10, 2024

Thanks @JulioZhao97 , that works for me. But I got a new error #68 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants