Update tempo.txt
Browse files
tempo.txt
CHANGED
@@ -1,48 +1,64 @@
|
|
1 |
-
import
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from torch import nn
|
3 |
+
from torch.utils.data import DataLoader
|
4 |
+
|
5 |
+
# Hyperparameters
|
6 |
+
image_size = (224, 224, 3) # Adjust based on your data
|
7 |
+
|
8 |
+
# Define the Generator Network
|
9 |
+
class Generator(nn.Module):
|
10 |
+
def __init__(self):
|
11 |
+
super(Generator, self).__init__()
|
12 |
+
# Define convolutional layers with appropriate filters and activations
|
13 |
+
self.conv1 = nn.Conv2d(3, 32, kernel_size=3, stride=1, padding=1)
|
14 |
+
# ... Add more convolutional layers as needed
|
15 |
+
self.conv_final = nn.Conv2d(128, 3, kernel_size=3, stride=1, padding=1, activation=nn.Tanh) # Tanh for shadow intensity
|
16 |
+
|
17 |
+
def forward(self, x):
|
18 |
+
# Define the forward pass through the convolutional layers
|
19 |
+
x = self.conv1(x)
|
20 |
+
# ... Forward pass through remaining convolutional layers
|
21 |
+
return self.conv_final(x)
|
22 |
+
|
23 |
+
# Define the Discriminator Network
|
24 |
+
class Discriminator(nn.Module):
|
25 |
+
def __init__(self):
|
26 |
+
super(Discriminator, self).__init__()
|
27 |
+
# Define convolutional layers with appropriate filters and activations
|
28 |
+
self.conv1 = nn.Conv2d(6, 32, kernel_size=3, stride=1, padding=1)
|
29 |
+
# ... Add more convolutional layers as needed
|
30 |
+
self.linear = nn.Linear(128, 1) # Final layer with sigmoid activation
|
31 |
+
|
32 |
+
def forward(self, car, shadow):
|
33 |
+
# Concatenate car and shadow features
|
34 |
+
x = torch.cat([car, shadow], dim=1)
|
35 |
+
# Define the forward pass through the convolutional layers
|
36 |
+
x = self.conv1(x)
|
37 |
+
# ... Forward pass through remaining convolutional layers
|
38 |
+
return torch.sigmoid(self.linear(x))
|
39 |
+
|
40 |
+
# Create data loaders for training and validation data
|
41 |
+
# ... (Implement data loading logic using PyTorch's DataLoader)
|
42 |
+
|
43 |
+
# Create the models
|
44 |
+
generator = Generator()
|
45 |
+
discriminator = Discriminator()
|
46 |
+
|
47 |
+
# Define loss function and optimizer
|
48 |
+
criterion = nn.BCELoss()
|
49 |
+
g_optimizer = torch.optim.Adam(generator.parameters(), lr=0.0002)
|
50 |
+
d_optimizer = torch.optim.Adam(discriminator.parameters(), lr=0.0002)
|
51 |
+
|
52 |
+
# Training loop
|
53 |
+
for epoch in range(epochs):
|
54 |
+
# Train the Discriminator
|
55 |
+
# ... (Implement discriminator training logic with loss calculation and updates)
|
56 |
+
|
57 |
+
# Train the Generator
|
58 |
+
# ... (Implement generator training logic with loss calculation and updates)
|
59 |
+
|
60 |
+
# Print training progress
|
61 |
+
# ... (Print loss values or other metrics)
|
62 |
+
|
63 |
+
# Save the trained generator
|
64 |
+
torch.save(generator.state_dict(), 'generator.pt')
|