tcm03 commited on
Commit ·
5696d8d
1
Parent(s): bd72620
Add config_file arg
Browse files- preprocessing/main.py +14 -8
preprocessing/main.py
CHANGED
|
@@ -13,9 +13,6 @@ from multiprocessing import cpu_count
|
|
| 13 |
# Configure logging
|
| 14 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 15 |
|
| 16 |
-
cambrianConfig = CambrianConfig.from_json_file("config.json")
|
| 17 |
-
processor = CambrianEncoders(cambrianConfig)
|
| 18 |
-
|
| 19 |
def get_optimal_workers() -> int:
|
| 20 |
"""Determine the optimal number of workers based on available CPU cores."""
|
| 21 |
try:
|
|
@@ -23,7 +20,7 @@ def get_optimal_workers() -> int:
|
|
| 23 |
except (NotImplementedError, ValueError):
|
| 24 |
return 1 # Fallback to a single worker in case of an error
|
| 25 |
|
| 26 |
-
def extract_features(file_path: str, file_name: str) -> Dict[str, torch.Tensor]:
|
| 27 |
try:
|
| 28 |
video, image_sizes = process_video_frames(file_path)
|
| 29 |
image_aux_features_list = processor.prepare_mm_features(images=video, image_sizes=image_sizes)
|
|
@@ -46,12 +43,21 @@ if __name__ == "__main__":
|
|
| 46 |
)
|
| 47 |
parser.add_argument(
|
| 48 |
'--output_file',
|
| 49 |
-
type=str,
|
| 50 |
-
default='entube_tensors.safetensors',
|
| 51 |
-
help='Safetensor file to store embeddings of EnTube dataset by vision encoders'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
)
|
| 53 |
args = parser.parse_args()
|
| 54 |
|
|
|
|
|
|
|
|
|
|
| 55 |
folder_paths: List[str] = args.folders
|
| 56 |
data_tensor = defaultdict(torch.Tensor) # Use defaultdict for thread safety
|
| 57 |
# Determine optimal workers
|
|
@@ -65,7 +71,7 @@ if __name__ == "__main__":
|
|
| 65 |
file_names = os.listdir(folder_path)
|
| 66 |
for file_name in file_names:
|
| 67 |
file_path = os.path.join(folder_path, file_name)
|
| 68 |
-
futures.append(executor.submit(extract_features, file_path, file_name))
|
| 69 |
|
| 70 |
# Collect results as tasks complete
|
| 71 |
for future in as_completed(futures):
|
|
|
|
| 13 |
# Configure logging
|
| 14 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
def get_optimal_workers() -> int:
|
| 17 |
"""Determine the optimal number of workers based on available CPU cores."""
|
| 18 |
try:
|
|
|
|
| 20 |
except (NotImplementedError, ValueError):
|
| 21 |
return 1 # Fallback to a single worker in case of an error
|
| 22 |
|
| 23 |
+
def extract_features(processor: CambrianEncoders, file_path: str, file_name: str) -> Dict[str, torch.Tensor]:
|
| 24 |
try:
|
| 25 |
video, image_sizes = process_video_frames(file_path)
|
| 26 |
image_aux_features_list = processor.prepare_mm_features(images=video, image_sizes=image_sizes)
|
|
|
|
| 43 |
)
|
| 44 |
parser.add_argument(
|
| 45 |
'--output_file',
|
| 46 |
+
type = str,
|
| 47 |
+
default = 'entube_tensors.safetensors',
|
| 48 |
+
help = 'Safetensor file to store embeddings of EnTube dataset by vision encoders'
|
| 49 |
+
)
|
| 50 |
+
parser.add_argument(
|
| 51 |
+
'--config_file',
|
| 52 |
+
type = str,
|
| 53 |
+
default = 'config.json',
|
| 54 |
+
help = 'Path to configuration file of encoders parameters'
|
| 55 |
)
|
| 56 |
args = parser.parse_args()
|
| 57 |
|
| 58 |
+
cambrianConfig = CambrianConfig.from_json_file(args.config_file)
|
| 59 |
+
processor = CambrianEncoders(cambrianConfig)
|
| 60 |
+
|
| 61 |
folder_paths: List[str] = args.folders
|
| 62 |
data_tensor = defaultdict(torch.Tensor) # Use defaultdict for thread safety
|
| 63 |
# Determine optimal workers
|
|
|
|
| 71 |
file_names = os.listdir(folder_path)
|
| 72 |
for file_name in file_names:
|
| 73 |
file_path = os.path.join(folder_path, file_name)
|
| 74 |
+
futures.append(executor.submit(extract_features, processor, file_path, file_name))
|
| 75 |
|
| 76 |
# Collect results as tasks complete
|
| 77 |
for future in as_completed(futures):
|