(audio_items, model, output_dir)
| 86 | return None, None, None, None, None, None, None, None, None |
| 87 | |
| 88 | def process_data_batch(audio_items, model, output_dir): |
| 89 | results = [] |
| 90 | |
| 91 | all_chunks = [] |
| 92 | audio_infos = [] |
| 93 | |
| 94 | valid_items = [] |
| 95 | for item in audio_items: |
| 96 | audio_path = item["audio_path"] |
| 97 | if not os.path.exists(audio_path): |
| 98 | logger.warning(f"Audio file not found: {audio_path}") |
| 99 | continue |
| 100 | valid_items.append(item) |
| 101 | |
| 102 | if not valid_items: |
| 103 | return results |
| 104 | |
| 105 | max_workers = min(len(valid_items), 8) |
| 106 | with ThreadPoolExecutor(max_workers=max_workers) as executor: |
| 107 | future_to_item = {executor.submit(prepare_audio_chunks, item["audio_path"]): item |
| 108 | for item in valid_items} |
| 109 | |
| 110 | for future in concurrent.futures.as_completed(future_to_item): |
| 111 | item = future_to_item[future] |
| 112 | try: |
| 113 | chunks, positions, shape, orig_len, sr, C, step, fade_size, border = future.result() |
| 114 | if chunks is None: |
| 115 | continue |
| 116 | |
| 117 | audio_infos.append({ |
| 118 | 'item': item, |
| 119 | 'chunks_start_idx': len(all_chunks), |
| 120 | 'chunks_count': len(chunks), |
| 121 | 'positions': positions, |
| 122 | 'shape': shape, |
| 123 | 'original_length': orig_len, |
| 124 | 'samplerate': sr, |
| 125 | 'C': C, |
| 126 | 'step': step, |
| 127 | 'fade_size': fade_size, |
| 128 | 'border': border |
| 129 | }) |
| 130 | |
| 131 | all_chunks.extend(chunks) |
| 132 | except Exception as e: |
| 133 | logger.error(f"Error processing audio file {item['audio_path']}: {e}") |
| 134 | continue |
| 135 | |
| 136 | if not all_chunks: |
| 137 | return results |
| 138 | |
| 139 | try: |
| 140 | batch_chunks = torch.stack(all_chunks).to(device) |
| 141 | with torch.no_grad(): |
| 142 | batch_outputs = model(batch_chunks).squeeze(1).cpu() |
| 143 | except RuntimeError as e: |
| 144 | if "out of memory" in str(e).lower(): |
| 145 | logger.error(f"CUDA out of memory: {e}") |
no test coverage detected