You've already forked JapariArchive
fixed memory leak related to video files
This commit is contained in:
@@ -15,7 +15,7 @@ async def classify_all(photo_bytes, wd_classifier: WDClassifier, vox_classifier
|
||||
phash = None
|
||||
dhash = None
|
||||
error_id = ErrorID.SUCCESS
|
||||
if not is_filtered:
|
||||
if not is_filtered: #won't execute if photo bytes is None (is video)
|
||||
rating, tags, filtered_tags = await wd_classifier.classify_async(photo_bytes, tag_threshold=0.6)
|
||||
tags = list(tags.keys())
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ from io import BytesIO
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from transformers import ViTForImageClassification, ViTImageProcessor
|
||||
|
||||
from Database.x_classes import HavoxLabel
|
||||
|
||||
class VoxClassifier():
|
||||
def __init__(self):
|
||||
self.feature_extractor = ViTImageProcessor.from_pretrained('Classifier/HAV0X/')
|
||||
@@ -21,9 +23,13 @@ class VoxClassifier():
|
||||
return self.model.config.id2label[predicted_class_idx]
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
return "Rejected"
|
||||
return HavoxLabel.Rejected
|
||||
|
||||
async def classify_async(self, image_bytes):
|
||||
if not image_bytes:
|
||||
#mainly for video files
|
||||
print("image bytes was null")
|
||||
return HavoxLabel.Rejected
|
||||
with ThreadPoolExecutor() as executor:
|
||||
future = executor.submit(self.classify, image_bytes)
|
||||
|
||||
|
||||
@@ -59,6 +59,10 @@ class WDClassifier():
|
||||
return "", {}, {}
|
||||
|
||||
async def classify_async(self, image_bytes, max_count = -1, tag_threshold = -1):
|
||||
if not image_bytes:
|
||||
#mainly for video files
|
||||
print("image bytes was null")
|
||||
return "", {}, {}
|
||||
with ThreadPoolExecutor() as executor:
|
||||
future = executor.submit(self.classify, image_bytes, max_count, tag_threshold)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user