使用vscode进行远程服务器代码调试

使用vscode进行远程服务器代码调试

使用了一段时间的vscode对服务器上的tensorflow代码进行调试,基本常用的功能摸索了一下,这里做一个总结记录。

1. 准备

  • 主机、服务器安装ssh

  • 将主机的ssh id_rsa.pub 写入服务器的/home/user_name/.ssh/authorized_keys文件中

  • vscode 的扩展中安装 Remote Development 套件

    [外链图片转存失败(img-eBPcwttv-1563782416177)(assets/1563780267284.png)]

2. 连接服务器

  • vscode中点击 F1,选择remote-ssh
    外链图片转存失败

  • 输入用户名及服务器ip:

    user_name@10.10.10.10
    
  • File -> open folder选择你的工作文件夹

    在这里插入图片描述

  • 此时,已经可以看到目录下的文件和代码,但是还不能使用debug功能

3.调试Debug

  • 安装扩展:python
    [外链图片转存失败(img-jKjHJWrg-1563782416178)(assets/1563781161929.png)]

  • 我还在服务器使用了anaconda,故也安装anaconda的扩展

    在这里插入图片描述

  • 此时,可以单机左下角选择调试需要的环境:

    [外链图片转存失败(img-jK2sANRE-1563782416178)(assets/1563781432427.png)]

    [外链图片转存失败(img-Q6Dpu84I-1563782416179)(assets/1563781461013.png)]

  • 至此,在程序中设置断点,即可进行调试啦~(F5调试,Ctrl + F5不调试运行)

    [外链图片转存失败(img-XHzgSaoH-1563782416179)(assets/1563781678117.png)]

4. 添加命令行变量

很多时候,跑代码的时候要设置环境变量(比如设置CUDA_VISIBLE_DEVICES)、运行路径、以及代码的命令行参数,按以下步骤操作:

  • 打开Debug -> Open Configurations

  • launch.json中更改,我这里设置了三个不同的debug参数,用于不同的文件使用:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        },
        
        {   "cwd": "/home/junyi/segmentation/tf-swift/",
            "env": {"CUDA_VISIBLE_DEVICES":[0]},
            "name": "Python: CS Train",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "args": [
                "--dataset","cityscapes",
                "--filter-scale","1",
                "--random-mirror",
                "--random-scale",
                "--update-mean-var",
                "--train-beta-gamma"
            ]
        },

        {   "cwd": "/home/junyi/segmentation/tf-swift/",
            "env": {"CUDA_VISIBLE_DEVICES":[3]},
            "name": "Python: CS Eval",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "args": [
                "--dataset","cityscapes"
            ]
        }
    ]
}

在这里插入图片描述

  • 19
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值