Better fix for #2 (Crashes when encountering files that aren't images)

* Only ignore invalid files in the `autotag` script, not in the
  web service. In the web service we want to return an error if given an
  invalid or corrupt file.

* Use the logger to log a warning instead of printing directly to stderr.
This commit is contained in:
evazion
2022-06-29 18:06:11 -05:00
parent 6719ed3a40
commit b2160576fc
2 changed files with 24 additions and 11 deletions
+4 -7
View File
@@ -28,14 +28,11 @@ class Autotagger:
return learn
def predict(self, files, threshold=0.01, limit=50, bs=64):
if not files:
return
with self.learn.no_bar(), self.learn.no_logging():
def create_image(file):
try:
return PILImage.create(file)
except:
print("skipped file " + file.name, file=sys.stderr)
return None
images = list(filter(lambda i: i != None, [create_image(file) for file in files]))
images = [PILImage.create(file) for file in files]
dl = self.learn.dls.test_dl(images, bs=bs)
batch, _ = self.learn.get_preds(dl=dl)