jschwab21 commited on
Commit
d2b6670
·
verified ·
1 Parent(s): c751763

Update video_processing.py

Browse files
Files changed (1) hide show
  1. video_processing.py +3 -3
video_processing.py CHANGED
@@ -93,7 +93,7 @@ def extract_frames(video, start_time, end_time):
93
  frames.append(frame)
94
  return frames
95
 
96
- def analyze_scenes(video_path, scenes, description, batch_size=4):
97
  scene_scores = []
98
  negative_descriptions = [
99
  "black screen",
@@ -112,7 +112,7 @@ def analyze_scenes(video_path, scenes, description, batch_size=4):
112
  text_inputs = processor(text=[description] + negative_descriptions, return_tensors="pt", padding=True).to(device)
113
  text_features = model.get_text_features(**text_inputs).detach()
114
  positive_feature, negative_features = text_features[0], text_features[1:]
115
- print("Negative features shape:", negative_features.shape)
116
  video = VideoFileClip(video_path)
117
 
118
  for scene_num, (start_time, end_time) in enumerate(scenes):
@@ -129,7 +129,7 @@ def analyze_scenes(video_path, scenes, description, batch_size=4):
129
  batch_tensors = torch.stack([preprocess(frame) for frame in batch]).to(device)
130
  with torch.no_grad():
131
  image_features = model.get_image_features(pixel_values=batch_tensors).detach()
132
- print("Image Features Shape:", image_features.shape)
133
 
134
  positive_similarities = torch.cosine_similarity(image_features, positive_feature.unsqueeze(0).expand_as(image_features))
135
  negative_mean = negative_features.mean(dim=0).unsqueeze(0).expand_as(image_features)
 
93
  frames.append(frame)
94
  return frames
95
 
96
+ def analyze_scenes(video_path, scenes, description, batch_size=10):
97
  scene_scores = []
98
  negative_descriptions = [
99
  "black screen",
 
112
  text_inputs = processor(text=[description] + negative_descriptions, return_tensors="pt", padding=True).to(device)
113
  text_features = model.get_text_features(**text_inputs).detach()
114
  positive_feature, negative_features = text_features[0], text_features[1:]
115
+ #print("Negative features shape:", negative_features.shape)
116
  video = VideoFileClip(video_path)
117
 
118
  for scene_num, (start_time, end_time) in enumerate(scenes):
 
129
  batch_tensors = torch.stack([preprocess(frame) for frame in batch]).to(device)
130
  with torch.no_grad():
131
  image_features = model.get_image_features(pixel_values=batch_tensors).detach()
132
+ #print("Image Features Shape:", image_features.shape)
133
 
134
  positive_similarities = torch.cosine_similarity(image_features, positive_feature.unsqueeze(0).expand_as(image_features))
135
  negative_mean = negative_features.mean(dim=0).unsqueeze(0).expand_as(image_features)