Skip to content

Commit

Permalink
fix bug of tmp file path on win (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
JingweiZhang12 authored Apr 27, 2022
1 parent d231cfc commit 9fbc0d2
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions mmtrack/apis/inference.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) OpenMMLab. All rights reserved.
import logging
import os
import tempfile

import mmcv
Expand Down Expand Up @@ -48,15 +49,16 @@ def init_model(config,
# parameters. If not, the information of initialized parameters will be
# printed to the console because of the call of
# `mmcv.runner.BaseModule.init_weights`.
with tempfile.NamedTemporaryFile(mode='w+t') as tmp_init_params_file:
file_handler = logging.FileHandler(
tmp_init_params_file.name, mode='w')
model.logger.addHandler(file_handler)
# We need call `init_weights()` to load pretained weights in MOT
# task.
model.init_weights()
file_handler.close()
model.logger.removeHandler(file_handler)
tmp_file = tempfile.NamedTemporaryFile(delete=False)
file_handler = logging.FileHandler(tmp_file.name, mode='w')
model.logger.addHandler(file_handler)
# We need call `init_weights()` to load pretained weights in MOT
# task.
model.init_weights()
file_handler.close()
model.logger.removeHandler(file_handler)
tmp_file.close()
os.remove(tmp_file.name)
else:
# We need call `init_weights()` to load pretained weights in MOT task.
model.init_weights()
Expand Down

0 comments on commit 9fbc0d2

Please sign in to comment.