ahmedghani commited on
Commit
27af9b9
·
1 Parent(s): bf481cc

Updated code to work

Browse files
florence_sam/{pipeline.py → florancesam_pipeline.py} RENAMED
@@ -12,6 +12,8 @@ from utils.sam import load_sam_image_model, load_sam_video_model, run_sam_infere
12
  class VideoProcessor:
13
  def __init__(self, device=None):
14
  self.device = device or torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
 
15
  self._enable_mixed_precision()
16
 
17
  # Load models
@@ -26,11 +28,20 @@ class VideoProcessor:
26
  )
27
 
28
  def _enable_mixed_precision(self):
29
- torch.autocast(device_type=self.device.type, dtype=torch.bfloat16).__enter__()
30
  if torch.cuda.is_available() and torch.cuda.get_device_properties(0).major >= 8:
31
  torch.backends.cuda.matmul.allow_tf32 = True
32
  torch.backends.cudnn.allow_tf32 = True
33
 
 
 
 
 
 
 
 
 
 
 
34
  def process_video(self, video_path, scale_factor, prompt):
35
  self.scale_factor = scale_factor
36
 
@@ -170,8 +181,6 @@ class VideoProcessor:
170
 
171
  return output_video_path, session_path
172
 
173
- video_processor = VideoProcessor()
174
-
175
  #Example usage
176
  # output_video = video_processor.process_video(
177
  # video_path="videos/clip-07-camera-2.mp4",
 
12
  class VideoProcessor:
13
  def __init__(self, device=None):
14
  self.device = device or torch.device("cuda" if torch.cuda.is_available() else "cpu")
15
+ self.autocast = torch.autocast(device_type=self.device.type, dtype=torch.bfloat16)
16
+ self.autocast.__enter__()
17
  self._enable_mixed_precision()
18
 
19
  # Load models
 
28
  )
29
 
30
  def _enable_mixed_precision(self):
 
31
  if torch.cuda.is_available() and torch.cuda.get_device_properties(0).major >= 8:
32
  torch.backends.cuda.matmul.allow_tf32 = True
33
  torch.backends.cudnn.allow_tf32 = True
34
 
35
+ def _reset_mixed_precision(self):
36
+ # Exit the autocast context
37
+ self.autocast.__exit__(None, None, None)
38
+
39
+ # Reset CUDA settings
40
+ if torch.cuda.is_available():
41
+ torch.backends.cuda.matmul.allow_tf32 = False
42
+ torch.backends.cudnn.allow_tf32 = False
43
+ torch.cuda.empty_cache() # Clear the CUDA cache
44
+
45
  def process_video(self, video_path, scale_factor, prompt):
46
  self.scale_factor = scale_factor
47
 
 
181
 
182
  return output_video_path, session_path
183
 
 
 
184
  #Example usage
185
  # output_video = video_processor.process_video(
186
  # video_path="videos/clip-07-camera-2.mp4",
florence_sam/main.py CHANGED
@@ -1,7 +1,11 @@
1
  import os
2
- from pipeline import video_processor
3
  from propainter_pipeline import process_video
 
4
 
 
 
 
5
  session_path, fps = video_processor.process_video(
6
  video_path="/home/ubuntu/ahmedghani/clip-07-camera-2.mp4",
7
  scale_factor=0.5,
@@ -9,4 +13,9 @@ session_path, fps = video_processor.process_video(
9
  )
10
  print(f"Processed video saved at: {session_path}")
11
  print(f"FPS: {fps}")
12
- process_video(video=os.path.join(session_path, "input_frames"), mask=os.path.join(session_path, "output_frames"), resize_ratio=0.5, save_fps=int(fps), fp16=True)
 
 
 
 
 
 
1
  import os
2
+ import torch
3
  from propainter_pipeline import process_video
4
+ from florancesam_pipeline import VideoProcessor
5
 
6
+ video_processor = VideoProcessor()
7
+
8
+ print("Processing video with FlorenceSam...")
9
  session_path, fps = video_processor.process_video(
10
  video_path="/home/ubuntu/ahmedghani/clip-07-camera-2.mp4",
11
  scale_factor=0.5,
 
13
  )
14
  print(f"Processed video saved at: {session_path}")
15
  print(f"FPS: {fps}")
16
+
17
+ video_processor._reset_mixed_precision()
18
+ del video_processor
19
+ torch.cuda.empty_cache()
20
+ print("Processing video with ProPainter...")
21
+ process_video(video=os.path.join(session_path, "input_frames"), mask=os.path.join(session_path, "output_frames"), save_fps=int(fps), fp16=True)
florence_sam/results/input_frames/inpaint_out.mp4 DELETED
Binary file (371 kB)
 
florence_sam/results/input_frames/masked_in.mp4 DELETED
Binary file (998 kB)