You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've downloaded pre-trained model from there, which is 20180402-114759-vggface2.pt. I've used this in python and it is working fine with great accuracy.
python.py:
from facenet_pytorch import MTCNN, InceptionResnetV1
from PIL import Image
import torch
mtcnn = MTCNN(image_size=160, margin=0)
resnet = InceptionResnetV1(pretrained='vggface2').eval()
resnet.load_state_dict(torch.load('../20180402-114759-vggface2.pt'), strict=False)
img1 = Image.open('../img1')
img2 = Image.open('../img2')
img1_cropped = mtcnn(img1)
img2_cropped = mtcnn(img2)
if img1_cropped is not None and img2_cropped is not None:
img1_embedding = resnet(img1_cropped.unsqueeze(0))
img2_embedding = resnet(img2_cropped.unsqueeze(0))
cos = torch.nn.CosineSimilarity(dim=1, eps=1e-6)
similarity = cos(img1_embedding, img2_embedding)
print(f"Cosine Similarity: {similarity.item()}")
threshold = 0.6
if similarity > threshold:
print("The faces are similar!")
else:
print("The faces are different!")
else:
print("Face not detected in one or both images.")
Now I want to use it in Scala (JVM Environment). I've searched a lot, and found that we can use .pt model in scala using DJL (Deep Java Library), the code which I tried in scala is:
I've downloaded pre-trained model from there, which is 20180402-114759-vggface2.pt. I've used this in python and it is working fine with great accuracy.
python.py:
Now I want to use it in
Scala (JVM Environment)
. I've searched a lot, and found that we can use.pt
model in scala usingDJL (Deep Java Library)
, the code which I tried in scala is:libraries in build.sbt:
main:
I have tried above code, after searching on different websites. But this is giving an error:
[error] Exception in thread "main" ai.djl.engine.EngineException: PytorchStreamReader failed reading zip archive: failed finding central directory
Same .pt model is working fine in python but I'm unable to run that in scala. Guide me what I'm doing wrong?
The text was updated successfully, but these errors were encountered: