Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
bob.learn.tensorflow
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
11
Issues
11
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bob
bob.learn.tensorflow
Commits
3ed2c592
Commit
3ed2c592
authored
Nov 04, 2016
by
Tiago de Freitas Pereira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create VGG 16 mod
parent
b5562129
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
248 additions
and
0 deletions
+248
-0
bob/learn/tensorflow/network/VGG16_mod.py
bob/learn/tensorflow/network/VGG16_mod.py
+248
-0
No files found.
bob/learn/tensorflow/network/VGG16_mod.py
0 → 100644
View file @
3ed2c592
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# @author: Tiago de Freitas Pereira <tiago.pereira@idiap.ch>
# @date: Wed 11 May 2016 09:39:36 CEST
"""
Class that creates the lenet architecture
"""
import
tensorflow
as
tf
from
.SequenceNetwork
import
SequenceNetwork
from
..layers
import
Conv2D
,
FullyConnected
,
MaxPooling
,
Dropout
,
AveragePooling
from
bob.learn.tensorflow.initialization
import
Xavier
from
bob.learn.tensorflow.initialization
import
Constant
class
VGG16_mod
(
SequenceNetwork
):
def
__init__
(
self
,
# First convolutional block
conv1_1_kernel_size
=
3
,
conv1_1_output
=
64
,
conv1_2_kernel_size
=
3
,
conv1_2_output
=
64
,
# Second convolutional block
conv2_1_kernel_size
=
3
,
conv2_1_output
=
128
,
conv2_2_kernel_size
=
3
,
conv2_2_output
=
128
,
# Third convolutional block
conv3_1_kernel_size
=
3
,
conv3_1_output
=
256
,
conv3_2_kernel_size
=
3
,
conv3_2_output
=
256
,
conv3_3_kernel_size
=
3
,
conv3_3_output
=
256
,
# Forth convolutional block
conv4_1_kernel_size
=
3
,
conv4_1_output
=
512
,
conv4_2_kernel_size
=
3
,
conv4_2_output
=
512
,
conv4_3_kernel_size
=
3
,
conv4_3_output
=
512
,
# Forth convolutional block
conv5_1_kernel_size
=
3
,
conv5_1_output
=
512
,
conv5_2_kernel_size
=
3
,
conv5_2_output
=
512
,
conv5_3_kernel_size
=
3
,
conv5_3_output
=
512
,
fc6_output
=
4096
,
fc7_output
=
4096
,
n_classes
=
10
,
default_feature_layer
=
"fc8"
,
seed
=
10
,
use_gpu
=
False
):
"""
Create all the necessary variables for this CNN
**Parameters**
conv1_kernel_size=5,
conv1_output=32,
conv2_kernel_size=5,
conv2_output=64,
fc1_output=400,
n_classes=10
seed = 10
"""
super
(
VGG16_mod
,
self
).
__init__
(
default_feature_layer
=
default_feature_layer
,
use_gpu
=
use_gpu
)
# First convolutional block
self
.
conv1_1_kernel_size
=
conv1_1_kernel_size
self
.
conv1_1_output
=
conv1_1_output
self
.
conv1_2_kernel_size
=
conv1_2_kernel_size
self
.
conv1_2_output
=
conv1_2_output
# Second convolutional block
self
.
conv2_1_kernel_size
=
conv2_1_kernel_size
self
.
conv2_1_output
=
conv2_1_output
self
.
conv2_2_kernel_size
=
conv2_2_kernel_size
self
.
conv2_2_output
=
conv2_2_output
# Third convolutional block
self
.
conv3_1_kernel_size
=
conv3_1_kernel_size
self
.
conv3_1_output
=
conv3_1_output
self
.
conv3_2_kernel_size
=
conv3_2_kernel_size
self
.
conv3_2_output
=
conv3_2_output
self
.
conv3_3_kernel_size
=
conv3_3_kernel_size
self
.
conv3_3_output
=
conv3_3_output
# Forth convolutional block
self
.
conv4_1_kernel_size
=
conv4_1_kernel_size
self
.
conv4_1_output
=
conv4_1_output
self
.
conv4_2_kernel_size
=
conv4_2_kernel_size
self
.
conv4_2_output
=
conv4_2_output
self
.
conv4_3_kernel_size
=
conv4_3_kernel_size
self
.
conv4_3_output
=
conv4_3_output
# Forth convolutional block
self
.
conv5_1_kernel_size
=
conv5_1_kernel_size
self
.
conv5_1_output
=
conv5_1_output
self
.
conv5_2_kernel_size
=
conv5_2_kernel_size
self
.
conv5_2_output
=
conv5_2_output
self
.
conv5_3_kernel_size
=
conv5_3_kernel_size
self
.
conv5_3_output
=
conv5_3_output
self
.
fc6_output
=
fc6_output
self
.
fc7_output
=
fc7_output
self
.
n_classes
=
n_classes
# First convolutional
self
.
add
(
Conv2D
(
name
=
"conv1_1"
,
kernel_size
=
conv1_1_kernel_size
,
filters
=
conv1_1_output
,
activation
=
tf
.
nn
.
relu
,
weights_initialization
=
Xavier
(
seed
=
seed
,
use_gpu
=
self
.
use_gpu
),
bias_initialization
=
Constant
(
use_gpu
=
self
.
use_gpu
)
))
self
.
add
(
Conv2D
(
name
=
"conv1_2"
,
kernel_size
=
conv1_2_kernel_size
,
filters
=
conv2_1_output
,
activation
=
tf
.
nn
.
relu
,
weights_initialization
=
Xavier
(
seed
=
seed
,
use_gpu
=
self
.
use_gpu
),
bias_initialization
=
Constant
(
use_gpu
=
self
.
use_gpu
)
))
self
.
add
(
MaxPooling
(
name
=
"pooling1"
,
strides
=
[
1
,
2
,
2
,
1
]))
# Second convolutional
self
.
add
(
Conv2D
(
name
=
"conv2_1"
,
kernel_size
=
conv2_1_kernel_size
,
filters
=
conv2_1_output
,
activation
=
tf
.
nn
.
relu
,
weights_initialization
=
Xavier
(
seed
=
seed
,
use_gpu
=
self
.
use_gpu
),
bias_initialization
=
Constant
(
use_gpu
=
self
.
use_gpu
)
))
self
.
add
(
Conv2D
(
name
=
"conv2_2"
,
kernel_size
=
conv2_2_kernel_size
,
filters
=
conv2_2_output
,
activation
=
tf
.
nn
.
relu
,
weights_initialization
=
Xavier
(
seed
=
seed
,
use_gpu
=
self
.
use_gpu
),
bias_initialization
=
Constant
(
use_gpu
=
self
.
use_gpu
)
))
self
.
add
(
MaxPooling
(
name
=
"pooling2"
,
strides
=
[
1
,
2
,
2
,
1
]))
# Third convolutional
self
.
add
(
Conv2D
(
name
=
"conv3_1"
,
kernel_size
=
conv3_1_kernel_size
,
filters
=
conv3_1_output
,
activation
=
tf
.
nn
.
relu
,
weights_initialization
=
Xavier
(
seed
=
seed
,
use_gpu
=
self
.
use_gpu
),
bias_initialization
=
Constant
(
use_gpu
=
self
.
use_gpu
)
))
self
.
add
(
Conv2D
(
name
=
"conv3_2"
,
kernel_size
=
conv3_2_kernel_size
,
filters
=
conv3_2_output
,
activation
=
tf
.
nn
.
relu
,
weights_initialization
=
Xavier
(
seed
=
seed
,
use_gpu
=
self
.
use_gpu
),
bias_initialization
=
Constant
(
use_gpu
=
self
.
use_gpu
)
))
self
.
add
(
Conv2D
(
name
=
"conv3_3"
,
kernel_size
=
conv3_3_kernel_size
,
filters
=
conv3_3_output
,
activation
=
tf
.
nn
.
relu
,
weights_initialization
=
Xavier
(
seed
=
seed
,
use_gpu
=
self
.
use_gpu
),
bias_initialization
=
Constant
(
use_gpu
=
self
.
use_gpu
)
))
self
.
add
(
MaxPooling
(
name
=
"pooling3"
,
strides
=
[
1
,
2
,
2
,
1
]))
# Forth convolutional
self
.
add
(
Conv2D
(
name
=
"conv4_1"
,
kernel_size
=
conv4_1_kernel_size
,
filters
=
conv4_1_output
,
activation
=
tf
.
nn
.
relu
,
weights_initialization
=
Xavier
(
seed
=
seed
,
use_gpu
=
self
.
use_gpu
),
bias_initialization
=
Constant
(
use_gpu
=
self
.
use_gpu
)
))
self
.
add
(
Conv2D
(
name
=
"conv4_2"
,
kernel_size
=
conv4_2_kernel_size
,
filters
=
conv4_2_output
,
activation
=
tf
.
nn
.
relu
,
weights_initialization
=
Xavier
(
seed
=
seed
,
use_gpu
=
self
.
use_gpu
),
bias_initialization
=
Constant
(
use_gpu
=
self
.
use_gpu
)
))
self
.
add
(
Conv2D
(
name
=
"conv4_3"
,
kernel_size
=
conv4_3_kernel_size
,
filters
=
conv4_3_output
,
activation
=
tf
.
nn
.
relu
,
weights_initialization
=
Xavier
(
seed
=
seed
,
use_gpu
=
self
.
use_gpu
),
bias_initialization
=
Constant
(
use_gpu
=
self
.
use_gpu
)
))
self
.
add
(
MaxPooling
(
name
=
"pooling4"
,
strides
=
[
1
,
2
,
2
,
1
]))
# Fifth convolutional
self
.
add
(
Conv2D
(
name
=
"conv5_1"
,
kernel_size
=
conv5_1_kernel_size
,
filters
=
conv5_1_output
,
activation
=
tf
.
nn
.
relu
,
weights_initialization
=
Xavier
(
seed
=
seed
,
use_gpu
=
self
.
use_gpu
),
bias_initialization
=
Constant
(
use_gpu
=
self
.
use_gpu
)
))
self
.
add
(
Conv2D
(
name
=
"conv5_2"
,
kernel_size
=
conv5_2_kernel_size
,
filters
=
conv5_2_output
,
activation
=
tf
.
nn
.
relu
,
weights_initialization
=
Xavier
(
seed
=
seed
,
use_gpu
=
self
.
use_gpu
),
bias_initialization
=
Constant
(
use_gpu
=
self
.
use_gpu
)
))
self
.
add
(
Conv2D
(
name
=
"conv5_3"
,
kernel_size
=
conv5_3_kernel_size
,
filters
=
conv5_3_output
,
activation
=
tf
.
nn
.
relu
,
weights_initialization
=
Xavier
(
seed
=
seed
,
use_gpu
=
self
.
use_gpu
),
bias_initialization
=
Constant
(
use_gpu
=
self
.
use_gpu
)
))
self
.
add
(
AveragePooling
(
name
=
"pooling5"
,
strides
=
[
1
,
2
,
2
,
1
]))
self
.
add
(
FullyConnected
(
name
=
"fc6"
,
output_dim
=
fc6_output
,
activation
=
tf
.
nn
.
relu
,
weights_initialization
=
Xavier
(
seed
=
seed
,
use_gpu
=
self
.
use_gpu
),
bias_initialization
=
Constant
(
use_gpu
=
self
.
use_gpu
)
))
self
.
add
(
Dropout
(
name
=
"dropout"
,
keep_prob
=
0.5
))
self
.
add
(
FullyConnected
(
name
=
"fc8"
,
output_dim
=
n_classes
,
activation
=
None
,
weights_initialization
=
Xavier
(
seed
=
seed
,
use_gpu
=
self
.
use_gpu
),
bias_initialization
=
Constant
(
use_gpu
=
self
.
use_gpu
)))
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