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
529337f9
Commit
529337f9
authored
Sep 25, 2022
by
Meet Narendra
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Loss and gram matrix
parent
4ff6ba78
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
11 deletions
+48
-11
1508.06576/feature_maps.py
1508.06576/feature_maps.py
+1
-0
1508.06576/logger.py
1508.06576/logger.py
+1
-1
1508.06576/loss.py
1508.06576/loss.py
+20
-4
1508.06576/preprocess.py
1508.06576/preprocess.py
+23
-5
1508.06576/style_transfer.py
1508.06576/style_transfer.py
+3
-1
No files found.
1508.06576/feature_maps.py
View file @
529337f9
...
@@ -2,6 +2,7 @@ import torch
...
@@ -2,6 +2,7 @@ import torch
from
logger
import
Logger
from
logger
import
Logger
LOGGER
=
Logger
()
.
logger
()
LOGGER
=
Logger
()
.
logger
()
LOGGER
.
info
(
"Started Feature Maps"
)
LOGGER
.
info
(
"Started Feature Maps"
)
#Author: @meetdoshi
class
FeatureMaps
:
class
FeatureMaps
:
def
__init__
(
self
,
arch
=
"vgg19"
):
def
__init__
(
self
,
arch
=
"vgg19"
):
'''
'''
...
...
1508.06576/logger.py
View file @
529337f9
from
distutils.log
import
Log
import
logging
import
logging
import
os
import
os
#Author: @meetdoshi
class
Logger
:
class
Logger
:
'''
'''
Singleton logger class
Singleton logger class
...
...
1508.06576/loss.py
View file @
529337f9
import
numpy
as
np
import
numpy
as
np
import
torch
from
logger
import
Logger
from
logger
import
Logger
LOGGER
=
Logger
()
.
logger
()
LOGGER
=
Logger
()
.
logger
()
...
@@ -24,21 +25,36 @@ class Loss:
...
@@ -24,21 +25,36 @@ class Loss:
def
gram_matrix
(
F
):
def
gram_matrix
(
F
):
'''
'''
Function to compute the gram matrix of a feature representation at a layer
Function to compute the gram matrix of a feature representation at a layer
Author: @himalisaini
'''
'''
shape_mat
=
F
.
shape
num_channels
=
shape_mat
[
1
]
height
=
shape_mat
[
2
]
width
=
shape_mat
[
3
]
return
torch
.
mm
(
F
.
view
(
num_channels
,(
height
*
width
)),
F
.
view
(
num_channels
,(
height
*
width
))
.
t
())
@
staticmethod
@
staticmethod
def
style_loss
(
F
,
A
):
def
style_loss
(
F
,
A
):
'''
'''
Function to compute style loss between two feature representations at multiple layers
Function to compute style loss between two feature representations at multiple layers
@params
@params
Author: @soumyagupta
'''
'''
num_channels
=
F
[
1
]
h
=
F
[
2
]
w
=
F
[
3
]
style_gram_matrix
=
Loss
.
gram_matrix
(
F
)
target_gram_matrix
=
Loss
.
gram_matrix
(
A
)
loss_s
=
np
.
sum
((
style_gram_matrix
-
target_gram_matrix
)
**
2
)
constant
=
1
/
(
4.0
*
(
num_channels
**
2
)
*
((
h
*
w
)
**
2
))
return
constant
*
loss_s
@
staticmethod
@
staticmethod
def
total_loss
(
alpha
,
beta
,
cont_fmap_real
,
cont_fmap_noise
,
style_fmap_real
,
style_fmap_noise
):
def
total_loss
(
alpha
,
beta
,
cont_fmap_real
,
cont_fmap_noise
,
style_fmap_real
,
style_fmap_noise
):
'''
'''
Function which computes total loss and returns it
Function which computes total loss and returns it
@params
@params
Author: @jiteshg
'''
'''
loss_t
=
alpha
*
Loss
.
content_loss
(
cont_fmap_real
,
cont_fmap_noise
)
+
beta
*
Loss
.
style_loss
(
style_fmap_real
,
style_fmap_noise
)
\ No newline at end of file
return
loss_t
\ No newline at end of file
1508.06576/preprocess.py
View file @
529337f9
from
distutils.log
import
Log
from
logger
import
Logger
from
logger
import
Logger
from
torch
import
transforms
from
PIL
import
Image
import
numpy
as
np
import
numpy
as
np
LOGGER
=
Logger
()
.
logger
()
LOGGER
=
Logger
()
.
logger
()
#Author: @meetdoshi
class
Preprocessor
:
class
Preprocessor
:
@
staticmethod
def
load_image
(
path
):
'''
Function to load image
@params
path: os.path
'''
img
=
Image
.
open
(
path
)
return
img
@
staticmethod
@
staticmethod
def
subtract_mean
(
img
):
def
subtract_mean
(
img
):
'''
'''
...
@@ -21,15 +32,22 @@ class Preprocessor:
...
@@ -21,15 +32,22 @@ class Preprocessor:
@params
@params
img: 3d numpy array
img: 3d numpy array
'''
'''
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
],),])
img
=
loader
(
img
)
.
unsqueeze
(
0
)
return
img
@
staticmethod
@
staticmethod
def
process
(
img
):
def
process
(
path
):
'''
'''
Function to preprocess the image
Function to preprocess the image
@params
@params
img: 2d numpy a[103.939, 116.779, 123.68]rray
path: os.path
'''
'''
img
=
Preprocessor
.
load_image
(
path
)
img
=
Preprocessor
.
reshape_img
(
img
)
img
=
Preprocessor
.
subtract_mean
(
img
)
return
img
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
prec
=
Preprocessor
()
prec
=
Preprocessor
()
...
...
1508.06576/style_transfer.py
View file @
529337f9
...
@@ -15,10 +15,12 @@ class StyleTransfer:
...
@@ -15,10 +15,12 @@ class StyleTransfer:
pass
pass
@
staticmethod
@
staticmethod
def
pipe
p
line
():
def
pipeline
():
'''
'''
Pipeline for style transfer
Pipeline for style transfer
@params: None
@params: None
Author: @gaurangathavale
'''
'''
\ No newline at end of file
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