Spaces:
Sleeping
Sleeping
Chore: Removed unused files
Browse files- scripts/app.py +0 -74
- scripts/training/model.py +0 -37
scripts/app.py
DELETED
@@ -1,74 +0,0 @@
|
|
1 |
-
@app.post("/train")
|
2 |
-
async def train_model(config: dict):
|
3 |
-
network_config = NetworkConfig()
|
4 |
-
network_config.update(**config)
|
5 |
-
|
6 |
-
# Create model with configured architecture
|
7 |
-
model = Net(
|
8 |
-
block1=network_config.block1,
|
9 |
-
block2=network_config.block2,
|
10 |
-
block3=network_config.block3
|
11 |
-
)
|
12 |
-
|
13 |
-
# Start training with websocket updates
|
14 |
-
result = await train(model, network_config)
|
15 |
-
return result
|
16 |
-
|
17 |
-
@app.websocket("/ws/compare")
|
18 |
-
async def websocket_compare_endpoint(websocket: WebSocket):
|
19 |
-
await websocket.accept()
|
20 |
-
try:
|
21 |
-
while True:
|
22 |
-
data = await websocket.receive_json()
|
23 |
-
if data.get("type") == "start_comparison":
|
24 |
-
# Create and train both models
|
25 |
-
model1_config = NetworkConfig()
|
26 |
-
model2_config = NetworkConfig()
|
27 |
-
|
28 |
-
# Update configs with received data
|
29 |
-
model1_config.update(**data["model1"])
|
30 |
-
model2_config.update(**data["model2"])
|
31 |
-
|
32 |
-
# Create models with respective configurations
|
33 |
-
model1 = Net(
|
34 |
-
block1=model1_config.block1,
|
35 |
-
block2=model1_config.block2,
|
36 |
-
block3=model1_config.block3
|
37 |
-
)
|
38 |
-
|
39 |
-
model2 = Net(
|
40 |
-
block1=model2_config.block1,
|
41 |
-
block2=model2_config.block2,
|
42 |
-
block3=model2_config.block3
|
43 |
-
)
|
44 |
-
|
45 |
-
# Train both models concurrently
|
46 |
-
tasks = [
|
47 |
-
train(model1, model1_config, websocket),
|
48 |
-
train(model2, model2_config, websocket)
|
49 |
-
]
|
50 |
-
|
51 |
-
results = await asyncio.gather(*tasks)
|
52 |
-
|
53 |
-
# Send completion message
|
54 |
-
await websocket.send_json({
|
55 |
-
"type": "comparison_complete",
|
56 |
-
"data": {
|
57 |
-
"model1": results[0],
|
58 |
-
"model2": results[1]
|
59 |
-
}
|
60 |
-
})
|
61 |
-
|
62 |
-
except Exception as e:
|
63 |
-
print(f"Error in websocket connection: {e}")
|
64 |
-
finally:
|
65 |
-
await websocket.close()
|
66 |
-
|
67 |
-
@app.post("/compare")
|
68 |
-
async def compare_models(request: Request):
|
69 |
-
data = await request.json()
|
70 |
-
return {"status": "started", "message": "Model comparison initiated"}
|
71 |
-
|
72 |
-
@app.get("/train/compare")
|
73 |
-
async def compare_page(request: Request):
|
74 |
-
return templates.TemplateResponse("train_compare.html", {"request": request})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scripts/training/model.py
DELETED
@@ -1,37 +0,0 @@
|
|
1 |
-
import torch
|
2 |
-
import torch.nn as nn
|
3 |
-
import torch.nn.functional as F
|
4 |
-
from torch.nn import Conv2d, MaxPool2d, Linear, Sequential, ReLU, LogSoftmax, Flatten
|
5 |
-
|
6 |
-
|
7 |
-
class Net(torch.nn.Module):
|
8 |
-
def __init__(self, block1=32, block2=64, block3=128):
|
9 |
-
"""
|
10 |
-
Constructor
|
11 |
-
"""
|
12 |
-
super(Net, self).__init__()
|
13 |
-
|
14 |
-
# Define model architecture with configurable blocks
|
15 |
-
self.conv1 = nn.Conv2d(1, block1, kernel_size=3)
|
16 |
-
self.conv2 = nn.Conv2d(block1, block2, kernel_size=3)
|
17 |
-
self.conv3 = nn.Conv2d(block2, block3, kernel_size=3)
|
18 |
-
self.conv4 = nn.Conv2d(block3, block3*2, kernel_size=3)
|
19 |
-
|
20 |
-
# Calculate the input size for the first fully connected layer
|
21 |
-
self.fc1 = nn.Linear(block3*2*16, 50)
|
22 |
-
self.fc2 = nn.Linear(50, 10)
|
23 |
-
|
24 |
-
def forward(self, x):
|
25 |
-
"""
|
26 |
-
Forward pass for model training
|
27 |
-
:param x: Input layer
|
28 |
-
:return: Output of the model
|
29 |
-
"""
|
30 |
-
x = F.relu(self.conv1(x))
|
31 |
-
x = F.relu(F.max_pool2d(self.conv2(x), 2))
|
32 |
-
x = F.relu(self.conv3(x))
|
33 |
-
x = F.relu(F.max_pool2d(self.conv4(x), 2))
|
34 |
-
x = x.view(x.size(0), -1)
|
35 |
-
x = F.relu(self.fc1(x))
|
36 |
-
x = self.fc2(x)
|
37 |
-
return x
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|