jamesljlster / yoro

A YOLO Variant for Rotated Object Detection
GNU General Public License v3.0
29 stars 5 forks source link

custom data training error #5

Closed ghost closed 1 year ago

ghost commented 1 year ago

hi, i'm here XD.

i want to train my data. so i change config , just dataset part (file path) on example.yaml in your configs. ( anchor is not change, because you said it is also okay to skip.)

And my dataset have 62 classes and more than 20 detections per picture. And train dataset are 2,207.

dataset structure is same. data

my train error code is below. Do you konw why it have IndexError? Thank you for your help.


=== Validation on Iter 0 === 0%| | 0/1 [00:00<?, ?it/s]/home/yjoh/anaconda3/envs/yoro-env/lib/python3.8/site-packages/yoro/transforms/rbox.py:356: UserWarning: Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at /opt/conda/conda-bld/pytorch_1646755903507/work/torch/csrc/utils/tensor_new.cpp:210.) [torch.tensor(elem, dtype=dtype) for (elem, dtype) in Traceback (most recent call last):
File "/home/yjoh/anaconda3/envs/yoro-env/bin/trainer", line 69, in tc.valid() File "/home/yjoh/anaconda3/envs/yoro-env/lib/python3.8/site-packages/yoro/utils/train_util/base_train.py", line 255, in valid for inst in loop: File "/home/yjoh/anaconda3/envs/yoro-env/lib/python3.8/site-packages/tqdm/std.py", line 1195, in iter for obj in iterable: File "/home/yjoh/anaconda3/envs/yoro-env/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 530, in next data = self._next_data() File "/home/yjoh/anaconda3/envs/yoro-env/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1224, in _next_data return self._process_data(data) File "/home/yjoh/anaconda3/envs/yoro-env/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1250, in _process_data data.reraise() File "/home/yjoh/anaconda3/envs/yoro-env/lib/python3.8/site-packages/torch/_utils.py", line 457, in reraise raise exception IndexError: Caught IndexError in DataLoader worker process 0. Original Traceback (most recent call last): File "/home/yjoh/anaconda3/envs/yoro-env/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop data = fetcher.fetch(index) File "/home/yjoh/anaconda3/envs/yoro-env/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 49, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/yjoh/anaconda3/envs/yoro-env/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 49, in data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/yjoh/anaconda3/envs/yoro-env/lib/python3.8/site-packages/yoro/datasets.py", line 96, in getitem sample = self.transform(sample) File "/home/yjoh/anaconda3/envs/yoro-env/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 95, in call img = t(img) File "/home/yjoh/anaconda3/envs/yoro-env/lib/python3.8/site-packages/yoro/transforms/rbox.py", line 423, in call anno = self.tgtBuilder(anno) File "/home/yjoh/anaconda3/envs/yoro-env/lib/python3.8/site-packages/yoro/transforms/rbox.py", line 313, in call if not objs[headIdx][acrIdx, yIdx, xIdx]: IndexError: index 7 is out of bounds for dimension 1 with size 7


example) data.jpg.mark

data.names

jamesljlster commented 1 year ago

Hi @yjoh-autonics,

Glad to see you again! XD

The error indicates that yIdx is out of bound. Maybe there are some problems in your dataset annotations. Would you help me run the following script to check your dataset?

from tqdm import tqdm
from yoro.datasets import RBoxSample

# Load dataset
dataset = RBoxSample(
    image_dir='~/dataset/coating/valid',
    names_file='~/dataset/coating/coating.names'
)

# Check for annotations
for sample_idx, (image, anno) in enumerate(tqdm(dataset, desc='Checking annotation')):
    for idx, inst in enumerate(anno):
        valid = (
            (inst['x'] >= 0 and inst['x'] < image.width) and
            (inst['y'] >= 0 and inst['y'] < image.height)
        )
        if not valid:
            image_path = dataset.instList[idx]['file']
            print(f'Annotation {idx} is not valid for image {image_path}')

And please don't forget to replace image_dir and names_file according to your dataset location.

Also, you may give yolov4-tiny.yaml a try. It would have better performance.

ghost commented 1 year ago

In the result of returning to the code you gave, there are strange data. I don't know why those data appeared. inst means my mark data? but it has difference in mine. Do you have any code to convert the data?

example) `from tqdm import tqdm from yoro.datasets import RBoxSample

out: here {'degree': 34.5, 'h': 76.17999999999995, 'label': 61, 'w': 65.35000000000014, 'x': 1246.295, 'y': 723.81} image.width, image.height 1280 720 inst['x'],inst['y'] 1246.295 723.81 True False Annotation 6 is not valid for image /home/yjoh/Desktop/code/08_yolo_angle/221214_yoro/dataset/custom/train/data-1000.jpg

my data all (data-1000.jpg.mark):

jamesljlster commented 1 year ago

Hi @yjoh-autonics,

Oops! I'm sorry, the script should be:

from tqdm import tqdm
from yoro.datasets import RBoxSample

# Load dataset
dataset = RBoxSample(
    image_dir='~/dataset/coating/valid',
    names_file='~/dataset/coating/coating.names'
)

# Check for annotations
for sample_idx, (image, anno) in enumerate(tqdm(dataset, desc='Checking annotation')):
    for idx, inst in enumerate(anno):
        valid = (
            (inst['x'] >= 0 and inst['x'] < image.width) and
            (inst['y'] >= 0 and inst['y'] < image.height)
        )
        if not valid:
            image_path = dataset.instList[sample_idx]['file']
            print(f'Annotation {idx} is not valid for image {image_path}')

There is a mistake in getting image_path. It should be sample_idx instead of idx. Please have a try!

ghost commented 1 year ago

I posted a late reply because I was learning. It works well :) Thank your answer!