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
5e7d7f35
Commit
5e7d7f35
authored
Oct 03, 2022
by
Meet Narendra
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added logging for loss debugging
parent
45de1076
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
18 additions
and
10 deletions
+18
-10
1508.06576/loss.py
1508.06576/loss.py
+9
-2
1508.06576/optimizer.py
1508.06576/optimizer.py
+6
-6
1508.06576/preprocess.py
1508.06576/preprocess.py
+3
-2
1508.06576/styled.png
1508.06576/styled.png
+0
-0
1508.06576/test/content.jpg
1508.06576/test/content.jpg
+0
-0
1508.06576/test/style.jpg
1508.06576/test/style.jpg
+0
-0
No files found.
1508.06576/loss.py
View file @
5e7d7f35
...
...
@@ -56,6 +56,13 @@ class Loss:
@params
Author: @jiteshg
'''
loss_t
=
0.0
a
=
0.0
b
=
0.0
for
gen
,
cont
,
sty
in
zip
(
content_fmap_gen
,
cont_fmap_real
,
style_fmap_real
):
loss_t
=
alpha
*
Loss
.
content_loss
(
cont
,
gen
)
+
beta
*
Loss
.
style_loss
(
sty
,
gen
)
return
loss_t
\ No newline at end of file
loss_cont
=
Loss
.
content_loss
(
cont
,
gen
)
loss_style
=
Loss
.
style_loss
(
sty
,
gen
)
a
+=
loss_cont
b
+=
loss_style
loss_t
+=
alpha
*
loss_cont
+
beta
*
loss_style
return
loss_t
,
a
,
b
\ No newline at end of file
1508.06576/optimizer.py
View file @
5e7d7f35
...
...
@@ -17,9 +17,9 @@ class Optimizer:
'''
LOGGER
.
info
(
"Running gradient descent with the following parameters"
)
epoch
=
5000
learning_rate
=
0.00
1
alpha
=
1
0
beta
=
100
learning_rate
=
0.00
2
alpha
=
1
beta
=
0.01
LOGGER
.
info
(
f
"{epoch},{learning_rate},{alpha},{beta}"
)
optimizer
=
optim
.
Adam
([
content_img_clone
],
lr
=
learning_rate
)
...
...
@@ -33,7 +33,7 @@ class Optimizer:
style_fmaps
=
feature_maps
.
get_fmaps
(
style_img
)
content_generated_fmaps
=
feature_maps
.
get_fmaps
(
content_img_clone
)
total_loss
=
Loss
.
total_loss
(
alpha
,
beta
,
content_fmaps
,
style_fmaps
,
content_generated_fmaps
)
total_loss
,
total_cont_loss
,
total_style_loss
=
Loss
.
total_loss
(
alpha
,
beta
,
content_fmaps
,
style_fmaps
,
content_generated_fmaps
)
# clears x.grad for every parameter x in the optimizer.
# It’s important to call this before total_loss.backward(), otherwise it will accumulate the gradients from multiple passes.
...
...
@@ -46,6 +46,6 @@ class Optimizer:
optimizer
.
step
()
#plt.clf()
#plt.plot(content_img_clone)
if
(
e
%
10
):
LOGGER
.
info
(
f
"Epoch = {e} Total Loss = {total_loss}"
)
if
(
e
%
10
==
0
):
LOGGER
.
info
(
f
"Epoch = {e} Total Loss = {total_loss}
Style Loss = {total_cont_loss} Content Loss = {total_style_loss}
"
)
save_image
(
content_img_clone
,
"styled.png"
)
\ No newline at end of file
1508.06576/preprocess.py
View file @
5e7d7f35
...
...
@@ -35,9 +35,10 @@ class Preprocessor:
@params
img: 3d numpy array
'''
loader
=
transforms
.
Compose
([
transforms
.
ToTensor
(),
transforms
.
Resize
([
512
,
512
]),
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
])])
img
=
loader
(
img
)
.
unsqueeze
(
0
)
assert
img
.
shape
==
(
1
,
3
,
512
,
512
)
assert
img
.
shape
==
(
1
,
3
,
224
,
224
)
return
img
.
to
(
device
,
torch
.
float
)
...
...
1508.06576/styled.png
View replaced file @
45de1076
View file @
5e7d7f35
187 KB
|
W:
|
H:
104 KB
|
W:
|
H:
2-up
Swipe
Onion skin
1508.06576/test/content.jpg
0 → 100644
View file @
5e7d7f35
100 KB
1508.06576/test/style.jpg
0 → 100644
View file @
5e7d7f35
914 KB
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