Darknsu commited on
Commit
403bc03
·
verified ·
1 Parent(s): ef2f1f1

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +32 -9
main.py CHANGED
@@ -371,7 +371,6 @@
371
 
372
 
373
 
374
-
375
  import os
376
  import json
377
  import torch
@@ -451,11 +450,13 @@ def get_available_videos_from_hf():
451
  videos = []
452
  for file in files:
453
  if file.startswith(f"{HF_DATASET_SUBFOLDER}/") and file.endswith('.npz'):
 
 
454
  video_name = os.path.basename(file).replace('.npz', '')
455
  videos.append(video_name)
456
 
457
  videos = sorted(videos)
458
- print(f"Found {len(videos)} videos in dataset")
459
  return videos
460
 
461
  except Exception as e:
@@ -472,18 +473,31 @@ class HFVideoDataSet(VideoDataSet):
472
 
473
  # Create temporary directory for this session
474
  self.temp_dir = tempfile.mkdtemp(prefix="hf_video_")
475
- opt['video_feature_all_test'] = self.temp_dir
476
 
477
  # Download the specific video file if video_name is provided
478
  if video_name:
479
  try:
 
480
  downloaded_path = download_npz_file(video_name)
 
 
 
 
481
  # Copy to temp directory with expected structure
482
  temp_file_path = os.path.join(self.temp_dir, f"{video_name}.npz")
483
  shutil.copy2(downloaded_path, temp_file_path)
484
  print(f"Video file ready: {temp_file_path}")
 
 
 
 
 
485
  except Exception as e:
486
- print(f"Warning: Could not download video {video_name}: {str(e)}")
 
 
 
 
487
 
488
  # Initialize parent class
489
  super().__init__(opt, subset, video_name)
@@ -493,8 +507,9 @@ class HFVideoDataSet(VideoDataSet):
493
  try:
494
  if hasattr(self, 'temp_dir') and os.path.exists(self.temp_dir):
495
  shutil.rmtree(self.temp_dir)
496
- except:
497
- pass
 
498
 
499
  def eval_frame(opt, model, dataset):
500
  """Evaluate model frame by frame"""
@@ -635,6 +650,9 @@ def load_ground_truth(opt, video_name):
635
  def process_video(video_name, split_number, progress=gr.Progress()):
636
  """Process a single video for action localization"""
637
  try:
 
 
 
638
  progress(0.1, desc="Initializing...")
639
 
640
  # Parse options
@@ -680,10 +698,13 @@ def process_video(video_name, split_number, progress=gr.Progress()):
680
  progress(0.4, desc=f"Downloading video features for {video_name}...")
681
 
682
  # Create dataset with HF integration
683
- dataset = HFVideoDataSet(opt, subset='test', video_name=video_name)
 
 
 
684
 
685
  if len(dataset.video_list) == 0:
686
- return f"Error: No video found with name '{video_name}' in dataset or failed to download"
687
 
688
  progress(0.6, desc="Running inference...")
689
 
@@ -778,7 +799,9 @@ def process_video(video_name, split_number, progress=gr.Progress()):
778
  return output_text
779
 
780
  except Exception as e:
781
- return f"Error processing video: {str(e)}\n\nPlease check:\n1. Model checkpoint exists\n2. Video exists in HF dataset\n3. All dependencies are installed"
 
 
782
 
783
  def refresh_video_list():
784
  """Refresh the list of available videos"""
 
371
 
372
 
373
 
 
374
  import os
375
  import json
376
  import torch
 
450
  videos = []
451
  for file in files:
452
  if file.startswith(f"{HF_DATASET_SUBFOLDER}/") and file.endswith('.npz'):
453
+ # Extract the full filename without extension
454
+ # For files like "I3D/OP02-R02-TurkeySandwich.npz"
455
  video_name = os.path.basename(file).replace('.npz', '')
456
  videos.append(video_name)
457
 
458
  videos = sorted(videos)
459
+ print(f"Found {len(videos)} videos in dataset: {videos[:5]}{'...' if len(videos) > 5 else ''}")
460
  return videos
461
 
462
  except Exception as e:
 
473
 
474
  # Create temporary directory for this session
475
  self.temp_dir = tempfile.mkdtemp(prefix="hf_video_")
 
476
 
477
  # Download the specific video file if video_name is provided
478
  if video_name:
479
  try:
480
+ print(f"Downloading features for video: {video_name}")
481
  downloaded_path = download_npz_file(video_name)
482
+
483
+ # Ensure the temp directory exists
484
+ os.makedirs(self.temp_dir, exist_ok=True)
485
+
486
  # Copy to temp directory with expected structure
487
  temp_file_path = os.path.join(self.temp_dir, f"{video_name}.npz")
488
  shutil.copy2(downloaded_path, temp_file_path)
489
  print(f"Video file ready: {temp_file_path}")
490
+
491
+ # Verify file exists
492
+ if not os.path.exists(temp_file_path):
493
+ raise Exception(f"Failed to copy file to {temp_file_path}")
494
+
495
  except Exception as e:
496
+ print(f"Error downloading video {video_name}: {str(e)}")
497
+ raise e
498
+
499
+ # Set the feature path to our temp directory
500
+ opt['video_feature_all_test'] = self.temp_dir
501
 
502
  # Initialize parent class
503
  super().__init__(opt, subset, video_name)
 
507
  try:
508
  if hasattr(self, 'temp_dir') and os.path.exists(self.temp_dir):
509
  shutil.rmtree(self.temp_dir)
510
+ print(f"Cleaned up temp directory: {self.temp_dir}")
511
+ except Exception as e:
512
+ print(f"Warning: Could not clean up temp directory: {e}")
513
 
514
  def eval_frame(opt, model, dataset):
515
  """Evaluate model frame by frame"""
 
650
  def process_video(video_name, split_number, progress=gr.Progress()):
651
  """Process a single video for action localization"""
652
  try:
653
+ if not video_name or video_name in ["Error: Could not load videos from HF dataset", "Error loading videos"]:
654
+ return "Error: Please select a valid video name"
655
+
656
  progress(0.1, desc="Initializing...")
657
 
658
  # Parse options
 
698
  progress(0.4, desc=f"Downloading video features for {video_name}...")
699
 
700
  # Create dataset with HF integration
701
+ try:
702
+ dataset = HFVideoDataSet(opt, subset='test', video_name=video_name)
703
+ except Exception as e:
704
+ return f"Error downloading or loading video '{video_name}': {str(e)}\n\nPlease check:\n1. Video name is correct\n2. File exists in HF dataset\n3. Network connection is stable"
705
 
706
  if len(dataset.video_list) == 0:
707
+ return f"Error: No video found with name '{video_name}' in dataset after download"
708
 
709
  progress(0.6, desc="Running inference...")
710
 
 
799
  return output_text
800
 
801
  except Exception as e:
802
+ import traceback
803
+ error_details = traceback.format_exc()
804
+ return f"Error processing video: {str(e)}\n\nDetailed error:\n{error_details}\n\nPlease check:\n1. Model checkpoint exists\n2. Video exists in HF dataset\n3. All dependencies are installed"
805
 
806
  def refresh_video_list():
807
  """Refresh the list of available videos"""