Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.learn.tensorflow
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.learn.tensorflow
Commits
3d732f1a
Commit
3d732f1a
authored
5 years ago
by
Amir MOHAMMADI
Browse files
Options
Downloads
Patches
Plain Diff
Add a Gaussian blur filter
parent
b50d730c
Branches
Branches containing commit
Tags
v2.0.1
Tags containing commit
No related merge requests found
Pipeline
#36776
failed
5 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bob/learn/tensorflow/image/__init__.py
+19
-0
19 additions, 0 deletions
bob/learn/tensorflow/image/__init__.py
bob/learn/tensorflow/image/filter.py
+38
-0
38 additions, 0 deletions
bob/learn/tensorflow/image/filter.py
with
57 additions
and
0 deletions
bob/learn/tensorflow/image/__init__.py
0 → 100644
+
19
−
0
View file @
3d732f1a
from
.filter
import
gaussian_kernel
,
GaussianFilter
# gets sphinx autodoc done right - don't remove it
def
__appropriate__
(
*
args
):
"""
Says object was actually declared here, an not on the import module.
Parameters:
*args: An iterable of objects to modify
Resolves `Sphinx referencing issues
<https://github.com/sphinx-doc/sphinx/issues/3048>`
"""
for
obj
in
args
:
obj
.
__module__
=
__name__
__appropriate__
(
GaussianFilter
)
__all__
=
[
_
for
_
in
dir
()
if
not
_
.
startswith
(
"
_
"
)]
This diff is collapsed.
Click to expand it.
bob/learn/tensorflow/image/filter.py
0 → 100644
+
38
−
0
View file @
3d732f1a
import
tensorflow
as
tf
def
gaussian_kernel
(
size
:
int
,
mean
:
float
,
std
:
float
):
"""
Makes 2D gaussian Kernel for convolution.
Code adapted from: https://stackoverflow.com/a/52012658/1286165
"""
d
=
tf
.
distributions
.
Normal
(
mean
,
std
)
vals
=
d
.
prob
(
tf
.
range
(
start
=-
size
,
limit
=
size
+
1
,
dtype
=
tf
.
float32
))
gauss_kernel
=
tf
.
einsum
(
"
i,j->ij
"
,
vals
,
vals
)
return
gauss_kernel
/
tf
.
reduce_sum
(
gauss_kernel
)
class
GaussianFilter
:
"""
A class for blurring images
"""
def
__init__
(
self
,
size
=
13
,
mean
=
0.0
,
std
=
3.0
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
self
.
size
=
size
self
.
mean
=
mean
self
.
std
=
std
self
.
gauss_kernel
=
gaussian_kernel
(
size
,
mean
,
std
)[:,
:,
None
,
None
]
def
__call__
(
self
,
image
):
shape
=
tf
.
shape
(
image
)
image
=
tf
.
reshape
(
image
,
[
-
1
,
shape
[
-
3
],
shape
[
-
2
],
shape
[
-
1
]])
input_channels
=
shape
[
-
1
]
gauss_kernel
=
tf
.
tile
(
self
.
gauss_kernel
,
[
1
,
1
,
input_channels
,
1
])
return
tf
.
nn
.
depthwise_conv2d
(
image
,
gauss_kernel
,
strides
=
[
1
,
1
,
1
,
1
],
padding
=
"
SAME
"
,
data_format
=
"
NHWC
"
,
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment