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
be39dbdf
Commit
be39dbdf
authored
Dec 19, 2018
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix deprecation about dropout; fix Keras compatibility in tf1.13
parent
79148350
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
22 deletions
+45
-22
examples/DoReFa-Net/svhn-digit-dorefa.py
examples/DoReFa-Net/svhn-digit-dorefa.py
+1
-1
examples/FasterRCNN/README.md
examples/FasterRCNN/README.md
+22
-14
examples/basics/cifar-convnet.py
examples/basics/cifar-convnet.py
+2
-2
examples/keras/imagenet-resnet-keras.py
examples/keras/imagenet-resnet-keras.py
+2
-2
tensorpack/contrib/keras.py
tensorpack/contrib/keras.py
+18
-3
No files found.
examples/DoReFa-Net/svhn-digit-dorefa.py
View file @
be39dbdf
...
@@ -100,7 +100,7 @@ class Model(ModelDesc):
...
@@ -100,7 +100,7 @@ class Model(ModelDesc):
.
apply
(
fg
)
.
apply
(
fg
)
.
BatchNorm
(
'bn5'
)
.
apply
(
activate
)
.
BatchNorm
(
'bn5'
)
.
apply
(
activate
)
# 5
# 5
.
tf
.
nn
.
dropout
(
0.5
if
is_training
else
1
.0
)
.
Dropout
(
rate
=
0.5
if
is_training
else
0
.0
)
.
Conv2D
(
'conv6'
,
512
,
5
,
padding
=
'VALID'
)
.
Conv2D
(
'conv6'
,
512
,
5
,
padding
=
'VALID'
)
.
apply
(
fg
)
.
BatchNorm
(
'bn6'
)
.
apply
(
fg
)
.
BatchNorm
(
'bn6'
)
.
apply
(
nonlin
)
.
apply
(
nonlin
)
...
...
examples/FasterRCNN/README.md
View file @
be39dbdf
This diff is collapsed.
Click to expand it.
examples/basics/cifar-convnet.py
View file @
be39dbdf
...
@@ -33,7 +33,7 @@ class Model(ModelDesc):
...
@@ -33,7 +33,7 @@ class Model(ModelDesc):
def
build_graph
(
self
,
image
,
label
):
def
build_graph
(
self
,
image
,
label
):
is_training
=
get_current_tower_context
()
.
is_training
is_training
=
get_current_tower_context
()
.
is_training
keep_prob
=
tf
.
constant
(
0.5
if
is_training
else
1
.0
)
drop_rate
=
tf
.
constant
(
0.5
if
is_training
else
0
.0
)
if
is_training
:
if
is_training
:
tf
.
summary
.
image
(
"train_image"
,
image
,
10
)
tf
.
summary
.
image
(
"train_image"
,
image
,
10
)
...
@@ -56,7 +56,7 @@ class Model(ModelDesc):
...
@@ -56,7 +56,7 @@ class Model(ModelDesc):
.
Conv2D
(
'conv3.1'
,
filters
=
128
,
padding
=
'VALID'
)
\
.
Conv2D
(
'conv3.1'
,
filters
=
128
,
padding
=
'VALID'
)
\
.
Conv2D
(
'conv3.2'
,
filters
=
128
,
padding
=
'VALID'
)
\
.
Conv2D
(
'conv3.2'
,
filters
=
128
,
padding
=
'VALID'
)
\
.
FullyConnected
(
'fc0'
,
1024
+
512
,
activation
=
tf
.
nn
.
relu
)
\
.
FullyConnected
(
'fc0'
,
1024
+
512
,
activation
=
tf
.
nn
.
relu
)
\
.
tf
.
nn
.
dropout
(
keep_prob
)
\
.
Dropout
(
rate
=
drop_rate
)
\
.
FullyConnected
(
'fc1'
,
512
,
activation
=
tf
.
nn
.
relu
)
\
.
FullyConnected
(
'fc1'
,
512
,
activation
=
tf
.
nn
.
relu
)
\
.
FullyConnected
(
'linear'
,
out_dim
=
self
.
cifar_classnum
)()
.
FullyConnected
(
'linear'
,
out_dim
=
self
.
cifar_classnum
)()
...
...
examples/keras/imagenet-resnet-keras.py
View file @
be39dbdf
...
@@ -147,8 +147,8 @@ if __name__ == '__main__':
...
@@ -147,8 +147,8 @@ if __name__ == '__main__':
num_gpu
=
get_num_gpu
()
num_gpu
=
get_num_gpu
()
if
args
.
fake
:
if
args
.
fake
:
df_train
=
FakeData
([[
64
,
224
,
224
,
3
],
[
64
,
1000
]],
5000
,
random
=
False
,
dtype
=
'uint8'
)
df_train
=
FakeData
([[
32
,
224
,
224
,
3
],
[
32
,
1000
]],
5000
,
random
=
False
,
dtype
=
'uint8'
)
df_val
=
FakeData
([[
64
,
224
,
224
,
3
],
[
64
,
1000
]],
5000
,
random
=
False
)
df_val
=
FakeData
([[
32
,
224
,
224
,
3
],
[
32
,
1000
]],
5000
,
random
=
False
)
else
:
else
:
batch_size
=
TOTAL_BATCH_SIZE
//
num_gpu
batch_size
=
TOTAL_BATCH_SIZE
//
num_gpu
assert
args
.
data
is
not
None
assert
args
.
data
is
not
None
...
...
tensorpack/contrib/keras.py
View file @
be39dbdf
...
@@ -4,7 +4,9 @@
...
@@ -4,7 +4,9 @@
import
tensorflow
as
tf
import
tensorflow
as
tf
import
six
import
six
from
tensorflow
import
keras
from
tensorflow
import
keras
import
tensorflow.keras.backend
as
K
from
tensorflow.python.keras
import
metrics
as
metrics_module
from
tensorflow.python.keras
import
metrics
as
metrics_module
from
contextlib
import
contextmanager
from
..models.regularize
import
regularize_cost_from_collection
from
..models.regularize
import
regularize_cost_from_collection
from
..train
import
Trainer
,
SimpleTrainer
,
SyncMultiGPUTrainerParameterServer
from
..train
import
Trainer
,
SimpleTrainer
,
SyncMultiGPUTrainerParameterServer
...
@@ -82,7 +84,19 @@ class KerasModelCaller(object):
...
@@ -82,7 +84,19 @@ class KerasModelCaller(object):
if
self
.
cached_model
is
None
:
if
self
.
cached_model
is
None
:
assert
not
reuse
assert
not
reuse
model
=
self
.
cached_model
=
self
.
get_model
(
*
input_tensors
)
# starting from some versions, tf.keras starts to prepend name scope to variable names ..
@
contextmanager
def
clear_tower0_name_scope
():
ns
=
tf
.
get_default_graph
()
.
get_name_scope
()
if
ns
==
'tower0'
:
with
tf
.
name_scope
(
'/'
):
yield
else
:
yield
with
clear_tower0_name_scope
():
model
=
self
.
cached_model
=
self
.
get_model
(
*
input_tensors
)
outputs
=
model
.
outputs
outputs
=
model
.
outputs
elif
reuse
:
elif
reuse
:
# use the cached Keras model to mimic reuse
# use the cached Keras model to mimic reuse
...
@@ -108,7 +122,7 @@ class KerasPhaseCallback(Callback):
...
@@ -108,7 +122,7 @@ class KerasPhaseCallback(Callback):
def
__init__
(
self
,
isTrain
):
def
__init__
(
self
,
isTrain
):
assert
isinstance
(
isTrain
,
bool
),
isTrain
assert
isinstance
(
isTrain
,
bool
),
isTrain
self
.
_isTrain
=
isTrain
self
.
_isTrain
=
isTrain
self
.
_learning_phase
=
keras
.
backend
.
learning_phase
()
self
.
_learning_phase
=
K
.
learning_phase
()
def
_setup_graph
(
self
):
def
_setup_graph
(
self
):
logger
.
info
(
"Using Keras learning phase {} in the graph!"
.
format
(
logger
.
info
(
"Using Keras learning phase {} in the graph!"
.
format
(
...
@@ -200,7 +214,8 @@ def setup_keras_trainer(
...
@@ -200,7 +214,8 @@ def setup_keras_trainer(
input
,
input
,
get_cost
,
get_cost
,
lambda
:
optimizer
)
lambda
:
optimizer
)
if
model_caller
.
cached_model
.
uses_learning_phase
:
if
len
(
K
.
learning_phase
()
.
consumers
())
>
0
:
# check if learning_phase is used in this model
trainer
.
register_callback
(
KerasPhaseCallback
(
True
))
trainer
.
register_callback
(
KerasPhaseCallback
(
True
))
...
...
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