-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinference.py
More file actions
29 lines (24 loc) · 1.4 KB
/
inference.py
File metadata and controls
29 lines (24 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from argparse import ArgumentParser
from minimagen.generate import load_minimagen, sample_and_save
# Command line argument parser
parser = ArgumentParser()
parser.add_argument("-c", "--CAPTIONS", dest="CAPTIONS", help="Single caption to generate for or filepath for .txt "
"file of captions to generate for", default=None, type=str)
parser.add_argument("-d", "--TRAINING_DIRECTORY", dest="TRAINING_DIRECTORY", help="Training directory to use for inference", type=str)
args = parser.parse_args()
minimagen = load_minimagen(args.TRAINING_DIRECTORY)
if args.CAPTIONS is None:
print("\nNo caption supplied - using the default of \"a happy dog\".\n")
captions = ['a happy dog']
elif not args.CAPTIONS.endswith(".txt"):
captions = [args.CAPTIONS]
elif args.CAPTIONS.endswith(".txt"):
with open(args.CAPTIONS, 'r') as f:
lines = f.readlines()
captions = [line[:-1] if line.endswith('\n') else line for line in lines]
else:
raise ValueError("Input a valid argument for --CAPTIONS")
# Can supply a training dictionary to load from for inference
sample_and_save(captions, training_directory=args.TRAINING_DIRECTORY, sample_args={'cond_scale':3.})
# Otherwise, can supply a MinImagen instance itself. In this case, information about the instance will not be saved.
# sample_and_save(captions, minimagen=minimagen, sample_args={'cond_scale':3.})