如何使用 X11 转发 运行 py-faster-rcnn
How to run py-faster-rcnn with X11 forwarding
我是 运行 py-faster-rcnn,在 Ubuntu 14.04 操作系统的 g2.8xlarge EC-2 实例上启用了 cuDNN。一切都已编译并且似乎运行良好。我通过以下方式登录到远程实例:
ssh -X -i "<key.pem>" ubuntu@<IP address>
我也输入命令:export DISPLAY=:0
运行 ./tools/demo.py
输出看起来不错:
Loaded network /home/ubuntu/py-faster-rcnn/data/faster_rcnn_models/VGG16_faster_rcnn_final.caffemodel
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/000456.jpg
Detection took 0.543s for 300 object proposals
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/000542.jpg
Detection took 0.506s for 161 object proposals
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/001150.jpg
Detection took 0.507s for 194 object proposals
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/001763.jpg
Detection took 0.507s for 196 object proposals
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/004545.jpg
Detection took 0.541s for 300 object proposals
但是我的 XQuartz 中没有呈现图形输出 window。
有没有其他人解决了这个问题?需要弄清楚如何使用 AWS 硬件但具有本地可视化功能。在这里检查,但我无法解决我的问题:BVLC/caffe#861
编辑
这里是我的远程 sshd_config
and local ssh_config
文件的链接。
以下是在远程 AWS 服务器环境中请求的测试结果:
$ echo $DISPLAY
localhost:10.0
和
$ DISPLAY=localhost:10.0 xhost && echo success
access control enabled, only authorized clients can connect
success
更新
运行 应用上述步骤后,远程计算机上的命令 xeyes
和 xcalc
会产生预期的输出(首先是眼睛,其次是计算器)在本地客户端上。这可能是一个 python 问题。打算从那里开始寻找。
解决方案——更新PYTHON库
在回复者 post 的指导下确认我的系统已设置为支持 X11 转发后,我专注于 运行 python 中的一系列测试以看看 matplotlib
是否与 X11 配合得很好。您可以通过 运行 this script interactively 自行查看。如果 xcalc
和 xeyes
按预期工作,但此脚本产生错误,则问题出在 python/matplotlib
。
我已经解决了这个问题,所以我手头没有这个错误,但是修复 Ubuntu 14.04,g2.8xlarge EC2 的步骤如下:
- 安装python gobject:
sudo apt-get install python-gobject-dev
- 安装python-tk:
sudo apt-get install python-tk
- 安装 pygtk:
wget http://ftp.gnome.org/pub/GNOME/sources/pygtk/2.24/pygtk-2.24.0.tar.gz
tar -xvzf pygtk-2.24.0.tar.gz
cd pygtk-2.24.0
./configure
make
sudo make install
cd
- 如果
matplotlib
是使用包管理器安装的,例如pip
,将其卸载并从源重新安装:
sudo pip uninstall matplotlib
git clone https://github.com/matplotlib/matplotlib.git
cd matplotlib
sudo python setup.py install
cd
- 不确定是否有必要,但是 运行
sudo apt-get install xorg openbox
是一个很好的措施。
完成上述步骤后,python ./tools/demo.py
与 py-faster-rcnn
根目录 returns 个边界框图像和 class 概率符合预期。
I also enter the command: export DISPLAY=:0
这一步可能是您的问题。当您通过 SSH 转发 X 时,几乎不需要在远程系统上手动设置 DISPLAY。
如果 ssh 成功转发 X,它会将远程会话中的 DISPLAY 环境变量设置为正确的值。如果未在远程系统上设置 DISPLAY,则意味着 ssh 无法与服务器协商以转发 X(或者您的 shell 启动中的某些内容正在删除该变量)。通过自己设置 DISPLAY,您可能会覆盖变量的正确值。至少,您设置的值对于通过 SSH 转发来说可能不正确。
DISPLAY 值“:0”表示通过系统的 X 默认连接,这可能涉及通过 unix 域套接字或通过 TCP 端口 6000 连接。这是为了让客户端访问 X 服务器 运行 在与客户端(在本例中为 EC2 服务器)相同的系统上。
对于 SSH 会话,正确的 DISPLAY 值通常类似于 "localhost:10",这意味着远程系统上的客户端应连接到本地主机端口 6010 (6000 + 10)。如果端口 6010 已被使用或 SSH 服务器配置为使用不同的端口范围,则数字 10 可能不同。
如果您发现尽管 运行 带有“-X”或“-Y”选项的 ssh 登录时未设置 DISPLAY,则可能是 ssh 中禁用了 X11 转发服务器。 OpenSSH 服务器有三个相关选项,可以是 set in sshd_config:
X11DisplayOffset
Specifies the first display number available for sshd(8)'s X11 forwarding. This prevents sshd from interfering with real X11 servers. The default is 10.
X11Forwarding
Specifies whether X11 forwarding is permitted. The argument must be “yes” or “no”. The default is “no”.
When X11 forwarding is enabled, there may be additional exposure to the server and to client displays if the sshd(8) proxy display is configured to listen on the wildcard address (see X11UseLocalhost below), though this is not the default. Additionally, the authentication spoofing and authentication data verification and substitution occur on the client side. The security risk of using X11 forwarding is that the client's X11 display server may be exposed to attack when the SSH client requests forwarding (see the warnings for ForwardX11 in ssh_config(5)). A system administrator may have a stance in which they want to protect clients that may expose themselves to attack by unwittingly requesting X11 forwarding, which can warrant a “no” setting.
Note that disabling X11 forwarding does not prevent users from forwarding X11 traffic, as users can always install their own forwarders. X11 forwarding is automatically disabled if UseLogin is enabled.
X11UseLocalhost
Specifies whether sshd(8) should bind the X11 forwarding server to the loopback address or to the wildcard address. By default, sshd binds the forwarding server to the loopback address and sets the hostname part of the DISPLAY environment variable to “localhost”. This prevents remote hosts from connecting to the proxy display. However, some older X11 clients may not function with this configuration. X11UseLocalhost may be set to “no” to specify that the forwarding server should be bound to the wildcard address. The argument must be “yes” or “no”. The default is “yes”.
OpenSSH ssh
客户端通常会连接到服务器,即使服务器拒绝转发。这可以隐藏您请求转发但服务器拒绝的事实。 ssh
有一个选项,您可以 set in ssh_config 来控制它:
ExitOnForwardFailure
Specifies whether ssh(1) should terminate the connection if it cannot set up all requested dynamic, tunnel, local, and remote port forwardings, (e.g. if either end is unable to bind and listen on a specified port). Note that ExitOnForwardFailure does not apply to connections made over port forwardings and will not, for example, cause ssh(1) to exit if TCP connections to the ultimate forwarding destination fail. The argument must be “yes” or “no”. The default is “no”.
我假设您的本地主机上有一个 X 服务器 运行,对吗?
有 2 个文件需要考虑:
/etc/ssh/ssh_config
:它位于您的本地主机上;它与客户端命令一起使用:ssh
.
/etc/ssh/sshd_config
:位于远程实例上;它与远程实例上的 sshd
服务器 运行 一起使用。
X11Forwarding yes
和 X11DisplayOffset 10
是需要为 sshd
设置的 2 个值:远程实例上的 ssh 守护进程 运行。编辑远程实例上的 /etc/ssh/sshd_config 文件。也许 sshd
必须在更改后在远程实例上重新启动。
再次连接 ssh -X ...
,并检查 DISPLAY
变量的值。
当设置 X11DisplayOffset 10
时,下面的示例是正确的:
# ssh -X -i "<key.pem>" ubuntu@<IP address>
# echo $DISPLAY
localhost:10.0
如果 DISPLAY
变量未设置或设置为另一个值(.bashrc .profile 等中的某些内容在登录时更改了它的值),那么这是一个问题。
另一种方法是用xhost
测试,在同一行设置环境:
# ssh -X -i "<key.pem>" ubuntu@<IP address>
# DISPLAY=localhost:10.0 xhost && echo success
如果显示错误消息,这是一个需要解决的问题:编辑您的问题并添加错误消息。
否则,打印状态行和 success
字,继续:
# DISPLAY=localhost:10.0 xcalc
A window 应该在本地主机上打开。最后继续:
# DISPLAY=localhost:10.0 ./tools/demo.py
我是 运行 py-faster-rcnn,在 Ubuntu 14.04 操作系统的 g2.8xlarge EC-2 实例上启用了 cuDNN。一切都已编译并且似乎运行良好。我通过以下方式登录到远程实例:
ssh -X -i "<key.pem>" ubuntu@<IP address>
我也输入命令:export DISPLAY=:0
运行 ./tools/demo.py
输出看起来不错:
Loaded network /home/ubuntu/py-faster-rcnn/data/faster_rcnn_models/VGG16_faster_rcnn_final.caffemodel
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/000456.jpg
Detection took 0.543s for 300 object proposals
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/000542.jpg
Detection took 0.506s for 161 object proposals
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/001150.jpg
Detection took 0.507s for 194 object proposals
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/001763.jpg
Detection took 0.507s for 196 object proposals
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo for data/demo/004545.jpg
Detection took 0.541s for 300 object proposals
但是我的 XQuartz 中没有呈现图形输出 window。
有没有其他人解决了这个问题?需要弄清楚如何使用 AWS 硬件但具有本地可视化功能。在这里检查,但我无法解决我的问题:BVLC/caffe#861
编辑
这里是我的远程 sshd_config
and local ssh_config
文件的链接。
以下是在远程 AWS 服务器环境中请求的测试结果:
$ echo $DISPLAY
localhost:10.0
和
$ DISPLAY=localhost:10.0 xhost && echo success
access control enabled, only authorized clients can connect
success
更新
运行 应用上述步骤后,远程计算机上的命令 xeyes
和 xcalc
会产生预期的输出(首先是眼睛,其次是计算器)在本地客户端上。这可能是一个 python 问题。打算从那里开始寻找。
解决方案——更新PYTHON库
在回复者 post 的指导下确认我的系统已设置为支持 X11 转发后,我专注于 运行 python 中的一系列测试以看看 matplotlib
是否与 X11 配合得很好。您可以通过 运行 this script interactively 自行查看。如果 xcalc
和 xeyes
按预期工作,但此脚本产生错误,则问题出在 python/matplotlib
。
我已经解决了这个问题,所以我手头没有这个错误,但是修复 Ubuntu 14.04,g2.8xlarge EC2 的步骤如下:
- 安装python gobject:
sudo apt-get install python-gobject-dev
- 安装python-tk:
sudo apt-get install python-tk
- 安装 pygtk:
wget http://ftp.gnome.org/pub/GNOME/sources/pygtk/2.24/pygtk-2.24.0.tar.gz
tar -xvzf pygtk-2.24.0.tar.gz
cd pygtk-2.24.0
./configure
make
sudo make install
cd
- 如果
matplotlib
是使用包管理器安装的,例如pip
,将其卸载并从源重新安装:sudo pip uninstall matplotlib
git clone https://github.com/matplotlib/matplotlib.git
cd matplotlib
sudo python setup.py install
cd
- 不确定是否有必要,但是 运行
sudo apt-get install xorg openbox
是一个很好的措施。
完成上述步骤后,python ./tools/demo.py
与 py-faster-rcnn
根目录 returns 个边界框图像和 class 概率符合预期。
I also enter the command:
export DISPLAY=:0
这一步可能是您的问题。当您通过 SSH 转发 X 时,几乎不需要在远程系统上手动设置 DISPLAY。
如果 ssh 成功转发 X,它会将远程会话中的 DISPLAY 环境变量设置为正确的值。如果未在远程系统上设置 DISPLAY,则意味着 ssh 无法与服务器协商以转发 X(或者您的 shell 启动中的某些内容正在删除该变量)。通过自己设置 DISPLAY,您可能会覆盖变量的正确值。至少,您设置的值对于通过 SSH 转发来说可能不正确。
DISPLAY 值“:0”表示通过系统的 X 默认连接,这可能涉及通过 unix 域套接字或通过 TCP 端口 6000 连接。这是为了让客户端访问 X 服务器 运行 在与客户端(在本例中为 EC2 服务器)相同的系统上。
对于 SSH 会话,正确的 DISPLAY 值通常类似于 "localhost:10",这意味着远程系统上的客户端应连接到本地主机端口 6010 (6000 + 10)。如果端口 6010 已被使用或 SSH 服务器配置为使用不同的端口范围,则数字 10 可能不同。
如果您发现尽管 运行 带有“-X”或“-Y”选项的 ssh 登录时未设置 DISPLAY,则可能是 ssh 中禁用了 X11 转发服务器。 OpenSSH 服务器有三个相关选项,可以是 set in sshd_config:
X11DisplayOffset
Specifies the first display number available for sshd(8)'s X11 forwarding. This prevents sshd from interfering with real X11 servers. The default is 10.X11Forwarding
Specifies whether X11 forwarding is permitted. The argument must be “yes” or “no”. The default is “no”.When X11 forwarding is enabled, there may be additional exposure to the server and to client displays if the sshd(8) proxy display is configured to listen on the wildcard address (see X11UseLocalhost below), though this is not the default. Additionally, the authentication spoofing and authentication data verification and substitution occur on the client side. The security risk of using X11 forwarding is that the client's X11 display server may be exposed to attack when the SSH client requests forwarding (see the warnings for ForwardX11 in ssh_config(5)). A system administrator may have a stance in which they want to protect clients that may expose themselves to attack by unwittingly requesting X11 forwarding, which can warrant a “no” setting.
Note that disabling X11 forwarding does not prevent users from forwarding X11 traffic, as users can always install their own forwarders. X11 forwarding is automatically disabled if UseLogin is enabled.
X11UseLocalhost
Specifies whether sshd(8) should bind the X11 forwarding server to the loopback address or to the wildcard address. By default, sshd binds the forwarding server to the loopback address and sets the hostname part of the DISPLAY environment variable to “localhost”. This prevents remote hosts from connecting to the proxy display. However, some older X11 clients may not function with this configuration. X11UseLocalhost may be set to “no” to specify that the forwarding server should be bound to the wildcard address. The argument must be “yes” or “no”. The default is “yes”.
OpenSSH ssh
客户端通常会连接到服务器,即使服务器拒绝转发。这可以隐藏您请求转发但服务器拒绝的事实。 ssh
有一个选项,您可以 set in ssh_config 来控制它:
ExitOnForwardFailure
Specifies whether ssh(1) should terminate the connection if it cannot set up all requested dynamic, tunnel, local, and remote port forwardings, (e.g. if either end is unable to bind and listen on a specified port). Note that ExitOnForwardFailure does not apply to connections made over port forwardings and will not, for example, cause ssh(1) to exit if TCP connections to the ultimate forwarding destination fail. The argument must be “yes” or “no”. The default is “no”.
我假设您的本地主机上有一个 X 服务器 运行,对吗?
有 2 个文件需要考虑:
/etc/ssh/ssh_config
:它位于您的本地主机上;它与客户端命令一起使用:ssh
./etc/ssh/sshd_config
:位于远程实例上;它与远程实例上的sshd
服务器 运行 一起使用。
X11Forwarding yes
和 X11DisplayOffset 10
是需要为 sshd
设置的 2 个值:远程实例上的 ssh 守护进程 运行。编辑远程实例上的 /etc/ssh/sshd_config 文件。也许 sshd
必须在更改后在远程实例上重新启动。
再次连接 ssh -X ...
,并检查 DISPLAY
变量的值。
当设置 X11DisplayOffset 10
时,下面的示例是正确的:
# ssh -X -i "<key.pem>" ubuntu@<IP address>
# echo $DISPLAY
localhost:10.0
如果 DISPLAY
变量未设置或设置为另一个值(.bashrc .profile 等中的某些内容在登录时更改了它的值),那么这是一个问题。
另一种方法是用xhost
测试,在同一行设置环境:
# ssh -X -i "<key.pem>" ubuntu@<IP address>
# DISPLAY=localhost:10.0 xhost && echo success
如果显示错误消息,这是一个需要解决的问题:编辑您的问题并添加错误消息。
否则,打印状态行和 success
字,继续:
# DISPLAY=localhost:10.0 xcalc
A window 应该在本地主机上打开。最后继续:
# DISPLAY=localhost:10.0 ./tools/demo.py