Spaces:
Runtime error
Runtime error
Update neural_style.py
Browse files- neural_style.py +8 -8
neural_style.py
CHANGED
|
@@ -70,7 +70,7 @@ class TransferParams():
|
|
| 70 |
optimizer = 'lbfgs'
|
| 71 |
learning_rate = 1e0
|
| 72 |
lbfgs_num_correction = 100
|
| 73 |
-
print_iter =
|
| 74 |
save_iter = 1000
|
| 75 |
output_image = 'out.png'
|
| 76 |
log_level = 10
|
|
@@ -91,7 +91,7 @@ def main():
|
|
| 91 |
|
| 92 |
def transfer(params):
|
| 93 |
dtype, multidevice, backward_device = setup_gpu()
|
| 94 |
-
|
| 95 |
|
| 96 |
cnn, layerList = loadCaffemodel(params.model_file, params.pooling, params.gpu, params.disable_check)
|
| 97 |
|
|
@@ -156,13 +156,13 @@ def transfer(params):
|
|
| 156 |
net.add_module(str(len(net)), layer)
|
| 157 |
|
| 158 |
if layerList['C'][c] in content_layers:
|
| 159 |
-
print("Setting up content layer " + str(i) + ": " + str(layerList['C'][c]))
|
| 160 |
loss_module = ContentLoss(params.content_weight)
|
| 161 |
net.add_module(str(len(net)), loss_module)
|
| 162 |
content_losses.append(loss_module)
|
| 163 |
|
| 164 |
if layerList['C'][c] in style_layers:
|
| 165 |
-
print("Setting up style layer " + str(i) + ": " + str(layerList['C'][c]))
|
| 166 |
loss_module = StyleLoss(params.style_weight)
|
| 167 |
net.add_module(str(len(net)), loss_module)
|
| 168 |
style_losses.append(loss_module)
|
|
@@ -172,14 +172,14 @@ def transfer(params):
|
|
| 172 |
net.add_module(str(len(net)), layer)
|
| 173 |
|
| 174 |
if layerList['R'][r] in content_layers:
|
| 175 |
-
print("Setting up content layer " + str(i) + ": " + str(layerList['R'][r]))
|
| 176 |
loss_module = ContentLoss(params.content_weight)
|
| 177 |
net.add_module(str(len(net)), loss_module)
|
| 178 |
content_losses.append(loss_module)
|
| 179 |
next_content_idx += 1
|
| 180 |
|
| 181 |
if layerList['R'][r] in style_layers:
|
| 182 |
-
print("Setting up style layer " + str(i) + ": " + str(layerList['R'][r]))
|
| 183 |
loss_module = StyleLoss(params.style_weight)
|
| 184 |
net.add_module(str(len(net)), loss_module)
|
| 185 |
style_losses.append(loss_module)
|
|
@@ -195,7 +195,7 @@ def transfer(params):
|
|
| 195 |
# Capture content targets
|
| 196 |
for i in content_losses:
|
| 197 |
i.mode = 'capture'
|
| 198 |
-
print("Capturing content targets")
|
| 199 |
print_torch(net, multidevice)
|
| 200 |
net(content_image)
|
| 201 |
|
|
@@ -204,7 +204,7 @@ def transfer(params):
|
|
| 204 |
i.mode = 'None'
|
| 205 |
|
| 206 |
for i, image in enumerate(style_images_caffe):
|
| 207 |
-
print("Capturing style target " + str(i+1))
|
| 208 |
for j in style_losses:
|
| 209 |
j.mode = 'capture'
|
| 210 |
j.blend_weight = style_blend_weights[i]
|
|
|
|
| 70 |
optimizer = 'lbfgs'
|
| 71 |
learning_rate = 1e0
|
| 72 |
lbfgs_num_correction = 100
|
| 73 |
+
print_iter = 1000
|
| 74 |
save_iter = 1000
|
| 75 |
output_image = 'out.png'
|
| 76 |
log_level = 10
|
|
|
|
| 91 |
|
| 92 |
def transfer(params):
|
| 93 |
dtype, multidevice, backward_device = setup_gpu()
|
| 94 |
+
|
| 95 |
|
| 96 |
cnn, layerList = loadCaffemodel(params.model_file, params.pooling, params.gpu, params.disable_check)
|
| 97 |
|
|
|
|
| 156 |
net.add_module(str(len(net)), layer)
|
| 157 |
|
| 158 |
if layerList['C'][c] in content_layers:
|
| 159 |
+
#print("Setting up content layer " + str(i) + ": " + str(layerList['C'][c]))
|
| 160 |
loss_module = ContentLoss(params.content_weight)
|
| 161 |
net.add_module(str(len(net)), loss_module)
|
| 162 |
content_losses.append(loss_module)
|
| 163 |
|
| 164 |
if layerList['C'][c] in style_layers:
|
| 165 |
+
#print("Setting up style layer " + str(i) + ": " + str(layerList['C'][c]))
|
| 166 |
loss_module = StyleLoss(params.style_weight)
|
| 167 |
net.add_module(str(len(net)), loss_module)
|
| 168 |
style_losses.append(loss_module)
|
|
|
|
| 172 |
net.add_module(str(len(net)), layer)
|
| 173 |
|
| 174 |
if layerList['R'][r] in content_layers:
|
| 175 |
+
#print("Setting up content layer " + str(i) + ": " + str(layerList['R'][r]))
|
| 176 |
loss_module = ContentLoss(params.content_weight)
|
| 177 |
net.add_module(str(len(net)), loss_module)
|
| 178 |
content_losses.append(loss_module)
|
| 179 |
next_content_idx += 1
|
| 180 |
|
| 181 |
if layerList['R'][r] in style_layers:
|
| 182 |
+
#print("Setting up style layer " + str(i) + ": " + str(layerList['R'][r]))
|
| 183 |
loss_module = StyleLoss(params.style_weight)
|
| 184 |
net.add_module(str(len(net)), loss_module)
|
| 185 |
style_losses.append(loss_module)
|
|
|
|
| 195 |
# Capture content targets
|
| 196 |
for i in content_losses:
|
| 197 |
i.mode = 'capture'
|
| 198 |
+
#print("Capturing content targets")
|
| 199 |
print_torch(net, multidevice)
|
| 200 |
net(content_image)
|
| 201 |
|
|
|
|
| 204 |
i.mode = 'None'
|
| 205 |
|
| 206 |
for i, image in enumerate(style_images_caffe):
|
| 207 |
+
#print("Capturing style target " + str(i+1))
|
| 208 |
for j in style_losses:
|
| 209 |
j.mode = 'capture'
|
| 210 |
j.blend_weight = style_blend_weights[i]
|