博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【解决错误】ValueError: some of the strides of a given numpy array are negative.
阅读量:2134 次
发布时间:2019-04-30

本文共 1631 字,大约阅读时间需要 5 分钟。

一、源码

def np2Tensor(l, rgb_range):    def _np2Tensor(img):        # if img.shape[2] == 3: # for opencv imread        #     img = img[:, :, [2, 1, 0]]        np_transpose = np.ascontiguousarray(img.transpose((2, 0, 1)), dtype=np.float32)        tensor = torch.from_numpy(np_transpose).float()        tensor.mul_(rgb_range / 255.)        return tensor    return [_np2Tensor(_l) for _l in l]

二、报错

  • 在复现SRFBN的时候遇到了一个报错,这里记录一下解决的过程,以为备忘!!!
File "D:\source code\SRFBN_CVPR19\data\LRHR_dataset.py", line 41, in __getitem__    lr_tensor, hr_tensor = common.np2Tensor([lr, hr], self.opt['rgb_range'])  File "D:\source code\SRFBN_CVPR19\data\common.py", line 119, in np2Tensor    return [_np2Tensor(_l) for _l in l]  File "D:\source code\SRFBN_CVPR19\data\common.py", line 119, in 
return [_np2Tensor(_l) for _l in l] File "D:\source code\SRFBN_CVPR19\data\common.py", line 114, in _np2Tensor tensor = torch.from_numpy(np_transpose).float()ValueError: some of the strides of a given numpy array are negative. This is currently not supported, but will be added in future releases.

三、原因

  • 这个原因是因为程序中操作的numpy中有使用负索引的情况

四、解决方案

  • **修改之处:**在np_transpose = np.ascontiguousarray(img.transpose((2, 0, 1)), dtype=np.float32)中指定了数据类型。
def np2Tensor(l, rgb_range):    def _np2Tensor(img):        # if img.shape[2] == 3: # for opencv imread        #     img = img[:, :, [2, 1, 0]]        np_transpose = np.ascontiguousarray(img.transpose((2, 0, 1)), dtype=np.float32)        tensor = torch.from_numpy(np_transpose).float()        tensor.mul_(rgb_range / 255.)        return tensor    return [_np2Tensor(_l) for _l in l]

五、参考

[1]

[2]
[3]
[4]
[5]

转载地址:http://kdugf.baihongyu.com/

你可能感兴趣的文章
Redis学习笔记(三)—— 使用redis客户端连接windows和linux下的redis并解决无法连接redis的问题
查看>>
Intellij IDEA使用(一)—— 安装Intellij IDEA(ideaIU-2017.2.3)并完成Intellij IDEA的简单配置
查看>>
Intellij IDEA使用(二)—— 在Intellij IDEA中配置JDK(SDK)
查看>>
Intellij IDEA使用(三)——在Intellij IDEA中配置Tomcat服务器
查看>>
Intellij IDEA使用(四)—— 使用Intellij IDEA创建静态的web(HTML)项目
查看>>
Intellij IDEA使用(五)—— Intellij IDEA在使用中的一些其他常用功能或常用配置收集
查看>>
Intellij IDEA使用(六)—— 使用Intellij IDEA创建Java项目并配置jar包
查看>>
Eclipse使用(十)—— 使用Eclipse创建简单的Maven Java项目
查看>>
Eclipse使用(十一)—— 使用Eclipse创建简单的Maven JavaWeb项目
查看>>
Intellij IDEA使用(十三)—— 在Intellij IDEA中配置Maven
查看>>
面试题 —— 关于main方法的十个面试题
查看>>
集成测试(一)—— 使用PHP页面请求Spring项目的Java接口数据
查看>>
使用Maven构建的简单的单模块SSM项目
查看>>
Intellij IDEA使用(十四)—— 在IDEA中创建包(package)的问题
查看>>
Redis学习笔记(四)—— redis的常用命令和五大数据类型的简单使用
查看>>
Win10+VS2015编译libcurl
查看>>
Windows下使用jsoncpp
查看>>
Ubuntu下测试使用Nginx+uWsgi+Django
查看>>
Windows下编译x264
查看>>
visual studio调试内存泄漏工具
查看>>