Skip to content

Commit

Permalink
CogVLM: Allow removing image files after caption
Browse files Browse the repository at this point in the history
  • Loading branch information
Bghira Bagheera committed Dec 2, 2023
1 parent 18ed772 commit 47fcd15
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions toolkit/captioning/caption_with_cogvlm.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def parse_args():
default=100,
help="Interval to save progress (number of files processed).",
)
parser.add_argument(
"--delete_after_caption",
action="store_true",
default=False,
help="Delete *input* image files after captioning."
)
return parser.parse_args()

def load_filter_list(filter_list_path):
Expand Down Expand Up @@ -113,6 +119,7 @@ def content_to_filename(content, filter_terms):


def process_directory(
args,
image_dir,
output_dir,
model,
Expand All @@ -139,6 +146,7 @@ def process_directory(
full_filepath = os.path.join(image_dir, filename)
if os.path.isdir(full_filepath):
process_directory(
args,
full_filepath,
output_dir,
model,
Expand Down Expand Up @@ -169,6 +177,9 @@ def process_directory(
counter += 1

image.save(new_filepath)
# Remove the original file if args.delete_after_caption
if args.delete_after_caption:
os.remove(full_filepath)

if caption_strategy == "text":
with open(new_filepath + ".txt", "w") as f:
Expand Down Expand Up @@ -229,6 +240,7 @@ def main():

# Process directory
process_directory(
args,
args.input_dir,
args.output_dir,
model,
Expand Down

0 comments on commit 47fcd15

Please sign in to comment.