(csv_folder_path, store_folder_path, GPU_offset, debug)
| 403 | |
| 404 | @torch.no_grad() |
| 405 | def single_process(csv_folder_path, store_folder_path, GPU_offset, debug): |
| 406 | |
| 407 | # Setting |
| 408 | store_freq = 10 |
| 409 | device = 'cuda' |
| 410 | |
| 411 | |
| 412 | # Read the csv file |
| 413 | csv_idx = GPU_offset |
| 414 | csv_file_path = os.path.join(csv_folder_path, "sub" + str(csv_idx) + ".csv") |
| 415 | print("CSV file we read is ", csv_file_path) |
| 416 | |
| 417 | |
| 418 | # Prepare the store file path |
| 419 | store_file_path = os.path.join(store_folder_path, "sub" + str(csv_idx) + ".csv") |
| 420 | if not resume and os.path.exists(store_file_path): |
| 421 | # Remove existing csv |
| 422 | os.remove(store_file_path) |
| 423 | |
| 424 | |
| 425 | # Resume the store csv |
| 426 | find_resume = True |
| 427 | if resume: # Read the last store row |
| 428 | find_resume = False |
| 429 | with open(store_file_path, 'r') as file: |
| 430 | reader = csv.reader(file) |
| 431 | store_rows = list(reader) |
| 432 | last_store_row = store_rows[-1] |
| 433 | print("The number of rows we have processed in the store csv is ", len(store_rows)) |
| 434 | |
| 435 | |
| 436 | |
| 437 | # Init the SAM2 model |
| 438 | sam2_predictor = SAM2VideoPredictor.from_pretrained("facebook/sam2.1-hiera-large") # Large model has 224.4M Param at 39.5 FPS |
| 439 | |
| 440 | |
| 441 | |
| 442 | # Read all row in the csv file |
| 443 | start_time = time.time() |
| 444 | info_lists = [] # The order will be follow automatically |
| 445 | with open(csv_file_path) as file_obj: |
| 446 | |
| 447 | reader_obj = csv.reader(file_obj) |
| 448 | |
| 449 | # Iterate over each row in the csv |
| 450 | for row_idx, row in enumerate(reader_obj): |
| 451 | |
| 452 | # For the first row case (With all title content) |
| 453 | if row_idx == 0: # The first line is the title of content |
| 454 | elements = dict() |
| 455 | for element_idx, key in enumerate(row): |
| 456 | elements[key] = element_idx |
| 457 | |
| 458 | print("The first row is ", row + ["ID_info"]) # TODO: we need ID_path (Especially 1st frame) + Region BBox position (All corresponds to Motion Traj) |
| 459 | |
| 460 | # Store the csv |
| 461 | if not resume: |
| 462 | with open(store_file_path, 'a', newline='') as csvfile: |
no test coverage detected