Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'''
inputs:
image_paths: list of image paths or can be a string too (for single image)
batch_size: batch_size for running predictions
image_size: size to which the image needs to be resized
categories: since the model predicts numbers, categories is the list of actual names of categories
'''
if isinstance(image_paths, str):
image_paths = [image_paths]
loaded_images, loaded_image_paths = load_images(image_paths, image_size)
if not loaded_image_paths:
return {}
model_preds = Classifier.nsfw_model.predict(loaded_images, batch_size = batch_size)
preds = np.argsort(model_preds, axis = 1).tolist()
probs = []
for i, single_preds in enumerate(preds):
single_probs = []
for j, pred in enumerate(single_preds):
single_probs.append(model_preds[i][pred])
preds[i][j] = categories[pred]
probs.append(single_probs)
images_preds = {}
for i, loaded_image_path in enumerate(loaded_image_paths):