misc
This commit is contained in:
@ -1,69 +1,74 @@
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import webbrowser
|
||||
import time
|
||||
import argparse
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
TensorBoard Launch Script
|
||||
|
||||
def run_tensorboard():
|
||||
"""Run TensorBoard server and open browser"""
|
||||
parser = argparse.ArgumentParser(description='TensorBoard Launcher')
|
||||
parser.add_argument('--port', type=int, default=6006, help='Port for TensorBoard server')
|
||||
parser.add_argument('--logdir', type=str, default='runs', help='Log directory for TensorBoard')
|
||||
parser.add_argument('--no-browser', action='store_true', help='Do not open browser automatically')
|
||||
args = parser.parse_args()
|
||||
Starts TensorBoard server for monitoring training progress.
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
import webbrowser
|
||||
from pathlib import Path
|
||||
|
||||
def main():
|
||||
"""Launch TensorBoard"""
|
||||
|
||||
# Create log directory if it doesn't exist
|
||||
os.makedirs(args.logdir, exist_ok=True)
|
||||
# Check if runs directory exists
|
||||
runs_dir = Path("runs")
|
||||
if not runs_dir.exists():
|
||||
print("❌ No 'runs' directory found.")
|
||||
print(" Start training first to generate TensorBoard logs.")
|
||||
return
|
||||
|
||||
# Print banner
|
||||
print("\n" + "="*60)
|
||||
print("📊 TRADING BOT - TENSORBOARD MONITORING 📊")
|
||||
print("="*60)
|
||||
print(f"Starting TensorBoard server on port {args.port}")
|
||||
print(f"Log directory: {args.logdir}")
|
||||
print("Press Ctrl+C to stop the server")
|
||||
print("="*60 + "\n")
|
||||
# Check if there are any log directories
|
||||
log_dirs = list(runs_dir.glob("*"))
|
||||
if not log_dirs:
|
||||
print("❌ No training logs found in 'runs' directory.")
|
||||
print(" Start training first to generate TensorBoard logs.")
|
||||
return
|
||||
|
||||
# Start TensorBoard server
|
||||
cmd = ["tensorboard", "--logdir", args.logdir, "--port", str(args.port)]
|
||||
print("🚀 Starting TensorBoard...")
|
||||
print(f"📁 Log directory: {runs_dir.absolute()}")
|
||||
print(f"📊 Found {len(log_dirs)} training sessions")
|
||||
|
||||
# List available sessions
|
||||
print("\nAvailable training sessions:")
|
||||
for i, log_dir in enumerate(sorted(log_dirs), 1):
|
||||
print(f" {i}. {log_dir.name}")
|
||||
|
||||
# Start TensorBoard
|
||||
try:
|
||||
port = 6006
|
||||
print(f"\n🌐 Starting TensorBoard on port {port}...")
|
||||
print(f"🔗 Access at: http://localhost:{port}")
|
||||
|
||||
# Try to open browser automatically
|
||||
try:
|
||||
webbrowser.open(f"http://localhost:{port}")
|
||||
print("🌍 Browser opened automatically")
|
||||
except:
|
||||
pass
|
||||
|
||||
# Start TensorBoard process
|
||||
process = subprocess.Popen(
|
||||
cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True
|
||||
)
|
||||
cmd = [sys.executable, "-m", "tensorboard.main", "--logdir", str(runs_dir), "--port", str(port)]
|
||||
|
||||
# Wait for TensorBoard to start
|
||||
time.sleep(3)
|
||||
print("\n" + "="*50)
|
||||
print("🔥 TensorBoard is running!")
|
||||
print(f"📈 View training metrics at: http://localhost:{port}")
|
||||
print("⏹️ Press Ctrl+C to stop TensorBoard")
|
||||
print("="*50 + "\n")
|
||||
|
||||
# Open browser
|
||||
if not args.no_browser:
|
||||
url = f"http://localhost:{args.port}"
|
||||
print(f"Opening browser to {url}")
|
||||
webbrowser.open(url)
|
||||
# Run TensorBoard
|
||||
subprocess.run(cmd)
|
||||
|
||||
# Print TensorBoard output
|
||||
while True:
|
||||
output = process.stdout.readline()
|
||||
if output == '' and process.poll() is not None:
|
||||
break
|
||||
if output:
|
||||
print(output.strip())
|
||||
|
||||
return process.poll()
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\nStopping TensorBoard server...")
|
||||
process.terminate()
|
||||
return 0
|
||||
print("\n🛑 TensorBoard stopped")
|
||||
except FileNotFoundError:
|
||||
print("❌ TensorBoard not found. Install with: pip install tensorboard")
|
||||
except Exception as e:
|
||||
print(f"Error running TensorBoard: {str(e)}")
|
||||
return 1
|
||||
print(f"❌ Error starting TensorBoard: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit_code = run_tensorboard()
|
||||
sys.exit(exit_code)
|
||||
main()
|
Reference in New Issue
Block a user