利用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. Redis原子计数器incr,防止并发请求

    转自:https://blog.csdn.net/Roy_70/article/details/78260826 一.前言在一些对高并发请求有限制的系统或者功能里,比如说秒杀活动,或者一些网站返回的当 ...

  2. Linux Exploit系列之一 典型的基于堆栈的缓冲区溢出

    Linux (x86) Exploit 开发系列教程之一(典型的基于堆栈的缓冲区溢出) Note:本文大部分来自于看雪hackyzh的中文翻译,加入了一些自己的理解 典型的基于堆栈的缓冲区溢出 虚拟机 ...

  3. Android单元测试之google官例CalculatorTest

    执行测试用例类CalculatorTest     设置genymotion可见: Android Studio界面中,依次单击菜单项 View >Toolbar.即可见改工具按钮. 启动gen ...

  4. javascript 几个易错点记录

    1.清空input标签值得时候,不能用html("")清空,要用val("")清空 2.事件如果绑定多次,触发事件后,回调函数也会执行多次,所有最好把绑定事件的 ...

  5. Django学习系列16:处理完POST请求后重定向

    处理完POST请求后重定向 代码中new_item_text = ''的写法不怎么样.解决第二个问题时候,顺带把这个问题也解决了. 人们都说处理完post请求后一定要重定向,接下来就实现这个功能吧.修 ...

  6. nginx理论基础

  7. web性能优化-浏览器渲染原理

    在web性能优化-浏览器工作原理中讲到,浏览器渲染是在renderer process中完成的. 那我们来看下renderer process究竟干了什么? Renderer Process包含的线程 ...

  8. 在vscode 中使用Git -- 已有项目添加到git

    本文使用与在已经存在本地项目的情况下将本地项目添加到git中管理,本地不存在项目则可以直接从Git上克隆下来后再创建项目目录更方便. 创建远程Git 仓库 如果Git 仓库已存在,可直接参考下一部,不 ...

  9. 说一说你对HTML5语义化的理解

    本题地址:https://github.com/YvetteLau/Step-By-Step/issues/8 语义化意味着顾名思义,HTML5的语义化指的是合理使用语义化的标签来创建页面结构,如he ...

  10. 《转发》特征工程——categorical特征 和 continuous特征

    from http://breezedeus.github.io/2014/11/15/breezedeus-feature-processing.html 请您移步原文观看,本文只供自己学习使用 连 ...