-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
109 lines (83 loc) · 3.08 KB
/
main.py
File metadata and controls
109 lines (83 loc) · 3.08 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
#!/usr/bin/env python3
"""
Neural Network 3D Visualizer
============================
A standalone PyTorch application that creates and visualizes neural networks in 3D using pythreejs.
Usage:
python main.py # Run with default network
python main.py --custom # Create custom network interactively
"""
import argparse
import sys
import webbrowser
import tempfile
import os
from neural_network import SimpleNeuralNetwork, create_sample_network
from visualizer_standalone import StandaloneVisualizer
def create_custom_network():
"""Interactive creation of a custom neural network"""
print("Creating Custom Neural Network")
print("=" * 30)
# Get user input for network architecture
try:
input_size = int(input("Enter input layer size (default 8): ") or "8")
print("Enter hidden layer sizes (comma-separated, e.g., '64,32,16'):")
hidden_input = input("Hidden layers (default '12,8,4'): ") or "12,8,4"
hidden_sizes = [int(x.strip()) for x in hidden_input.split(',')]
output_size = int(input("Enter output layer size (default 3): ") or "3")
print(f"\nCreating network: {input_size} -> {hidden_sizes} -> {output_size}")
network = SimpleNeuralNetwork(
input_size=input_size,
hidden_sizes=hidden_sizes,
output_size=output_size
)
return network
except ValueError as e:
print(f"Invalid input: {e}")
print("Using default network instead.")
return create_sample_network()
def main():
parser = argparse.ArgumentParser(
description="Neural Network 3D Visualizer - Standalone App",
formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument(
'--custom', '-c',
action='store_true',
help='Create custom network interactively'
)
parser.add_argument(
'--port', '-p',
type=int,
default=8080,
help='Port for web server (default: 8080)'
)
parser.add_argument(
'--no-browser',
action='store_true',
help='Do not automatically open browser'
)
args = parser.parse_args()
print("Neural Network 3D Visualizer - Standalone App")
print("=" * 45)
try:
# Create network
if args.custom:
network = create_custom_network()
else:
print("Using default sample network...")
network = create_sample_network()
# Create visualizer and start server
visualizer = StandaloneVisualizer(network)
print(f"\nStarting web server on port {args.port}...")
print("Press Ctrl+C to stop the server")
# Start the visualization server
visualizer.start_server(port=args.port, open_browser=not args.no_browser)
except KeyboardInterrupt:
print("\nServer stopped by user.")
sys.exit(0)
except Exception as e:
print(f"Error: {e}")
sys.exit(1)
if __name__ == '__main__':
main()