Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,19 @@
|
|
1 |
-
# from google.colab import drive
|
2 |
-
# drive.mount('/content/drive')
|
3 |
-
|
4 |
-
# import gradio as gr
|
5 |
import gradio as gr
|
6 |
import webbrowser
|
7 |
from threading import Timer
|
8 |
import torch
|
9 |
-
import torch.nn.functional as F
|
10 |
from facenet_pytorch import InceptionResnetV1
|
11 |
import cv2
|
12 |
-
from PIL import Image
|
13 |
import numpy as np
|
14 |
import warnings
|
|
|
15 |
warnings.filterwarnings("ignore")
|
16 |
|
17 |
DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
|
18 |
|
19 |
model = InceptionResnetV1(pretrained="vggface2", classify=True, num_classes=1).to(DEVICE).eval()
|
20 |
|
21 |
-
# checkpoint_path = "/content/drive/MyDrive/resnetinceptionv1_epoch_32.pth"
|
22 |
checkpoint_path = "resnetinceptionv1_epoch_32.pth"
|
23 |
checkpoint = torch.load(checkpoint_path, map_location=DEVICE)
|
24 |
if 'model_state_dict' in checkpoint:
|
@@ -40,7 +35,8 @@ def create_montage(frames, size=(512, 512)):
|
|
40 |
thumb_size = (size[0] // montage_grid, size[1] // montage_grid)
|
41 |
|
42 |
for i, frame in enumerate(frames):
|
43 |
-
|
|
|
44 |
x_offset = (i % montage_grid) * thumb_size[0]
|
45 |
y_offset = (i // montage_grid) * thumb_size[1]
|
46 |
montage.paste(thumbnail, (x_offset, y_offset))
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import webbrowser
|
3 |
from threading import Timer
|
4 |
import torch
|
|
|
5 |
from facenet_pytorch import InceptionResnetV1
|
6 |
import cv2
|
7 |
+
from PIL import Image, ImageOps
|
8 |
import numpy as np
|
9 |
import warnings
|
10 |
+
|
11 |
warnings.filterwarnings("ignore")
|
12 |
|
13 |
DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
|
14 |
|
15 |
model = InceptionResnetV1(pretrained="vggface2", classify=True, num_classes=1).to(DEVICE).eval()
|
16 |
|
|
|
17 |
checkpoint_path = "resnetinceptionv1_epoch_32.pth"
|
18 |
checkpoint = torch.load(checkpoint_path, map_location=DEVICE)
|
19 |
if 'model_state_dict' in checkpoint:
|
|
|
35 |
thumb_size = (size[0] // montage_grid, size[1] // montage_grid)
|
36 |
|
37 |
for i, frame in enumerate(frames):
|
38 |
+
# Updated resize method
|
39 |
+
thumbnail = ImageOps.fit(frame, thumb_size, Image.Resampling.LANCZOS)
|
40 |
x_offset = (i % montage_grid) * thumb_size[0]
|
41 |
y_offset = (i // montage_grid) * thumb_size[1]
|
42 |
montage.paste(thumbnail, (x_offset, y_offset))
|