Do batch prediction.

Do batch prediction inside the `predict` method instead of calling
`predict` once for each image.
This commit is contained in:
evazion
2022-06-21 20:08:14 -05:00
parent 5c90c7378d
commit 07b84d73fe
4 changed files with 30 additions and 16 deletions
+6 -2
View File
@@ -12,8 +12,12 @@ from fastai.vision.core import PILImage
@click.argument("file", nargs=-1, type=click.File("rb"), required=True)
def main(file, threshold, limit, model):
autotagger = Autotagger(model)
predictions = [{ "filename": f.name, "tags": autotagger.predict(PILImage.create(f), threshold=threshold, limit=limit) } for f in file]
click.echo(json.dumps(predictions, indent=2))
images = [PILImage.create(f) for f in file]
predictions = autotagger.predict(images, threshold=threshold, limit=limit)
for i, tags in enumerate(predictions):
data = { "filename": file[i].name, "tags": tags }
click.echo(json.dumps(data))
if __name__ == "__main__":
main()