Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
f24fc412
Commit
f24fc412
authored
Jul 21, 2021
by
Frederick Liu
Committed by
A. Unique TensorFlower
Jul 21, 2021
Browse files
Internal change
PiperOrigin-RevId: 386029066
parent
1ec978a2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
2 deletions
+12
-2
official/core/train_utils.py
official/core/train_utils.py
+12
-2
No files found.
official/core/train_utils.py
View file @
f24fc412
...
...
@@ -377,11 +377,15 @@ def remove_ckpts(model_dir):
tf
.
io
.
gfile
.
remove
(
file_to_remove
)
def
try_count_params
(
model
:
tf
.
keras
.
Model
):
def
try_count_params
(
model
:
Union
[
tf
.
Module
,
tf
.
keras
.
Model
],
trainable_only
:
bool
=
False
):
"""Count the number of parameters if model is possible.
Args:
model: Try to count the number of params in this model.
trainable_only: Whether to calculate trainable params only. This flag is
not used when the model has `count_params` attribute.
Returns:
The number of parameters or None.
...
...
@@ -395,7 +399,13 @@ def try_count_params(model: tf.keras.Model):
'because the model was not feed any input, e.g., the max '
'train step already reached before this run.'
)
return
None
return
None
else
:
total_params
=
0
variables
=
model
.
trainable_variables
if
trainable_only
else
model
.
variables
for
var
in
variables
:
shape
=
tf
.
shape
(
var
)
total_params
+=
tf
.
math
.
reduce_prod
(
shape
).
numpy
()
return
total_params
def
try_count_flops
(
model
:
Union
[
tf
.
Module
,
tf
.
keras
.
Model
],
...
...
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