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

Enhanced image loading reliability with error handling #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions captioner/fast_captioner_lmdeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ def __len__(self):

def __getitem__(self, idx):
video_img_list = self.video_dir_list[idx]
img_path_list = os.listdir(video_img_list)
img_path_list.sort()
images = [Image.open(os.path.join(video_img_list, img_path)).convert('RGB') for img_path in img_path_list]
try:
img_path_list = os.listdir(video_img_list)
img_path_list.sort()
images = [Image.open(os.path.join(video_img_list, img_path)).convert('RGB') for img_path in img_path_list]
except Exception as e:
print(f"Error loading image: {e}")
return None

img_width, img_height = images[0].size
grid_image = Image.new('RGB', (self.img_grid_w * img_width, self.img_grid_h * img_height))
Expand All @@ -72,8 +76,9 @@ def custom_collate_fn(batch):
input_list = []
filename_list = []
for item in batch:
input_list.append(item[0])
filename_list.append(item[1])
if item:
input_list.append(item[0])
filename_list.append(item[1])
return input_list, filename_list

def parse_args():
Expand Down Expand Up @@ -111,4 +116,4 @@ def parse_args():
}
filename = filename.split('/')[-1]
with open(os.path.join(args.save_path, filename+'.json'), 'w') as f:
f.write(json.dumps(finish_data, indent=2, ensure_ascii=False))
f.write(json.dumps(finish_data, indent=2, ensure_ascii=False))