Spaces:
Running
on
T4
Running
on
T4
modify app
Browse files
app.py
CHANGED
@@ -100,19 +100,28 @@ def gen_semantic_feature(frame_dir, semantic_dir):
|
|
100 |
|
101 |
output_path = semantic_dir / "semantic.npy"
|
102 |
if torch.cuda.is_available():
|
103 |
-
features = torch.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
else:
|
105 |
features = torch.FloatTensor(len(sorted_file_names), 768).fill_(0)
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
features
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
def gen_emotion_feature(frame_dir, emotion_dir):
|
117 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
118 |
model, preprocess = clip.load("ViT-L/14@336px", device=device)
|
|
|
100 |
|
101 |
output_path = semantic_dir / "semantic.npy"
|
102 |
if torch.cuda.is_available():
|
103 |
+
features = torch.FloatTensor(len(sorted_file_names), 768).fill_(0)
|
104 |
+
features = features.to(device)
|
105 |
+
|
106 |
+
for idx, file_name in enumerate(sorted_file_names):
|
107 |
+
fpath = frame_dir / file_name
|
108 |
+
image = preprocess(Image.open(fpath)).unsqueeze(0).to(device)
|
109 |
+
with torch.no_grad():
|
110 |
+
image_features = model.encode_image(image)
|
111 |
+
features[idx] = image_features[0]
|
112 |
+
features = features.cpu().numpy()
|
113 |
+
np.save(output_path, features)
|
114 |
else:
|
115 |
features = torch.FloatTensor(len(sorted_file_names), 768).fill_(0)
|
116 |
+
for idx, file_name in enumerate(sorted_file_names):
|
117 |
+
fpath = frame_dir / file_name
|
118 |
+
image = preprocess(Image.open(fpath)).unsqueeze(0).to(device)
|
119 |
+
with torch.no_grad():
|
120 |
+
image_features = model.encode_image(image)
|
121 |
+
features[idx] = image_features[0]
|
122 |
+
features = features.numpy()
|
123 |
+
np.save(output_path, features)
|
124 |
+
|
|
|
125 |
def gen_emotion_feature(frame_dir, emotion_dir):
|
126 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
127 |
model, preprocess = clip.load("ViT-L/14@336px", device=device)
|