feat(txt2img): allow from_file to work with len(lines) < batch_size (#349)

This commit is contained in:
Olivier Louvignes 2022-09-06 12:41:08 +02:00 committed by GitHub
parent 720e5cd651
commit eef788981c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -232,7 +232,12 @@ def main():
print(f"reading prompts from {opt.from_file}") print(f"reading prompts from {opt.from_file}")
with open(opt.from_file, "r") as f: with open(opt.from_file, "r") as f:
data = f.read().splitlines() data = f.read().splitlines()
if (len(data) >= batch_size):
data = list(chunk(data, batch_size)) data = list(chunk(data, batch_size))
else:
while (len(data) < batch_size):
data.append(data[-1])
data = [data]
sample_path = os.path.join(outpath, "samples") sample_path = os.path.join(outpath, "samples")
os.makedirs(sample_path, exist_ok=True) os.makedirs(sample_path, exist_ok=True)