--random for --feed-from-tags
Browse files
joy
CHANGED
@@ -17,6 +17,7 @@ The main components include:
|
|
17 |
import os
|
18 |
import argparse
|
19 |
import re
|
|
|
20 |
from pathlib import Path
|
21 |
from PIL import Image
|
22 |
import pillow_jxl
|
@@ -453,9 +454,18 @@ def main():
|
|
453 |
const=-1,
|
454 |
help='Use .txt files with the same base filename as the images as input to the captioner. Optionally specify the number of tags to use.'
|
455 |
)
|
|
|
|
|
|
|
|
|
|
|
456 |
|
457 |
args = parser.parse_args()
|
458 |
|
|
|
|
|
|
|
|
|
459 |
# Initialize and load models
|
460 |
joy_caption_model = JoyCaptionModel()
|
461 |
joy_caption_model.load_models()
|
@@ -495,7 +505,12 @@ def main():
|
|
495 |
with open(tag_file, 'r', encoding='utf-8') as f:
|
496 |
tags = f.read().strip().split(',')
|
497 |
|
498 |
-
if args.
|
|
|
|
|
|
|
|
|
|
|
499 |
tags = tags[:args.feed_from_tags]
|
500 |
|
501 |
tag_string = ', '.join(tags)
|
|
|
17 |
import os
|
18 |
import argparse
|
19 |
import re
|
20 |
+
import random
|
21 |
from pathlib import Path
|
22 |
from PIL import Image
|
23 |
import pillow_jxl
|
|
|
454 |
const=-1,
|
455 |
help='Use .txt files with the same base filename as the images as input to the captioner. Optionally specify the number of tags to use.'
|
456 |
)
|
457 |
+
parser.add_argument(
|
458 |
+
'--random-tags',
|
459 |
+
type=int,
|
460 |
+
help='Randomly select n number of tags. Only works if --feed-from-tags is enabled.'
|
461 |
+
)
|
462 |
|
463 |
args = parser.parse_args()
|
464 |
|
465 |
+
# Validate random-tags usage
|
466 |
+
if args.random_tags is not None and args.feed_from_tags is None:
|
467 |
+
parser.error("--random-tags can only be used when --feed-from-tags is enabled")
|
468 |
+
|
469 |
# Initialize and load models
|
470 |
joy_caption_model = JoyCaptionModel()
|
471 |
joy_caption_model.load_models()
|
|
|
505 |
with open(tag_file, 'r', encoding='utf-8') as f:
|
506 |
tags = f.read().strip().split(',')
|
507 |
|
508 |
+
if args.random_tags is not None:
|
509 |
+
# Randomly select tags if --random-tags is specified
|
510 |
+
num_tags = min(args.random_tags, len(tags))
|
511 |
+
tags = random.sample(tags, num_tags)
|
512 |
+
elif args.feed_from_tags > 0:
|
513 |
+
# Use specified number of tags if --feed-from-tags has a positive value
|
514 |
tags = tags[:args.feed_from_tags]
|
515 |
|
516 |
tag_string = ', '.join(tags)
|