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
5c4ecf64
Commit
5c4ecf64
authored
7 years ago
by
Amir MOHAMMADI
Browse files
Options
Downloads
Patches
Plain Diff
Allow for transfer learning maybe?
parent
e1992171
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!33
Changes to the biogenerator
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/learn/tensorflow/network/SimpleCNN.py
+61
-59
61 additions, 59 deletions
bob/learn/tensorflow/network/SimpleCNN.py
with
61 additions
and
59 deletions
bob/learn/tensorflow/network/SimpleCNN.py
+
61
−
59
View file @
5c4ecf64
...
...
@@ -3,68 +3,71 @@ import tensorflow as tf
def
architecture
(
input_layer
,
mode
=
tf
.
estimator
.
ModeKeys
.
TRAIN
,
kernerl_size
=
(
3
,
3
),
n_classes
=
2
,
data_format
=
'
channels_last
'
):
data_format
=
'
channels_last
'
,
reuse
=
False
):
# Keep track of all the endpoints
endpoints
=
{}
# Convolutional Layer #1
# Computes 32 features using a kernerl_size filter with ReLU activation.
# Padding is added to preserve width and height.
conv1
=
tf
.
layers
.
conv2d
(
inputs
=
input_layer
,
filters
=
32
,
kernel_size
=
kernerl_size
,
padding
=
"
same
"
,
activation
=
tf
.
nn
.
relu
,
data_format
=
data_format
)
endpoints
[
'
conv1
'
]
=
conv1
# Pooling Layer #1
# First max pooling layer with a 2x2 filter and stride of 2
pool1
=
tf
.
layers
.
max_pooling2d
(
inputs
=
conv1
,
pool_size
=
[
2
,
2
],
strides
=
2
,
data_format
=
data_format
)
endpoints
[
'
pool1
'
]
=
pool1
# Convolutional Layer #2
# Computes 64 features using a kernerl_size filter.
# Padding is added to preserve width and height.
conv2
=
tf
.
layers
.
conv2d
(
inputs
=
pool1
,
filters
=
64
,
kernel_size
=
kernerl_size
,
padding
=
"
same
"
,
activation
=
tf
.
nn
.
relu
,
data_format
=
data_format
)
endpoints
[
'
conv2
'
]
=
conv2
# Pooling Layer #2
# Second max pooling layer with a 2x2 filter and stride of 2
pool2
=
tf
.
layers
.
max_pooling2d
(
inputs
=
conv2
,
pool_size
=
[
2
,
2
],
strides
=
2
,
data_format
=
data_format
)
endpoints
[
'
pool2
'
]
=
pool2
# Flatten tensor into a batch of vectors
# TODO: use tf.layers.flatten in tensorflow 1.4 and above
pool2_flat
=
tf
.
contrib
.
layers
.
flatten
(
pool2
)
endpoints
[
'
pool2_flat
'
]
=
pool2_flat
# Dense Layer
# Densely connected layer with 1024 neurons
dense
=
tf
.
layers
.
dense
(
inputs
=
pool2_flat
,
units
=
1024
,
activation
=
tf
.
nn
.
relu
)
endpoints
[
'
dense
'
]
=
dense
# Add dropout operation; 0.6 probability that element will be kept
dropout
=
tf
.
layers
.
dropout
(
inputs
=
dense
,
rate
=
0.4
,
training
=
mode
==
tf
.
estimator
.
ModeKeys
.
TRAIN
)
endpoints
[
'
dropout
'
]
=
dropout
# Logits layer
# Input Tensor Shape: [batch_size, 1024]
# Output Tensor Shape: [batch_size, 2]
logits
=
tf
.
layers
.
dense
(
inputs
=
dropout
,
units
=
n_classes
)
endpoints
[
'
logits
'
]
=
logits
with
tf
.
variable_scope
(
'
SimpleCNN
'
,
reuse
=
reuse
):
# Convolutional Layer #1
# Computes 32 features using a kernerl_size filter with ReLU
# activation.
# Padding is added to preserve width and height.
conv1
=
tf
.
layers
.
conv2d
(
inputs
=
input_layer
,
filters
=
32
,
kernel_size
=
kernerl_size
,
padding
=
"
same
"
,
activation
=
tf
.
nn
.
relu
,
data_format
=
data_format
)
endpoints
[
'
conv1
'
]
=
conv1
# Pooling Layer #1
# First max pooling layer with a 2x2 filter and stride of 2
pool1
=
tf
.
layers
.
max_pooling2d
(
inputs
=
conv1
,
pool_size
=
[
2
,
2
],
strides
=
2
,
data_format
=
data_format
)
endpoints
[
'
pool1
'
]
=
pool1
# Convolutional Layer #2
# Computes 64 features using a kernerl_size filter.
# Padding is added to preserve width and height.
conv2
=
tf
.
layers
.
conv2d
(
inputs
=
pool1
,
filters
=
64
,
kernel_size
=
kernerl_size
,
padding
=
"
same
"
,
activation
=
tf
.
nn
.
relu
,
data_format
=
data_format
)
endpoints
[
'
conv2
'
]
=
conv2
# Pooling Layer #2
# Second max pooling layer with a 2x2 filter and stride of 2
pool2
=
tf
.
layers
.
max_pooling2d
(
inputs
=
conv2
,
pool_size
=
[
2
,
2
],
strides
=
2
,
data_format
=
data_format
)
endpoints
[
'
pool2
'
]
=
pool2
# Flatten tensor into a batch of vectors
# TODO: use tf.layers.flatten in tensorflow 1.4 and above
pool2_flat
=
tf
.
contrib
.
layers
.
flatten
(
pool2
)
endpoints
[
'
pool2_flat
'
]
=
pool2_flat
# Dense Layer
# Densely connected layer with 1024 neurons
dense
=
tf
.
layers
.
dense
(
inputs
=
pool2_flat
,
units
=
1024
,
activation
=
tf
.
nn
.
relu
)
endpoints
[
'
dense
'
]
=
dense
# Add dropout operation; 0.6 probability that element will be kept
dropout
=
tf
.
layers
.
dropout
(
inputs
=
dense
,
rate
=
0.4
,
training
=
mode
==
tf
.
estimator
.
ModeKeys
.
TRAIN
)
endpoints
[
'
dropout
'
]
=
dropout
# Logits layer
# Input Tensor Shape: [batch_size, 1024]
# Output Tensor Shape: [batch_size, 2]
logits
=
tf
.
layers
.
dense
(
inputs
=
dropout
,
units
=
n_classes
)
endpoints
[
'
logits
'
]
=
logits
return
logits
,
endpoints
...
...
@@ -117,7 +120,6 @@ def model_fn(features, labels, mode, params=None, config=None):
else
:
train_op
=
None
return
tf
.
estimator
.
EstimatorSpec
(
mode
=
mode
,
predictions
=
predictions
,
...
...
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