Skip to content

Commit

Permalink
Fix yolo to support a memory leak fix
Browse files Browse the repository at this point in the history
After this commit apache/mxnet#18328 , some memory leak were fixed.
Whitout this commit faster rcnn traning cannot be successfully closed.
These commits can be commit again after this yolo training fix.
apache/mxnet#18692
apache/mxnet@0496690
  • Loading branch information
chinakook authored Nov 17, 2020
1 parent 3fa9613 commit 3f35aa6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions gluoncv/data/transforms/presets/yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,14 @@ def __init__(self, width, height, net=None, mean=(0.485, 0.456, 0.406),

# in case network has reset_ctx to gpu
self._fake_x = mx.nd.zeros((1, 3, height, width))
net = copy.deepcopy(net)
net.collect_params().reset_ctx(None)
old_ctx = list(net.collect_params().values())[0].list_ctx()
net.collect_params().reset_ctx(mx.cpu())
with autograd.train_mode():
_, self._anchors, self._offsets, self._feat_maps, _, _, _, _ = net(self._fake_x)
from ....model_zoo.yolo.yolo_target import YOLOV3PrefetchTargetGenerator
self._target_generator = YOLOV3PrefetchTargetGenerator(
num_class=len(net.classes), **kwargs)
net.collect_params().reset_ctx(old_ctx)

def __call__(self, src, label):
"""Apply transform to training image/label."""
Expand Down

0 comments on commit 3f35aa6

Please sign in to comment.