Loping151/ForPlane

Debug code

xwx0924 opened this issue · 16 comments

Hi,
I have a simple question. I can run the code smoothly, but when I use PyCharm to debug the code, I don't know how to set it up. The debugging process gets stuck near the base_iter of base_trainer, and even when I set a small batch_size, it still doesn't work. Do the authors have any debugging tips for this?

Hmm, I think the built-in Python debugger in VSCode is user-friendly enough. I'm not sure if this is due to issues with the debugger used by PyCharm. If you're willing to try VSCode, I'd be happy to help.

Thank you for your prompt response. I am now using VSCode for debugging, and there is a launch configuration file here. If it's convenient for you, could you please share how to set it up? I've been encountering continuous errors.

"configurations": [

    {
        "name": "Python: Current File",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "integratedTerminal",
        "justMyCode": true,
        "cwd": "${workspaceFolder}/..",
        "env":{
            "PYTHONPATH": "${workspaceFolder}/..",
            "CUDA_VISIBLE_DEVICES": "0"
        },
        "args":[
            
            "--configs","lerplanes/config/pull_soft_tissue-9k.py"
        ]

    }
    this is my debug launch.json
       {
            "name": "Debug Lerplanes",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/lerplanes/main.py",
            "args": [
                "--config-path", "lerplanes/config/example-9k.py"
            ],
            "env": {
                "PYTHONPATH": "."
            },
            "console": "integratedTerminal"
        }

Well, I currently use this config for reproduction. It seems your JSON is just fine. The debug command by VSCode for me is:
/usr/bin/env /home/loping151/.conda/envs/lerplane/bin/python /home/loping151/.vscode/extensions/ms-python.python-2023.20.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 54517 -- /home/loping151/blablabla/ForPlane/lerplanes/main.py --config-path lerplanes/config/example-9k.py and the debug process as well as direct training are both fine.
If you are sure your path and env are correct...where exactly did you get stuck?

Wait..where is your PYTHONPATH=. ?
Try mine.
In fact, nowadays you can ask GPT to generate a json for u. Just give him the training command, like this.
image
but I still recommend you to learn how to write.

是不是工作目录的问题,main文件是在lerplanes文件夹下,我好像读不到文件夹lerplane,这是我的配置文件:
"version": "0.2.0",
"configurations": [

    {
        "name": "Debug Lerplanes",
        "type": "python",
        "request": "launch",
        "program": "${workspaceFolder}/lerplanes/main.py",
        "cwd": "${workspaceFolder}",
        "args": [
            "--config-path", "lerplanes/config/pull_soft_tissue-9k.py"
        ],
        "env": {
            "PYTHONPATH": ".",
            "CUDA_VISIBLE_DEVICES": "0"
        },
        "console": "integratedTerminal"
    }

这是我的错误
from lerplanes.runners import video_trainer
发生异常: ModuleNotFoundError
No module named 'lerplanes'

这是debug的命令 和你的对比少了参数传入
cd /home/xwx/xwx/second/ForPlane-main ; /usr/bin/env /home/xwx/anaconda3/envs/lerplanes/bin/python /home/xwx/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 39189 -- /home/xwx/xwx/second/ForPlane-main/lerplanes/main.py

No module named 'lerplanes',你的工作路径是错误的,直接加上PYTHONPATH=.就好了。${workspaceFolder}是vscode打开的目录,你再/..好像反而到更外面去了

我已经改了那个配置文件了 这是最新的

    {
        "name": "Debug Lerplanes",
        "type": "python",
        "request": "launch",
        "program": "${workspaceFolder}/lerplanes/main.py",
        "args": [
            "--config-path", "lerplanes/config/pull_soft_tissue-9k.py"
        ],
        "env": {
            "PYTHONPATH": ".",
            "CUDA_VISIBLE_DEVICES": "0"
        },
        "console": "integratedTerminal"
    }

不知道为啥 直接运行训练命令是可以正常运行的...

我用vscode打开的文件夹是 Forplane-main,这应该就是${workspaceFolder},不知道为啥就是工作路径读不到...

我已经改了那个配置文件了 这是最新的

    {
        "name": "Debug Lerplanes",
        "type": "python",
        "request": "launch",
        "program": "${workspaceFolder}/lerplanes/main.py",
        "args": [
            "--config-path", "lerplanes/config/pull_soft_tissue-9k.py"
        ],
        "env": {
            "PYTHONPATH": ".",
            "CUDA_VISIBLE_DEVICES": "0"
        },
        "console": "integratedTerminal"
    }

所以这个还不行吗?

是的

还是报一样的错误.

我加了个这个命令 "cwd": "${workspaceFolder}", 发现出来的debug 命令中 明确的工作目录是对的 但代码那还是报错,这个应该是工作目录:/home/xwx/xwx/second/ForPlane-main
cd /home/xwx/xwx/second/ForPlane-main ; /usr/bin/env /home/xwx/anaconda3/envs/lerplanes/bin/python /home/xwx/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 39929 -- /home/xwx/xwx/second/ForPlane-main/lerplanes/main.py

好的 我加你了~~