Skip to content

ERROR: Unexpected segmentation fault encountered in worker. RuntimeError: DataLoader worker (pid 237557) is killed by signal: Segmentation fault. #184

Description

@2effort

每次训练几轮后出现段错误。这个错误是用lmdb加载数据导致的,只要在abstract_dataset.py文件中,把下面这部分获取self.env改成在def getitem(self, index, no_norm=False):这个函数中,就能保证模型完全正常训练。主要是不能在初始化的时候就打开lmdb。

if mode == 'train':
dataset_list = config['train_dataset']
# Training data should be collected together for training
image_list, label_list = [], []
for one_data in dataset_list:
tmp_image, tmp_label, tmp_name = self.collect_img_and_label_for_one_dataset(one_data)
image_list.extend(tmp_image)
label_list.extend(tmp_label)
#
if self.lmdb:
# 如果训练数据集合大与1个,则进入if
if len(dataset_list)>1:
if all_in_pool(dataset_list,FFpp_pool):
lmdb_path = os.path.join(config['lmdb_dir'], f"FaceForensics++_lmdb")
self.env = lmdb.open(lmdb_path, create=False, subdir=True, readonly=True, lock=False)
else:
raise ValueError('Training with multiple dataset and lmdb is not implemented yet.')
else:
lmdb_path = os.path.join(config['lmdb_dir'], f"{dataset_list[0] if dataset_list[0] not in FFpp_pool else 'FaceForensics++'}_lmdb")
self.env = lmdb.open(lmdb_path, create=False, subdir=True, readonly=True, lock=False)
elif mode == 'test':
one_data = config['test_dataset']
# Test dataset should be evaluated separately. So collect only one dataset each time
#image_list对应的是图片的具体路径,label_list对应每张图片的标签,name_list对应视频的名称,他们一一对应
image_list, label_list, name_list = self.collect_img_and_label_for_one_dataset(one_data)
if self.lmdb:
# 这段代码用于构建 LMDB 数据库的路径,并以只读模式打开该数据库。
lmdb_path = os.path.join(config['lmdb_dir'], f"{one_data}_lmdb" if one_data not in FFpp_pool else 'FaceForensics++_lmdb')
# 下面的代码是打开lmdb数据
self.env = lmdb.open(lmdb_path, create=False, subdir=True, readonly=True, lock=False)
else:
raise NotImplementedError('Only train and test modes are supported.')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions