记困扰很久的pytorch加载模型OOM,python import执行流程,python“懒运行”,whindows控制ubuntu远程桌面

本文探讨了PyTorch加载模型时遇到的内存溢出问题,以及Python的import执行流程。强调了在import时避免耗内存的初始化操作,并提供了解决方案。同时,文章还介绍了Windows远程控制Ubuntu桌面的方法。
摘要由CSDN通过智能技术生成

前言

半路接手项目,阅读代码,解决bug,优化速度。

part one

  1. 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 is True, 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 尽量不要。

  1. 继续debug,发现在某个py脚本中,有变量赋值
    sess, saver, net = load_tf_model()
    所以在import的时候,这句代码会被解释执行,load_tf_model()函数中,
    net = get_network("VGGnet_test&#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值