利用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)

最新文章

  1. mac下生成ssh keys 并上传github仓储
  2. .数据库连接池技术:DBCP和C3P0
  3. C#播放声音的四种方法 +AxWindowsMediaPlayer的详细用法
  4. 关于 矩阵在ACM中的应用
  5. 把Git Repository建到U盘上去(转)
  6. C#中的特性基本理解
  7. scrapy 的三个入门应用场景
  8. 【python】 web开发入门
  9. 前不久一个swift项目用uicollectionview 用sdwebimage 加载图片,发生内存猛增,直接闪退的情况,简单说一下解决方案。
  10. Android 解决ScrollView下嵌套ListView进页面不在顶部的问题
  11. PHP中的常量
  12. (简单) LightOJ 1074 Extended Traffic,SPFA+负环。
  13. Why does eclipse automatically add appcompat v7 library support whenever I create a new project?
  14. 重构仿vue社区代码
  15. play @Before 的使用
  16. golang的包管理---vendor/dep等
  17. [转]centos7指定yum安装软件路径
  18. win10 HTTP 错误 500.21 - Internal Server Error
  19. [UE4]背景模糊
  20. Codeforces Round #429 (Div. 2)

热门文章

  1. 雷赛DMC2410_入门篇
  2. CF407D Largest Submatrix 3
  3. appium 自动化测试框架详读(一)
  4. Java一些小例子
  5. 关于spring读取配置文件的两种方式
  6. Linux 配置:Xmanager连接Linux图形界面
  7. elastic 基本操作
  8. Centos7.0 三种网络适配器
  9. golang 方法
  10. Laying out a webpage is easy with flex