前言
半路接手项目,阅读代码,解决bug,优化速度。
part one
- 1050 Ti加载模型时OOM
model.load_state_dict(torch.load(path))
Copies parameters and buffers from :attr:
state_dict
into
this module and its descendants. If :attr:strict
isTrue
, then
the keys of :attr:state_dict
must exactly match the keys returned
by this module’s :meth:~torch.nn.Module.state_dict
function.
Arguments:
state_dict (dict): a dict containing parameters and
persistent buffers.
strict (bool, optional): whether to strictly enforce that the keys
in :attr:state_dict
match the keys returned by this module’s
:meth:~torch.nn.Module.state_dict
function. Default:True
2019/1/16补:
其实问题是出在main函数,当时一直没考虑到(因为Java中必须得主函数作为运行入口,Python不强求,所以写Python代码没养成好习惯)。
所以,尽量写主函数,尽量少进行耗内存的初始化,确实需要该初始化操作的话,控制好它的初始化时间、范围。无用的import 尽量不要。
- 继续debug,发现在某个py脚本中,有变量赋值
sess, saver, net = load_tf_model()
所以在import的时候,这句代码会被解释执行,load_tf_model()函数中,
net = get_network("VGGnet_test&#