未验证 提交 3384dcaa 编写于 作者: L littletomatodonkey 提交者: GitHub

fix reader in release (#676)

上级 725a8ffd
...@@ -16,6 +16,7 @@ import numpy as np ...@@ -16,6 +16,7 @@ import numpy as np
import imghdr import imghdr
import os import os
import signal import signal
import random
from paddle.io import Dataset, DataLoader, DistributedBatchSampler from paddle.io import Dataset, DataLoader, DistributedBatchSampler
...@@ -182,12 +183,17 @@ class CommonDataset(Dataset): ...@@ -182,12 +183,17 @@ class CommonDataset(Dataset):
return return
def __getitem__(self, idx): def __getitem__(self, idx):
line = self.full_lines[idx] try:
img_path, label = line.split(self.delimiter) line = self.full_lines[idx]
img_path = os.path.join(self.params['data_dir'], img_path) img_path, label = line.split(self.delimiter)
with open(img_path, 'rb') as f: img_path = os.path.join(self.params['data_dir'], img_path)
img = f.read() with open(img_path, 'rb') as f:
return (transform(img, self.ops), int(label)) img = f.read()
return (transform(img, self.ops), int(label))
except Exception as e:
logger.error("data read faild: {}, exception info: {}".format(line,
e))
return self.__getitem__(random.randint(0, len(self)))
def __len__(self): def __len__(self):
return self.num_samples return self.num_samples
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册