利用Google Colab跑了50代的EDSR超分神经网络,然后把网络模型下载到win10上做测试,结果,一直出错,卡了好久

结果百度到这一文章:Pytorch load深度模型时报错:RuntimeError: cuda runtime error (10) : invalid device ordinal

引起这种报错的原因是因为pytorch在save模型的时候会把显卡的信息也保存,当重新load的时候,发现不是同一一块显卡就报错invalid device ordinal

知道之后,我赶紧跑的colab上做测试,结果又报错

训练默认使用了GPU,而我测试任然使用的是CPU的,所以出现以上错误

下面是可以使用的GPU下的测试:

from __future__ import print_function
import argparse
import torch
import torch.backends.cudnn as cudnn
from PIL import Image
from torchvision.transforms import ToTensor import numpy as np # ===========================================================
# Argument settings
# ===========================================================
parser = argparse.ArgumentParser(description='PyTorch Super Res Example')
parser.add_argument('--input', type=str, required=False, default='/content/drive/My Drive/app/EDSR_medical/path/rgb512.tif', help='input image to use')
parser.add_argument('--model', type=str, default='/content/drive/My Drive/app/EDSR_medical/path/EDSR_model_50.pth', help='model file to use')
parser.add_argument('--output_filename', type=str, default='/content/drive/My Drive/app/EDSR_medical/path/out_EDSR_50.tif', help='where to save the output image')
args = parser.parse_args()
print(args) # ===========================================================
# input image setting
# ===========================================================
GPU_IN_USE = torch.cuda.is_available()
img = Image.open(args.input)
red_c, green_c, blue_c = img.split() red_c.save('/content/drive/My Drive/app/EDSR_medical/path/red_c.tif')
green_c.save('/content/drive/My Drive/app/EDSR_medical/path/green_c.tif')
all_black = Image.open('/content/drive/My Drive/app/EDSR_medical/path/all_black_1024.tif')
# ===========================================================
# model import & setting
# ===========================================================
device = torch.device('cuda' if GPU_IN_USE else 'cpu')
model = torch.load(args.model)#, map_location=lambda storage, loc: storage
model = model.to(device)
data = (ToTensor()(red_c)).view(, -, y.size[], y.size[])
data = data.to(device) if GPU_IN_USE:
cudnn.benchmark = True # ===========================================================
# output and save image
# ===========================================================
out = model(data)
out = out.cpu()
out_img_r = out.data[].numpy()
out_img_r *= 255.0
out_img_r = out_img_r.clip(, )
out_img_r = Image.fromarray(np.uint8(out_img_r[]), mode='L') out_img_r.save('/content/drive/My Drive/app/EDSR_medical/path/test_r_1024_edsr_50.tif') out_img_g = all_black
out_img_b = all_black
out_img = Image.merge('RGB', [out_img_r, out_img_g, out_img_b]).convert('RGB')
#out_img = out_img_r
out_img.save(args.output_filename)
print('output image saved to ', args.output_filename)

迷人的bug--torch.load的更多相关文章

  1. 解决Torch.load()错误信息: UnicodeDecodeError: 'ascii' codec can't decode byte 0x8d in position 0: ordinal not in range(128)

    使用PyTorch跑pretrained预训练模型的时候,发现在加载数据的时候会报错,具体错误信息如下: File "main.py", line 238, in main_wor ...

  2. pytorch------cpu与gpu load时相互转化 torch.load(map_location=)

    将gpu改为cpu时,遇到一个报错: RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is ...

  3. golang bug Unknown load command 0x32 (50)

    问题 编译文件时报错: /usr/local/go/pkg/tool/darwin_amd64/link: /usr/local/go/pkg/tool/darwin_amd64/link: comb ...

  4. Pytorch中torch.load()中出现AttributeError: Can't get attribute

    原因:保存下来的模型和参数不能在没有类定义时直接使用. Pytorch使用Pickle来处理保存/加载模型,这个问题实际上是Pickle的问题,而不是Pytorch. 解决方法也非常简单,只需显式地导 ...

  5. 实践torch.fx第一篇——基于Pytorch的模型优化量化神器

    第一篇--什么是torch.fx 今天聊一下比较重要的torch.fx,也趁着这次机会把之前的torch.fx笔记整理下,笔记大概拆成三份,分别对应三篇: 什么是torch.fx 基于torch.fx ...

  6. 深度学习框架 Torch 7 问题笔记

    深度学习框架 Torch 7 问题笔记 1. 尝试第一个 CNN 的 torch版本, 代码如下: -- We now have 5 steps left to do in training our ...

  7. PyTorch官方中文文档:torch

    torch 包 torch 包含了多维张量的数据结构以及基于其上的多种数学操作.另外,它也提供了多种工具,其中一些可以更有效地对张量和任意类型进行序列化. 它有CUDA 的对应实现,可以在NVIDIA ...

  8. Deep Learning with Torch

    原文地址:https://github.com/soumith/cvpr2015/blob/master/Deep%20Learning%20with%20Torch.ipynb Deep Learn ...

  9. 学习笔记CB012: LSTM 简单实现、完整实现、torch、小说训练word2vec lstm机器人

    真正掌握一种算法,最实际的方法,完全手写出来. LSTM(Long Short Tem Memory)特殊递归神经网络,神经元保存历史记忆,解决自然语言处理统计方法只能考虑最近n个词语而忽略更久前词语 ...

随机推荐

  1. spring基于注解的IoC以及IoC的案例

    1.Spring中IoC的常用注解 1.1明确: (1)基于注解的配置和xml的配置要实现的功能都是一样的,都是要降低程序之间的耦合,只是配置的形式不一样 2.案例:使用xml方式和注解方式实现单表的 ...

  2. js截取字符串相关的知识点

    截取字符串中的数字 1.使用parseInt() var str ="4500元"; var num = parseInt(str); console.log(num);//450 ...

  3. jQuery 遍历 - 后代

    向下遍历 DOM 树 下面是两个用于向下遍历 DOM 树的 jQuery 方法: children() find() jQuery children() 方法 children() 方法返回被选元素的 ...

  4. Docker搭建Gitlab服务器

    1.使用docker搜索gitlab镜像 docker search gitlab 2.下载镜像: docker pull docker.io/gitlab/gitlab-ce 3.查看docker镜 ...

  5. 解决:使用java连接Fastdfs,上传文件时报:SocketTimeOutException的问题

    最近研究了下分布式存储Fastdfs,在centOS上配置完后,使用centOS或putty连接并上传图片,然后用浏览器读取storage server返回的URL,一切正常. 但是,使用eclips ...

  6. centos6.8 上传文件到amazon s3

    centos6.8 上传文件到amazon s3 0.参考 AWS CLI Cinnabd Reference Possible to sync a single file with aws s3 s ...

  7. CentOS 7 安装 gcc 4.1.2

    CentOS 7 安装 gcc 4.1.2 0. 参考 在centOS7.2上编译gcc4.1.2 1. 安装了编译所需 yum groupinstall "Development Tool ...

  8. D2. Kirk and a Binary String (hard version) D1 Kirk and a Binary String (easy version) Codeforces Round #581 (Div. 2) (实现,构造)

    D2. Kirk and a Binary String (hard version) time limit per test1 second memory limit per test256 meg ...

  9. zencart搜索结果页面静态化 advanced_search_result

    首先,确认网站是否安装了ultimate_seo_urls 伪静态模块. 修改include/classes/seo.url.php 大约126行添加代码 'keyword' => 'sale' ...

  10. 高性能mysql 第11章 可扩展的mysql

    可扩展性的定义:当增加资源以获得执行更多的工作系统能获得划算的同等提升. 向上扩展(垂直扩展):提升服务器的硬件性能. 向外扩展(水平扩展):一般都是复制,拆分,数据分片(sharding). 复制: ...