|
|
|
|
|
""" |
|
|
Script to recursively find JSON files and replace 'np.float64' with 'np.float32' |
|
|
""" |
|
|
|
|
|
import os |
|
|
import json |
|
|
from pathlib import Path |
|
|
|
|
|
def process_json_files(root_directory): |
|
|
""" |
|
|
Recursively scan directories for JSON files and replace np.float64 with np.float32 |
|
|
|
|
|
Args: |
|
|
root_directory (str): The root directory to start scanning from |
|
|
""" |
|
|
root_path = Path(root_directory) |
|
|
|
|
|
if not root_path.exists(): |
|
|
print(f"Error: Directory '{root_directory}' does not exist") |
|
|
return |
|
|
|
|
|
json_files_found = 0 |
|
|
json_files_modified = 0 |
|
|
|
|
|
|
|
|
for json_file in root_path.rglob("*.json"): |
|
|
json_files_found += 1 |
|
|
print(f"Processing: {json_file}") |
|
|
|
|
|
try: |
|
|
|
|
|
with open(json_file, 'r', encoding='utf-8') as f: |
|
|
content = f.read() |
|
|
|
|
|
|
|
|
string_to_replace = "_threshold': (" |
|
|
if string_to_replace in content: |
|
|
|
|
|
modified_content = content.replace(string_to_replace, "_threshold': " ) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with open(json_file, 'w', encoding='utf-8') as f: |
|
|
f.write(modified_content) |
|
|
|
|
|
json_files_modified += 1 |
|
|
print(f" ✓ Modified: {json_file}") |
|
|
else: |
|
|
print(f" - No changes needed: {json_file}") |
|
|
|
|
|
except Exception as e: |
|
|
print(f" ✗ Error processing {json_file}: {e}") |
|
|
|
|
|
print(f"\nSummary:") |
|
|
print(f"JSON files found: {json_files_found}") |
|
|
print(f"JSON files modified: {json_files_modified}") |
|
|
|
|
|
def main(): |
|
|
"""Main function""" |
|
|
|
|
|
current_dir = "." |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(f"Scanning directory: {os.path.abspath(current_dir)}") |
|
|
print("Looking for JSON files to process...") |
|
|
print("-" * 50) |
|
|
|
|
|
process_json_files(current_dir) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|