无法连接到 X 服务器 GOOGLE COLAB

Cannot connect to X server GOOGLE COLAB

我正在尝试使用 Tensorflow 对象检测 APIGoogle COLAB。我已经成功完成训练过程和导出推理图任务。

但问题是当我要做出新的预测时它会抛出一些错误日志。

cannot connect to X server

现在我无法做出新的预测。我的错误日志的一部分:

totalMemory: 11.17GiB freeMemory: 6.65GiB
2019-02-07 15:08:38.398219: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 0
2019-02-07 15:08:38.745889: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-02-07 15:08:38.745955: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990]      0 
2019-02-07 15:08:38.745975: I 
tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0:   N
2019-02-07 15:08:38.746201: W 
tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:42] Overriding allow_growth setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0.
2019-02-07 15:08:38.746259: I 
tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 6426 MB memory) -> physical GPU (device: 0, name: Tesla K80, pci bus id: 0000:00:04.0, compute capability: 3.7)
2019-02-07 15:08:39.683618: W ./tensorflow/core/grappler/optimizers/graph_optimizer_stage.h:241] Failed to run optimizer ArithmeticOptimizer, stage RemoveStackStridedSliceSameAxis node Preprocessor/map/while/ResizeToRange/strided_slice_3. Error: Pack node (Preprocessor/map/while/ResizeToRange/stack_2) axis attribute is out of bounds: 0
2019-02-07 15:08:40.360560: W ./tensorflow/core/grappler/optimizers/graph_optimizer_stage.h:241] Failed to run optimizer ArithmeticOptimizer, stage RemoveStackStridedSliceSameAxis node Preprocessor/map/while/ResizeToRange/strided_slice_3. Error: Pack node (Preprocessor/map/while/ResizeToRange/stack_2) axis attribute is out of bounds: 0
2019-02-07 15:08:40.646093: I tensorflow/stream_executor/dso_loader.cc:152] successfully opened CUDA library libcublas.so.10.0 locally
: cannot connect to X server 

如何找出这个问题的原因?

X 服务器是 X Window 系统中的一个程序,它在本地机器(即用户直接使用的计算机)上运行并处理对图形卡、显示屏和输入设备(通常键盘和鼠标)在这些计算机上。

话虽如此,Colab 在服务器中作为终端实例运行,如果您使用的是 GPU 运行时,那么问题不在于 X 服务器访问您的显卡,也不在于输入设备,通常这发生在您尝试解析一些应该在桌面上显示为单独 window 的数据,像 cv2.imshow() 这样的命令,可能还有其他类似的功能可能会导致这个问题,如果你必须使用图形输出你可能想看看进入 %matplotlib notebook 并在可交互的 matplot 图中显示数据。

如果这不是您的问题,只需 post 对您修改后的代码进行 link,我可能会提供更多帮助。

我在 Colab 中遇到了同样的问题,因为一个简单的 OpenCV 程序在网球比赛视频中跟踪网球并且不得不注释掉这些行,正如@anand 所提到的:

#cv2.namedWindow("motion")
#cv2.imshow("motion", img)# モーション画像を表示 

#cv2.destroyAllWindows()

注意:以上线条不是聚集而是散开。

我可以通过在 Google Colab note

中使用以下 python 代码来解决这个问题
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "1"