Pytorch中GPU训练好模型CPU下使用

el/2023/9/24 23:01:27

GPU训练模型在CPU下使用

今天我想试试那个SkyAR,但是我没找到GPU的电脑我就想在CPU下使用GPU训练好的模型,使用的时遇到了下面这个问题

`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.

后来发现是因为模型实在GPU上训练,加载模型时需要映射到CPU上才能使用。
解决方式就是在代码中找到加载模型的那个位置
我的是下面这样

checkpoint = torch.load(os.path.join(self.ckptdir,'best_ckpt.pt'))

将它修改为

checkpoint = torch.load(os.path.join(self.ckptdir,'best_ckpt.pt'),map_location=torch.device(device))

就可以使用了

`


http://www.ngui.cc/el/3577060.html

相关文章

C++按照空格分割字符串

C /A/B/1 1024 C /A/B/2 1024 C /A/B/1/3 1024 C /A 1024 R /A/B/1/3 Q / 0 1500 C /A/B/1 100 Q / 0 1500 R /A/B Q / 0 1 当我们需要处理上述数据时,其中有空格作为标志进行分割我们可以采取C中的一个处理string的标准库sstream。 操作方法如下: stri…

删除含有头结点的单链表中的最小值的结点

删除有头节点的单链表中的最小值的结点 #include <iostream>using namespace std;typedef struct node {int data;struct node *next; } LNode;void Del_minNode(LNode *L);LNode *CreateLink(const int data[], int n);void PrtLink(LNode *L);int main() {int n 6;int…

循环队列出队与入队

循环队列的入队与出队 #include <iostream>#define MaxSize 10using namespace std;typedef struct Node {int data[MaxSize];int front, rear; //队首&#xff0c;队尾指针 } SQueue;SQueue *init_queue();int En_queue(SQueue &qu, int x);int De_queue(SQueue &a…

邻接表创建有向图

使用邻接表创建有向图&#xff0c;可以使用数组链表的方式创建。 定义的顶点表如下 生成代码如下 char c; for (int i 0; i < graph->n; i) {cin >> c;graph->adj_list[i].data c;graph->adj_list[i].first_arc nullptr; }我们的图的整体结构如下图所示…

线索二叉树(先序)

#include <iostream>using namespace std;typedef struct ThBTNode {char data;ThBTNode *l_child;ThBTNode *r_child;int l_tag, r_tag;//l_tag1表示指向前驱&#xff0c;l_tag0表示指向左孩子//r_tag1表示指向后继&#xff0c;r_tag0表示指向右孩子 } ThBTNode;ThBTNod…

统计二叉树的叶子节点个数

#include <iostream> #include <queue>using namespace std;typedef struct node {char data;struct node *lchild;struct node *rchild; } TNode;TNode *CreateTree(TNode *&t);int Count(TNode *t); //统计t的叶子节点个数,非递归 int R_Count(TNode *t); //…

选择排序之选择排序

选择排序的思路很简单&#xff0c;就是左端为有序段&#xff0c;右端为待排序段&#xff0c;设置一个标志位&#xff0c;分割左右两端&#xff0c;外层循环控制标志位往后移&#xff0c;内层循环用于寻找无需段的最小值 #include <iostream>using namespace std;void Se…

创建一个简单的jsp跳转界面

创建环境&#xff1a;eclipsemaventomcatmysql 一&#xff1a;在eclipse下一次点击file-->new-->other-->maven-->maven project--> 如下图&#xff1a;勾选前两项 点击next,页面如下所示&#xff1a; Group id 和Artifact id 自己设定&#xff0c;Packaging将…

有bug的世界

不多说&#xff0c;点击---->知乎

有bug的世界(二)

看完后真的细思极恐&#xff0c;&#xff0c;-----> 转自知乎