Spaces:
Sleeping
Sleeping
new
Browse files- .DS_Store +0 -0
- app.py +1 -37
- data/16546923557574.jpg +0 -0
- data/imagen2.png +0 -0
- main.py +0 -1
- train.py +38 -0
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
app.py
CHANGED
|
@@ -1,37 +1 @@
|
|
| 1 |
-
|
| 2 |
-
import torch
|
| 3 |
-
import dataprepare
|
| 4 |
-
from model import VGG16
|
| 5 |
-
def white_noise_img(model, original_image, content_image, epochs = 5):
|
| 6 |
-
#FIRST OF ALL REMOVE THE BATCH_SIZE FROM THE IMAGE
|
| 7 |
-
original_image = original_image.squeeze(0)
|
| 8 |
-
#GENERATE A NEW IMAGE AND TRACK THE PROCESS SO WE CAN PARAMETRIZE COMPUTING GRADIENTS
|
| 9 |
-
generated_image = torch.rand_like(original_image,requires_grad=True)
|
| 10 |
-
optimizer = torch.optim.Adam([generated_image], lr= 0.01)
|
| 11 |
-
|
| 12 |
-
for i in range(epochs):
|
| 13 |
-
optimizer.zero_grad()
|
| 14 |
-
|
| 15 |
-
content_result = model(content_image)
|
| 16 |
-
#style_result = model(original_image)
|
| 17 |
-
generated_result = model(generated_image)
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
content_loss = sum(mse_loss(generated_result["content"][l], content_result["content"][l]) for l in content_result["content"])
|
| 21 |
-
#style_loss = sum(#mse(gram(generated_image[style][l]), gram(style_image[l])) #for l in style_layers)
|
| 22 |
-
result_list = model(generated_image)
|
| 23 |
-
print(f"Loss at content type: {content_loss}")
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
image = dataprepare.image_process('/content/drive/MyDrive/16546923557574.jpg')
|
| 27 |
-
content_image = dataprepare.image_process('/content/drive/MyDrive/imagen2.png')
|
| 28 |
-
print(image.shape)
|
| 29 |
-
print(content_image.shape)
|
| 30 |
-
image = image.view(1, image.shape[0],image.shape[1],image.shape[2])
|
| 31 |
-
model = VGG16(num_features=5,num_classes=5)
|
| 32 |
-
|
| 33 |
-
model = model.to("cpu")
|
| 34 |
-
#result_list = model(image)
|
| 35 |
-
#style_computing(result_list, model, image)
|
| 36 |
-
#view_activations()
|
| 37 |
-
white_noise_img(model,image,content_image)
|
|
|
|
| 1 |
+
import train
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data/16546923557574.jpg
ADDED
|
data/imagen2.png
ADDED
|
main.py
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
import app
|
|
|
|
|
|
train.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from torch.nn.functional import mse_loss
|
| 2 |
+
import torch
|
| 3 |
+
import dataprepare
|
| 4 |
+
from model import VGG16
|
| 5 |
+
|
| 6 |
+
def white_noise_img(model, original_image, content_image, epochs = 5):
|
| 7 |
+
#FIRST OF ALL REMOVE THE BATCH_SIZE FROM THE IMAGE
|
| 8 |
+
original_image = original_image.squeeze(0)
|
| 9 |
+
#GENERATE A NEW IMAGE AND TRACK THE PROCESS SO WE CAN PARAMETRIZE COMPUTING GRADIENTS
|
| 10 |
+
generated_image = torch.rand_like(original_image,requires_grad=True)
|
| 11 |
+
optimizer = torch.optim.Adam([generated_image], lr= 0.01)
|
| 12 |
+
|
| 13 |
+
for i in range(epochs):
|
| 14 |
+
optimizer.zero_grad()
|
| 15 |
+
|
| 16 |
+
content_result = model(content_image)
|
| 17 |
+
#style_result = model(original_image)
|
| 18 |
+
generated_result = model(generated_image)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
content_loss = sum(mse_loss(generated_result["content"][l], content_result["content"][l]) for l in content_result["content"])
|
| 22 |
+
#style_loss = sum(#mse(gram(generated_image[style][l]), gram(style_image[l])) #for l in style_layers)
|
| 23 |
+
result_list = model(generated_image)
|
| 24 |
+
print(f"Loss at content type: {content_loss}")
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
image = dataprepare.image_process('/content/drive/MyDrive/16546923557574.jpg')
|
| 28 |
+
content_image = dataprepare.image_process('/content/drive/MyDrive/imagen2.png')
|
| 29 |
+
print(image.shape)
|
| 30 |
+
print(content_image.shape)
|
| 31 |
+
image = image.view(1, image.shape[0],image.shape[1],image.shape[2])
|
| 32 |
+
model = VGG16(num_features=5,num_classes=5)
|
| 33 |
+
|
| 34 |
+
model = model.to("cpu")
|
| 35 |
+
#result_list = model(image)
|
| 36 |
+
#style_computing(result_list, model, image)
|
| 37 |
+
#view_activations()
|
| 38 |
+
white_noise_img(model,image,content_image)
|