我可以在没有GPU的机器上使用PyTorch或Tensorflow项目吗?

2024-05-20 01:53:09 发布

您现在位置:Python中文网/ 问答频道 /正文

说到Python和机器学习,我是个笨蛋。我正在尝试运行两个不同的项目,这两个项目都与一种称为深度图像抠图(Deep Image Matting)的东西有关:

我只是想在这些项目中运行测试,但我遇到了各种问题。我可以在没有GPU的机器上运行这些吗?我原以为GPU只是为了加快处理速度,但我只对在使用GPU的机器之前运行这些程序感兴趣。 我事先道歉,因为我知道我在这件事上是个十足的傻瓜

当我尝试Tensorflow项目时:

  1. 我在这一行gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction = args.gpu_fraction)上得到一个错误,可能是因为我是tf2,这需要tf1
  2. 在我尝试运行测试时降级到tf1之后,我得到了W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. InvalidArgumentError (see above for traceback): No OpKernel was registered to support Op 'MaxPoolWithArgmax' with these attrs. Registered devices: [CPU], Registered kernels: <no registered kernels>,现在我被卡住了,因为我不知道这意味着什么

当我尝试Pytorch项目时:

  1. 首先我得到这个错误:RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.
  2. 所以我在加载模型时添加了map_location=torch.device('cpu'),但是现在我得到了RuntimeError: Error(s) in loading state_dict for VGG16: size mismatch for conv6_1.weight: copying a param with shape torch.Size([512, 512, 1, 1]) from checkpoint, the shape in current model is torch.Size([512, 512, 3, 3]).,我又被卡住了

有人能帮忙吗

提前谢谢你


Tags: to项目机器mapforgpuison
1条回答
网友
1楼 · 发布于 2024-05-20 01:53:09

对于PyTorch one,有两个问题,看起来您已经用map_location自己解决了第一个问题。第二个问题是检查点中的权重和模型中的权重形状不同!快速绕过github回购协议;让我们访问内核中的net.py。请看第26到28行:

# model released before 2019.09.09 should use kernel_size=1 & padding=0
# self.conv6_1 = nn.Conv2d(512, 512, kernel_size=1, padding=0,bias=True)
self.conv6_1 = nn.Conv2d(512, 512, kernel_size=3, padding=1,bias=True)

我猜检查点正在加载conv6_1的内核大小为1而不是3的权重,就像注释掉的代码行一样。因此,请尝试取消注释kernel_size=1的行,并注释掉kernel_size=3的行

相关问题 更多 >