Переделал рекурсию на цикл.
Some checks are pending
Build/Publish Develop Docs / deploy (push) Waiting to run
Some checks are pending
Build/Publish Develop Docs / deploy (push) Waiting to run
This commit is contained in:
@@ -116,10 +116,25 @@ class SimpleDataSet(Dataset):
|
|||||||
ext_data.append(data)
|
ext_data.append(data)
|
||||||
return ext_data
|
return ext_data
|
||||||
|
|
||||||
|
def create_dummy_sample(self):
|
||||||
|
"""Создает пустой образец для предотвращения сбоев"""
|
||||||
|
dummy_img = np.zeros((32, 320, 3), dtype=np.uint8)
|
||||||
|
dummy_img = cv2.imencode('.jpg', dummy_img)[1].tobytes()
|
||||||
|
|
||||||
|
return {
|
||||||
|
"image": dummy_img,
|
||||||
|
"label": "",
|
||||||
|
"img_path": "dummy.jpg",
|
||||||
|
"ext_data": self.get_ext_data(),
|
||||||
|
"filename": "dummy.jpg"
|
||||||
|
}
|
||||||
|
|
||||||
def __getitem__(self, idx):
|
def __getitem__(self, idx):
|
||||||
|
max_attempts = 10
|
||||||
|
for attempt in range(max_attempts):
|
||||||
|
try:
|
||||||
file_idx = self.data_idx_order_list[idx]
|
file_idx = self.data_idx_order_list[idx]
|
||||||
data_line = self.data_lines[file_idx]
|
data_line = self.data_lines[file_idx]
|
||||||
try:
|
|
||||||
data_line = data_line.decode("utf-8")
|
data_line = data_line.decode("utf-8")
|
||||||
substr = data_line.strip("\n").split(self.delimiter)
|
substr = data_line.strip("\n").split(self.delimiter)
|
||||||
file_name = substr[0]
|
file_name = substr[0]
|
||||||
@@ -135,23 +150,23 @@ class SimpleDataSet(Dataset):
|
|||||||
data["ext_data"] = self.get_ext_data()
|
data["ext_data"] = self.get_ext_data()
|
||||||
data["filename"] = data["img_path"]
|
data["filename"] = data["img_path"]
|
||||||
outs = transform(data, self.ops)
|
outs = transform(data, self.ops)
|
||||||
|
return outs
|
||||||
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
print("HERE", str(exc))
|
if attempt < max_attempts - 1:
|
||||||
self.logger.error(
|
idx = (
|
||||||
"When parsing line {}, error happened with msg: {}".format(
|
|
||||||
data_line, traceback.format_exc()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
outs = None
|
|
||||||
if outs is None:
|
|
||||||
# during evaluation, we should fix the idx to get same results for many times of evaluation.
|
|
||||||
rnd_idx = (
|
|
||||||
np.random.randint(self.__len__())
|
np.random.randint(self.__len__())
|
||||||
if self.mode == "train"
|
if self.mode == "train"
|
||||||
else (idx + 1) % self.__len__()
|
else (idx + 1) % self.__len__()
|
||||||
)
|
)
|
||||||
return self.__getitem__(rnd_idx)
|
|
||||||
return outs
|
self.logger.error(
|
||||||
|
"Failed after {} attempts: {}".format(
|
||||||
|
max_attempts, str(exc)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return self.create_dummy_sample()
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.data_idx_order_list)
|
return len(self.data_idx_order_list)
|
||||||
|
|||||||
Reference in New Issue
Block a user