Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
deepFriedConvnet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
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
Show more breadcrumbs
Luc Giffon
deepFriedConvnet
Commits
4a92670e
Commit
4a92670e
authored
7 years ago
by
Luc Giffon
Browse files
Options
Downloads
Patches
Plain Diff
modification on the build of P in order to make it work with multiple dimensions
parent
bc0cbecf
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main/deepfriedConvnetMnist.py
+16
-8
16 additions, 8 deletions
main/deepfriedConvnetMnist.py
with
16 additions
and
8 deletions
main/
convnet_random
.py
→
main/
deepfriedConvnetMnist
.py
+
16
−
8
View file @
4a92670e
...
@@ -42,7 +42,7 @@ def max_pool_2x2(x):
...
@@ -42,7 +42,7 @@ def max_pool_2x2(x):
strides
=
[
1
,
2
,
2
,
1
],
padding
=
'
SAME
'
)
strides
=
[
1
,
2
,
2
,
1
],
padding
=
'
SAME
'
)
def
convolution
(
input
):
def
convolution
_mnist
(
input
):
with
tf
.
name_scope
(
"
conv_pool_1
"
):
with
tf
.
name_scope
(
"
conv_pool_1
"
):
# 32 is the number of filter we'll use. e.g. the number of different
# 32 is the number of filter we'll use. e.g. the number of different
# shapes this layer is able to recognize
# shapes this layer is able to recognize
...
@@ -118,7 +118,7 @@ def P_variable(d, nbr_stack):
...
@@ -118,7 +118,7 @@ def P_variable(d, nbr_stack):
:type nbr_stack: int
:type nbr_stack: int
:return: tf.Variable object containing the matrix
:return: tf.Variable object containing the matrix
"""
"""
idx
=
[(
i
*
d
)
+
np
.
random
.
permutation
(
d
)
for
i
in
range
(
nbr_stack
)]
idx
=
np
.
hstack
(
[(
i
*
d
)
+
np
.
random
.
permutation
(
d
)
for
i
in
range
(
nbr_stack
)]
)
P
=
np
.
random
.
permutation
(
np
.
eye
(
N
=
nbr_stack
*
d
))[
idx
].
astype
(
np
.
float32
)
P
=
np
.
random
.
permutation
(
np
.
eye
(
N
=
nbr_stack
*
d
))[
idx
].
astype
(
np
.
float32
)
return
tf
.
Variable
(
P
,
name
=
"
P
"
,
trainable
=
False
)
return
tf
.
Variable
(
P
,
name
=
"
P
"
,
trainable
=
False
)
...
@@ -259,21 +259,29 @@ def fully_connected(conv_out):
...
@@ -259,21 +259,29 @@ def fully_connected(conv_out):
return
h_fc1
return
h_fc1
def
mnist_dims
():
input_dim
=
int
(
mnist
.
train
.
images
.
shape
[
1
])
output_dim
=
int
(
mnist
.
train
.
labels
.
shape
[
1
])
return
input_dim
,
output_dim
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
SIGMA
=
5.0
SIGMA
=
5.0
print
(
"
Sigma = {}
"
.
format
(
SIGMA
))
print
(
"
Sigma = {}
"
.
format
(
SIGMA
))
with
tf
.
Graph
().
as_default
():
with
tf
.
Graph
().
as_default
():
input_dim
=
int
(
mnist
.
train
.
images
.
shape
[
1
])
# todo parametrize datset
output_dim
=
int
(
mnist
.
train
.
labels
.
shape
[
1
]
)
input_dim
,
output_dim
=
mnist
_dims
(
)
side_size
=
int
(
np
.
sqrt
(
input_dim
))
x
=
tf
.
placeholder
(
tf
.
float32
,
shape
=
[
None
,
input_dim
],
name
=
"
x
"
)
x
=
tf
.
placeholder
(
tf
.
float32
,
shape
=
[
None
,
input_dim
],
name
=
"
x
"
)
y_
=
tf
.
placeholder
(
tf
.
float32
,
shape
=
[
None
,
output_dim
],
name
=
"
labels
"
)
y_
=
tf
.
placeholder
(
tf
.
float32
,
shape
=
[
None
,
output_dim
],
name
=
"
labels
"
)
# side size is width or height of the images
side_size
=
int
(
np
.
sqrt
(
input_dim
))
x_image
=
tf
.
reshape
(
x
,
[
-
1
,
side_size
,
side_size
,
1
])
x_image
=
tf
.
reshape
(
x
,
[
-
1
,
side_size
,
side_size
,
1
])
tf
.
summary
.
image
(
"
digit
"
,
x_image
,
max_outputs
=
3
)
tf
.
summary
.
image
(
"
digit
"
,
x_image
,
max_outputs
=
3
)
# Representation layer
# Representation layer
h_conv
=
convolution
(
x_image
)
h_conv
=
convolution
_mnist
(
x_image
)
# h_conv = x
# h_conv = x
# out_fc = fully_connected(h_conv) # 95% accuracy
# out_fc = fully_connected(h_conv) # 95% accuracy
# out_fc = tf.nn.relu(fast_food(h_conv, SIGMA, nbr_stack=1)) # 83% accuracy (conv) | 56% accuracy (noconv)
# out_fc = tf.nn.relu(fast_food(h_conv, SIGMA, nbr_stack=1)) # 83% accuracy (conv) | 56% accuracy (noconv)
...
@@ -288,8 +296,8 @@ if __name__ == '__main__':
...
@@ -288,8 +296,8 @@ if __name__ == '__main__':
keep_prob
=
tf
.
placeholder
(
tf
.
float32
,
name
=
"
keep_prob
"
)
keep_prob
=
tf
.
placeholder
(
tf
.
float32
,
name
=
"
keep_prob
"
)
h_fc1_drop
=
tf
.
nn
.
dropout
(
out_fc
,
keep_prob
)
h_fc1_drop
=
tf
.
nn
.
dropout
(
out_fc
,
keep_prob
)
dim
=
np
.
prod
([
s
.
value
for
s
in
h_fc1_drop
.
shape
if
s
.
value
is
not
None
])
dim
=
np
.
prod
([
s
.
value
for
s
in
h_fc1_drop
.
shape
if
s
.
value
is
not
None
])
W_fc2
=
weight_variable
([
dim
,
10
])
W_fc2
=
weight_variable
([
dim
,
output_dim
])
b_fc2
=
bias_variable
([
10
])
b_fc2
=
bias_variable
([
output_dim
])
tf
.
summary
.
histogram
(
"
weights
"
,
W_fc2
)
tf
.
summary
.
histogram
(
"
weights
"
,
W_fc2
)
tf
.
summary
.
histogram
(
"
biases
"
,
b_fc2
)
tf
.
summary
.
histogram
(
"
biases
"
,
b_fc2
)
...
...
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