kjysmu commited on
Commit
1f2b5f0
1 Parent(s): 6a93d5c

modify app

Browse files
Files changed (1) hide show
  1. app.py +20 -11
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.cuda.FloatTensor(len(sorted_file_names), 768).fill_(0)
 
 
 
 
 
 
 
 
 
 
104
  else:
105
  features = torch.FloatTensor(len(sorted_file_names), 768).fill_(0)
106
-
107
- for idx, file_name in enumerate(sorted_file_names):
108
- fpath = frame_dir / file_name
109
- image = preprocess(Image.open(fpath)).unsqueeze(0).to(device)
110
- with torch.no_grad():
111
- image_features = model.encode_image(image)
112
- features[idx] = image_features[0]
113
- features = features.cpu().numpy()
114
- np.save(output_path, features)
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)