Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
FML Project
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Meet Narendra
FML Project
Commits
c85f68bf
Commit
c85f68bf
authored
Oct 04, 2022
by
Soumya Gupta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
norm loss to mean loss
parent
5e7d7f35
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
9 additions
and
9 deletions
+9
-9
1508.06576/feature_maps.py
1508.06576/feature_maps.py
+2
-2
1508.06576/loss.py
1508.06576/loss.py
+4
-4
1508.06576/optimizer.py
1508.06576/optimizer.py
+2
-2
1508.06576/preprocess.py
1508.06576/preprocess.py
+1
-1
1508.06576/styled.png
1508.06576/styled.png
+0
-0
No files found.
1508.06576/feature_maps.py
View file @
c85f68bf
...
@@ -16,8 +16,8 @@ class FeatureMaps():
...
@@ -16,8 +16,8 @@ class FeatureMaps():
super
()
super
()
try
:
try
:
self
.
model
=
torch
.
hub
.
load
(
'pytorch/vision:v0.10.0'
,
arch
,
pretrained
=
True
)
self
.
model
=
torch
.
hub
.
load
(
'pytorch/vision:v0.10.0'
,
arch
,
pretrained
=
True
)
except
:
except
Exception
as
e
:
LOGGER
.
error
(
"Could not load model"
)
LOGGER
.
error
(
"Could not load model"
+
str
(
e
)
)
return
return
def
get_model
(
self
):
def
get_model
(
self
):
...
...
1508.06576/loss.py
View file @
c85f68bf
...
@@ -16,7 +16,7 @@ class Loss:
...
@@ -16,7 +16,7 @@ class Loss:
l2_norm_sq
=
None
l2_norm_sq
=
None
try
:
try
:
diff
=
F
-
P
diff
=
F
-
P
l2_norm_sq
=
torch
.
norm
(
diff
)
**
2
l2_norm_sq
=
torch
.
mean
((
diff
)
**
2
)
except
Exception
as
e
:
except
Exception
as
e
:
LOGGER
.
error
(
"Error computing loss"
,
e
)
LOGGER
.
error
(
"Error computing loss"
,
e
)
return
l2_norm_sq
return
l2_norm_sq
...
@@ -45,9 +45,9 @@ class Loss:
...
@@ -45,9 +45,9 @@ class Loss:
w
=
F
.
shape
[
3
]
w
=
F
.
shape
[
3
]
style_gram_matrix
=
Loss
.
gram_matrix
(
F
)
style_gram_matrix
=
Loss
.
gram_matrix
(
F
)
target_gram_matrix
=
Loss
.
gram_matrix
(
A
)
target_gram_matrix
=
Loss
.
gram_matrix
(
A
)
loss_s
=
torch
.
norm
(
style_gram_matrix
-
target_gram_matrix
)
**
2
loss_s
=
torch
.
mean
((
style_gram_matrix
-
target_gram_matrix
)
**
2
)
constant
=
1
/
(
4.0
*
(
num_channels
**
2
)
*
((
h
*
w
)
**
2
))
#
constant = 1/(4.0*(num_channels**2)*((h*w)**2))
return
constant
*
loss_s
return
loss_s
@
staticmethod
@
staticmethod
def
total_loss
(
alpha
,
beta
,
cont_fmap_real
,
style_fmap_real
,
content_fmap_gen
):
def
total_loss
(
alpha
,
beta
,
cont_fmap_real
,
style_fmap_real
,
content_fmap_gen
):
...
...
1508.06576/optimizer.py
View file @
c85f68bf
...
@@ -17,7 +17,7 @@ class Optimizer:
...
@@ -17,7 +17,7 @@ class Optimizer:
'''
'''
LOGGER
.
info
(
"Running gradient descent with the following parameters"
)
LOGGER
.
info
(
"Running gradient descent with the following parameters"
)
epoch
=
5000
epoch
=
5000
learning_rate
=
0.0
02
learning_rate
=
0.0
1
alpha
=
1
alpha
=
1
beta
=
0.01
beta
=
0.01
LOGGER
.
info
(
f
"{epoch},{learning_rate},{alpha},{beta}"
)
LOGGER
.
info
(
f
"{epoch},{learning_rate},{alpha},{beta}"
)
...
@@ -47,5 +47,5 @@ class Optimizer:
...
@@ -47,5 +47,5 @@ class Optimizer:
#plt.clf()
#plt.clf()
#plt.plot(content_img_clone)
#plt.plot(content_img_clone)
if
(
e
%
10
==
0
):
if
(
e
%
10
==
0
):
LOGGER
.
info
(
f
"Epoch = {e} Total Loss = {total_loss}
Style Loss = {total_cont_loss} Content
Loss = {total_style_loss}"
)
LOGGER
.
info
(
f
"Epoch = {e} Total Loss = {total_loss}
content Loss = {total_cont_loss} style
Loss = {total_style_loss}"
)
save_image
(
content_img_clone
,
"styled.png"
)
save_image
(
content_img_clone
,
"styled.png"
)
\ No newline at end of file
1508.06576/preprocess.py
View file @
c85f68bf
...
@@ -38,7 +38,7 @@ class Preprocessor:
...
@@ -38,7 +38,7 @@ class Preprocessor:
#loader = transforms.Compose([transforms.ToTensor(),transforms.Resize([224,224]),transforms.Normalize(mean=[0.485, 0.456, 0.406],std=[0.229, 0.224, 0.225],),])
#loader = transforms.Compose([transforms.ToTensor(),transforms.Resize([224,224]),transforms.Normalize(mean=[0.485, 0.456, 0.406],std=[0.229, 0.224, 0.225],),])
loader
=
transforms
.
Compose
([
transforms
.
ToTensor
(),
transforms
.
Resize
([
224
,
224
])])
loader
=
transforms
.
Compose
([
transforms
.
ToTensor
(),
transforms
.
Resize
([
224
,
224
])])
img
=
loader
(
img
)
.
unsqueeze
(
0
)
img
=
loader
(
img
)
.
unsqueeze
(
0
)
assert
img
.
shape
==
(
1
,
3
,
224
,
224
)
#
assert img.shape == (1,3,224,224)
return
img
.
to
(
device
,
torch
.
float
)
return
img
.
to
(
device
,
torch
.
float
)
...
...
1508.06576/styled.png
View replaced file @
5e7d7f35
View file @
c85f68bf
104 KB
|
W:
|
H:
138 KB
|
W:
|
H:
2-up
Swipe
Onion skin
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment