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
OpenDAS
MMCV
Commits
9895a1af
Unverified
Commit
9895a1af
authored
Apr 02, 2020
by
lizz
Committed by
GitHub
Apr 02, 2020
Browse files
Check empty before clip grads (#219)
Signed-off-by:
lizz
<
lizz@sensetime.com
>
parent
cd873f9c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
2 deletions
+4
-2
mmcv/runner/hooks/optimizer.py
mmcv/runner/hooks/optimizer.py
+4
-2
No files found.
mmcv/runner/hooks/optimizer.py
View file @
9895a1af
...
...
@@ -11,8 +11,10 @@ class OptimizerHook(Hook):
self
.
grad_clip
=
grad_clip
def
clip_grads
(
self
,
params
):
clip_grad
.
clip_grad_norm_
(
filter
(
lambda
p
:
p
.
requires_grad
,
params
),
**
self
.
grad_clip
)
params
=
list
(
filter
(
lambda
p
:
p
.
requires_grad
and
p
.
grad
is
not
None
,
params
))
if
len
(
params
)
>
0
:
clip_grad
.
clip_grad_norm_
(
params
,
**
self
.
grad_clip
)
def
after_train_iter
(
self
,
runner
):
runner
.
optimizer
.
zero_grad
()
...
...
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