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

自制数据集训练报错Error occurred during training with self-made dataset #44

Open
gobranchya opened this issue Jan 14, 2025 · 0 comments

Comments

@gobranchya
Copy link

我在用自己的数据集跑YOWOv2的算法,出现了以下报错,不知道如何解决:
File "train.py", line 330, in
train()
File "train.py", line 222, in train
for iter_i, (frame_ids, video_clips, targets) in enumerate(dataloader):
File "/root/miniconda3/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 521, in next
data = self._next_data()
File "/root/miniconda3/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1203, in _next_data
return self._process_data(data)
File "/root/miniconda3/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1229, in _process_data
data.reraise()
File "/root/miniconda3/lib/python3.8/site-packages/torch/_utils.py", line 425, in reraise
raise self.exc_type(msg)
IndexError: Caught IndexError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/root/miniconda3/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
data = fetcher.fetch(index)
File "/root/miniconda3/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/root/miniconda3/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/root/YOWOv2/dataset/ava.py", line 156, in getitem
frame_idx, video_clip, target = self.pull_item(idx)
File "/root/YOWOv2/dataset/ava.py", line 178, in pull_item
keyframe_info = self._image_paths[video_idx][frame_idx - 1]
IndexError: list index out of range

Try to modify some specific parameters to be relevant to your own dataset. I am using a 60-second video with 30 frames per second to detect 6 actions, and modify the following modules:
尝试将一些特定的参数修改为自己数据集相关,我使用的60秒30帧的视频检测6个动作,对以下几个模块进行修改:
class AVA_Dataset(Dataset):
def init(self,
cfg,
data_root,
is_train=False,
img_size=224,
transform=None,
len_clip=60,
sampling_rate=1):
self.num_classes = 6

if name == 'main':
import cv2
from transforms import Augmentation, BaseTransform

is_train = False
img_size = 224
len_clip = 60
sampling_rate = 1

parser.add_argument('-K', '--len_clip', default=60, type=int,
help='video clip length.')

I know the problem lies in the following function, but I don't know how to modify it.
我知道问题出现在以下函数,不知道如何修改:
def pull_item(self, idx):
# Get the frame idxs for current clip. We can use it as center or latest
video_idx, sec_idx, sec, frame_idx = self._keyframe_indices[idx]
clip_label_list = self._keyframe_boxes_and_labels[video_idx][sec_idx]

    # check label list
    assert len(clip_label_list) > 0
    assert len(clip_label_list) <= self._max_objs

    # get a sequence
    seq = self.get_sequence(
        frame_idx,
        self.seq_len // 2,
        self.sampling_rate,
        num_frames=len(self._image_paths[video_idx]),
    )
    image_paths = [self._image_paths[video_idx][frame - 1] for frame in seq]
    keyframe_info = self._image_paths[video_idx][frame_idx - 1]

    # load a video clip
    video_clip = []
    for img_path in image_paths:
        frame = Image.open(img_path).convert('RGB')
        video_clip.append(frame)
    ow, oh = frame.width, frame.height

    # Get boxes and labels for current clip.
    boxes = []
    labels = []
    for box_labels in clip_label_list:
        bbox = box_labels[0]
        label = box_labels[1]
        multi_hot_label = np.zeros(1 + self.num_classes)
        multi_hot_label[..., label] = 1.0

        boxes.append(bbox)
        labels.append(multi_hot_label[..., 1:].tolist())

    boxes = np.array(boxes).reshape(-1, 4)
    # renormalize bbox
    boxes[..., [0, 2]] *= ow
    boxes[..., [1, 3]] *= oh
    labels = np.array(labels).reshape(-1, self.num_classes)

    # target: [N, 4 + C]
    target = np.concatenate([boxes, labels], axis=-1)

    # transform
    video_clip, target = self.transform(video_clip, target)
    # List [T, 3, H, W] -> [3, T, H, W]
    video_clip = torch.stack(video_clip, dim=1)

    # reformat target
    target = {
        'boxes': target[:, :4].float(),  # [N, 4]
        'labels': target[:, 4:].long(),  # [N, C]
        'orig_size': [ow, oh],
        'video_idx': video_idx,
        'sec': sec,

    }

    return [video_idx, sec], video_clip, target
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

1 participant