-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataset_compiler.py
More file actions
154 lines (121 loc) · 5.26 KB
/
dataset_compiler.py
File metadata and controls
154 lines (121 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env python3
"""
NEURAL COMPOSITOR DATASET COMPILER v1.0
Framework: Gamesa Cortex V2 / FANUC RISE
Module: Dataset Processing Engine
This script recompiles the entire visual dataset, optimizing it via the OpenVINO platform
and validating resource usage against the Economic Governor.
Usage:
python3 dataset_compiler.py --dataset <path/to/dataset> --accelerator <DEVICE>
"""
import sys
import os
import time
import json
import logging
import argparse
from datetime import datetime
# Adjust paths to import Cortex modules
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
# Import Neural Engine
from ascii_neural_compositor.neural_art_engine import load_image, render_ascii
from ascii_neural_compositor.openvino_accelerator import NeuralAccelerator
# Import Cortex Core (mock if not available, but user has it)
try:
from gamesa_cortex_v2.src.core.economic_governor import EconomicGovernor
from gamesa_cortex_v2.src.core.openvino_subsystem import OpenVINOSubsystem
CORTEX_AVAILABLE = True
except ImportError:
print("Warning: Gamesa Cortex V2 Core not found in path. Running in Standalone Mode.")
CORTEX_AVAILABLE = False
# Simple Mock for Governor
class EconomicGovernor:
def __init__(self): self.budget = 1000
def request_allocation(self, task, priority):
print(f"[Governor Mock] Approved {task}")
return True
# Simple Mock for OpenVINO Subsystem
class OpenVINOSubsystem:
def set_performance_hint(self, hint): pass
# Constants
DATASET_Modes = ["standard", "edge", "cyberpunk", "retro", "sketch"]
OUTPUT_DIR = "compiled_dataset"
def setup_logging():
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[logging.StreamHandler()]
)
return logging.getLogger("DatasetCompiler")
def main():
logger = setup_logging()
parser = argparse.ArgumentParser(description="Neural Dataset Compiler")
parser.add_argument("--device", type=str, default="CPU", help="Target OpenVINO Device")
parser.add_argument("--batch_size", type=int, default=5, help="Number of samples to process")
args = parser.parse_args()
logger.info("Initializing Gamesa Cortex V2 Neural Core...")
# 1. Initialize Subsystems
governor = EconomicGovernor()
ov_subsystem = OpenVINOSubsystem() # Cortex Wrapper
accelerator = NeuralAccelerator(device=args.device) # Art Engine Bridge
# Configure OpenVINO via Cortex Protocol
if CORTEX_AVAILABLE:
ov_subsystem.set_performance_hint("THROUGHPUT")
# Optimize Neural Model
accelerator.optimize_model("Sobel_Kernel_v2.xml")
# 2. Prepare Dataset (Synthetic Generation if no path provided)
logger.info(f"Generating Synthetic Dataset (Batch Size: {args.batch_size})...")
if not os.path.exists(OUTPUT_DIR):
os.makedirs(OUTPUT_DIR)
compilation_report = {
"timestamp": datetime.now().isoformat(),
"device": args.device,
"total_samples": args.batch_size,
"results": []
}
# 3. Compilation Loop
start_time = time.time()
PRESETS = ["tech", "nature", "architecture"]
for i in range(args.batch_size):
sample_id = f"sample_{i:04d}"
# Cycle through presets and modes
preset = PRESETS[i % len(PRESETS)]
mode = DATASET_Modes[i % len(DATASET_Modes)]
logger.info(f"[{i+1}/{args.batch_size}] Processing {sample_id} | Preset: {preset} | Mode: {mode}")
# A. Economic Check
if not governor.request_allocation("NEURAL_INFERENCE", "HIGH"):
logger.warning(f"Skipping {sample_id}: Budget Denied by Governor.")
compilation_report["results"].append({"id": sample_id, "status": "DENIED"})
continue
# B. Load/Generate Input (Using Presets)
img_input = load_image(None, width=120, preset=preset)
# C. Neural Inference (Accelerated)
# We pass the image object. In a real OpenVINO pipeline, this would be a numpy tensor.
# The 'accelerator' simulates the inference latency.
_, latency = accelerator.infer(img_input)
# D. Rendering (Transduction)
ascii_art = render_ascii(img_input, mode=mode)
# E. Save Result
output_path = os.path.join(OUTPUT_DIR, f"{sample_id}_{preset}_{mode}.txt")
with open(output_path, "w") as f:
f.write(ascii_art)
# F. Log Metrics
metrics = {
"id": sample_id,
"preset": preset,
"mode": mode,
"latency_ms": latency,
"status": "COMPILED",
"output": output_path
}
compilation_report["results"].append(metrics)
logger.info(f"Compiled {sample_id} -> {output_path} ({latency}ms)")
total_time = time.time() - start_time
logger.info(f"Compilation Complete. Total Time: {total_time:.2f}s")
# Save Report
report_path = os.path.join(OUTPUT_DIR, "compilation_report.json")
with open(report_path, "w") as f:
json.dump(compilation_report, f, indent=4)
logger.info(f"Report saved to {report_path}")
if __name__ == "__main__":
main()