Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
536c7587
Commit
536c7587
authored
Jul 21, 2018
by
Patrick Wieschollek
Committed by
Yuxin Wu
Jul 20, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rewrite VGG16 as well (#835)
parent
75c857db
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
33 deletions
+39
-33
examples/CaffeModels/load-vgg16.py
examples/CaffeModels/load-vgg16.py
+39
-33
No files found.
examples/CaffeModels/load-vgg16.py
View file @
536c7587
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# File: load-vgg16.py
# File: load-vgg16.py
# Author: Yuxin Wu
from
__future__
import
print_function
from
__future__
import
print_function
import
cv2
import
cv2
import
tensorflow
as
tf
import
tensorflow
as
tf
import
numpy
as
np
import
numpy
as
np
import
os
import
os
import
six
import
argparse
import
argparse
from
tensorpack
import
*
from
tensorpack
import
*
from
tensorpack.tfutils.symbolic_functions
import
*
from
tensorpack.tfutils.summary
import
*
from
tensorpack.dataflow.dataset
import
ILSVRCMeta
from
tensorpack.dataflow.dataset
import
ILSVRCMeta
enable_argscope_for_module
(
tf
.
layers
)
def
tower_func
(
image
):
def
tower_func
(
image
):
with
argscope
(
Conv2D
,
kernel_size
=
3
,
activation
=
tf
.
nn
.
relu
):
is_training
=
get_current_tower_context
()
.
is_training
logits
=
(
LinearWrap
(
image
)
.
Conv2D
(
'conv1_1'
,
64
)
with
argscope
([
tf
.
layers
.
conv2d
],
kernel_size
=
3
,
activation
=
tf
.
nn
.
relu
,
padding
=
'same'
):
.
Conv2D
(
'conv1_2'
,
64
)
x
=
image
.
MaxPooling
(
'pool1'
,
2
)
x
=
tf
.
layers
.
conv2d
(
x
,
64
,
name
=
'conv1_1'
)
# 112
x
=
tf
.
layers
.
conv2d
(
x
,
64
,
name
=
'conv1_2'
)
.
Conv2D
(
'conv2_1'
,
128
)
x
=
tf
.
layers
.
max_pooling2d
(
x
,
2
,
2
,
name
=
'pool1'
)
.
Conv2D
(
'conv2_2'
,
128
)
.
MaxPooling
(
'pool2'
,
2
)
x
=
tf
.
layers
.
conv2d
(
x
,
128
,
name
=
'conv2_1'
)
# 56
x
=
tf
.
layers
.
conv2d
(
x
,
128
,
name
=
'conv2_2'
)
.
Conv2D
(
'conv3_1'
,
256
)
x
=
tf
.
layers
.
max_pooling2d
(
x
,
2
,
2
,
name
=
'pool2'
)
.
Conv2D
(
'conv3_2'
,
256
)
.
Conv2D
(
'conv3_3'
,
256
)
x
=
tf
.
layers
.
conv2d
(
x
,
256
,
name
=
'conv3_1'
)
.
MaxPooling
(
'pool3'
,
2
)
x
=
tf
.
layers
.
conv2d
(
x
,
256
,
name
=
'conv3_2'
)
# 28
x
=
tf
.
layers
.
conv2d
(
x
,
256
,
name
=
'conv3_3'
)
.
Conv2D
(
'conv4_1'
,
512
)
x
=
tf
.
layers
.
max_pooling2d
(
x
,
2
,
2
,
name
=
'pool3'
)
.
Conv2D
(
'conv4_2'
,
512
)
.
Conv2D
(
'conv4_3'
,
512
)
x
=
tf
.
layers
.
conv2d
(
x
,
512
,
name
=
'conv4_1'
)
.
MaxPooling
(
'pool4'
,
2
)
x
=
tf
.
layers
.
conv2d
(
x
,
512
,
name
=
'conv4_2'
)
# 14
x
=
tf
.
layers
.
conv2d
(
x
,
512
,
name
=
'conv4_3'
)
.
Conv2D
(
'conv5_1'
,
512
)
x
=
tf
.
layers
.
max_pooling2d
(
x
,
2
,
2
,
name
=
'pool4'
)
.
Conv2D
(
'conv5_2'
,
512
)
.
Conv2D
(
'conv5_3'
,
512
)
x
=
tf
.
layers
.
conv2d
(
x
,
512
,
name
=
'conv5_1'
)
.
MaxPooling
(
'pool5'
,
2
)
x
=
tf
.
layers
.
conv2d
(
x
,
512
,
name
=
'conv5_2'
)
# 7
x
=
tf
.
layers
.
conv2d
(
x
,
512
,
name
=
'conv5_3'
)
.
FullyConnected
(
'fc6'
,
4096
,
activation
=
tf
.
nn
.
relu
)
x
=
tf
.
layers
.
max_pooling2d
(
x
,
2
,
2
,
name
=
'pool5'
)
.
Dropout
(
'drop0'
,
0.5
)
x
=
tf
.
layers
.
flatten
(
x
,
name
=
'flatten'
)
.
FullyConnected
(
'fc7'
,
4096
,
activation
=
tf
.
nn
.
relu
)
.
Dropout
(
'drop1'
,
0.5
)
x
=
tf
.
layers
.
dense
(
x
,
4096
,
activation
=
tf
.
nn
.
relu
,
name
=
'fc6'
)
.
FullyConnected
(
'fc8'
,
1000
)())
x
=
tf
.
layers
.
dropout
(
x
,
rate
=
0.5
,
name
=
'drop0'
,
training
=
is_training
)
x
=
tf
.
layers
.
dense
(
x
,
4096
,
activation
=
tf
.
nn
.
relu
,
name
=
'fc7'
)
x
=
tf
.
layers
.
dropout
(
x
,
rate
=
0.5
,
name
=
'drop1'
,
training
=
is_training
)
logits
=
tf
.
layers
.
dense
(
x
,
1000
,
activation
=
tf
.
identity
,
name
=
'fc8'
)
tf
.
nn
.
softmax
(
logits
,
name
=
'prob'
)
tf
.
nn
.
softmax
(
logits
,
name
=
'prob'
)
def
run_test
(
path
,
input
):
def
run_test
(
path
,
input
):
param_dict
=
dict
(
np
.
load
(
path
))
param_dict
=
dict
(
np
.
load
(
path
))
param_dict
=
{
k
.
replace
(
'/W'
,
'/kernel'
)
.
replace
(
'/b'
,
'/bias'
):
v
for
k
,
v
in
six
.
iteritems
(
param_dict
)}
predict_func
=
OfflinePredictor
(
PredictConfig
(
predict_func
=
OfflinePredictor
(
PredictConfig
(
inputs_desc
=
[
InputDesc
(
tf
.
float32
,
(
None
,
224
,
224
,
3
),
'input'
)],
inputs_desc
=
[
InputDesc
(
tf
.
float32
,
(
None
,
224
,
224
,
3
),
'input'
)],
tower_func
=
tower_func
,
tower_func
=
tower_func
,
...
...
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