python调用caffe接口进行classify时提示Mean shape incompatible with input shape错误的解决方法

本文主要是介绍python调用caffe接口进行classify时提示Mean shape incompatible with input shape错误的解决方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

本文转自:http://blog.csdn.net/eagelangel/article/details/51009682?ref=myread

python调用caffe接口进行classify时提示Mean shape incompatible with input shape错误的解决方法:


第一种:将 mean = np.load(args.mean_file),改成 mean = np.load(args.mean_file).mean(1).mean(1)


第二种:修改caffe中python接口的源代码caffe/python/caffe/io.py,将

<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;"><span style="font-size:18px;"><span class="kwd" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 0, 139);">if</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> ms </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">!=</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> self</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">inputs</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">[</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">in_</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">][</span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; color: maroon;">1</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">:]:</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"></span><span class="kwd" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 0, 139);">raise</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> </span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; color: rgb(43, 145, 175);">ValueError</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">(</span><span class="str" style="margin: 0px; padding: 0px; border: 0px; color: maroon;">'Mean shape incompatible with input shape.'</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">)</span></span></code>
修改为

<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;"><span style="font-size:18px;"><span class="kwd" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 0, 139);">if</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> ms </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">!=</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> self</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">inputs</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">[</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">in_</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">][</span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; color: maroon;">1</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">:]:</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"></span><span class="kwd" style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 0, 139);">print</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">(</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">self</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">inputs</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">[</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">in_</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">])</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">in_shape </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">=</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> self</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">inputs</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">[</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">in_</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">][</span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; color: maroon;">1</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">:]</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">m_min</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">,</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> m_max </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">=</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> mean</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">min</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">(),</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> mean</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">max</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">()</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">normal_mean </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">=</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">(</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">mean </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">-</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> m_min</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">)</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">/</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">(</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">m_max </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">-</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> m_min</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">)</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">mean </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">=</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> resize_image</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">(</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">normal_mean</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">transpose</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">((</span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; color: maroon;">1</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">,</span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; color: maroon;">2</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">,</span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; color: maroon;">0</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">)),</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">in_shape</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">[</span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; color: maroon;">1</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">:]).</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">transpose</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">((</span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; color: maroon;">2</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">,</span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; color: maroon;">0</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">,</span><span class="lit" style="margin: 0px; padding: 0px; border: 0px; color: maroon;">1</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">))</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">*</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">(</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;">m_max </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">-</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> m_min</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">)</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; color: black;">+</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; color: black;"> m_min</span><span class="com" style="margin: 0px; padding: 0px; border: 0px; color: gray;">#raise ValueError('Mean shape incompatible with input shape.')</span></span></code>
并重新编译caffe-python接口

这篇关于python调用caffe接口进行classify时提示Mean shape incompatible with input shape错误的解决方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/729330

相关文章

Oracle查询优化之高效实现仅查询前10条记录的方法与实践

《Oracle查询优化之高效实现仅查询前10条记录的方法与实践》:本文主要介绍Oracle查询优化之高效实现仅查询前10条记录的相关资料,包括使用ROWNUM、ROW_NUMBER()函数、FET... 目录1. 使用 ROWNUM 查询2. 使用 ROW_NUMBER() 函数3. 使用 FETCH FI

Python脚本实现自动删除C盘临时文件夹

《Python脚本实现自动删除C盘临时文件夹》在日常使用电脑的过程中,临时文件夹往往会积累大量的无用数据,占用宝贵的磁盘空间,下面我们就来看看Python如何通过脚本实现自动删除C盘临时文件夹吧... 目录一、准备工作二、python脚本编写三、脚本解析四、运行脚本五、案例演示六、注意事项七、总结在日常使用

Git中恢复已删除分支的几种方法

《Git中恢复已删除分支的几种方法》:本文主要介绍在Git中恢复已删除分支的几种方法,包括查找提交记录、恢复分支、推送恢复的分支等步骤,文中通过代码介绍的非常详细,需要的朋友可以参考下... 目录1. 恢复本地删除的分支场景方法2. 恢复远程删除的分支场景方法3. 恢复未推送的本地删除分支场景方法4. 恢复

Python将大量遥感数据的值缩放指定倍数的方法(推荐)

《Python将大量遥感数据的值缩放指定倍数的方法(推荐)》本文介绍基于Python中的gdal模块,批量读取大量多波段遥感影像文件,分别对各波段数据加以数值处理,并将所得处理后数据保存为新的遥感影像... 本文介绍基于python中的gdal模块,批量读取大量多波段遥感影像文件,分别对各波段数据加以数值处

python管理工具之conda安装部署及使用详解

《python管理工具之conda安装部署及使用详解》这篇文章详细介绍了如何安装和使用conda来管理Python环境,它涵盖了从安装部署、镜像源配置到具体的conda使用方法,包括创建、激活、安装包... 目录pytpshheraerUhon管理工具:conda部署+使用一、安装部署1、 下载2、 安装3

Python进阶之Excel基本操作介绍

《Python进阶之Excel基本操作介绍》在现实中,很多工作都需要与数据打交道,Excel作为常用的数据处理工具,一直备受人们的青睐,本文主要为大家介绍了一些Python中Excel的基本操作,希望... 目录概述写入使用 xlwt使用 XlsxWriter读取修改概述在现实中,很多工作都需要与数据打交

详解Java如何向http/https接口发出请求

《详解Java如何向http/https接口发出请求》这篇文章主要为大家详细介绍了Java如何实现向http/https接口发出请求,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 用Java发送web请求所用到的包都在java.net下,在具体使用时可以用如下代码,你可以把它封装成一

使用MongoDB进行数据存储的操作流程

《使用MongoDB进行数据存储的操作流程》在现代应用开发中,数据存储是一个至关重要的部分,随着数据量的增大和复杂性的增加,传统的关系型数据库有时难以应对高并发和大数据量的处理需求,MongoDB作为... 目录什么是MongoDB?MongoDB的优势使用MongoDB进行数据存储1. 安装MongoDB

使用Python实现在Word中添加或删除超链接

《使用Python实现在Word中添加或删除超链接》在Word文档中,超链接是一种将文本或图像连接到其他文档、网页或同一文档中不同部分的功能,本文将为大家介绍一下Python如何实现在Word中添加或... 在Word文档中,超链接是一种将文本或图像连接到其他文档、网页或同一文档中不同部分的功能。通过添加超

Linux使用fdisk进行磁盘的相关操作

《Linux使用fdisk进行磁盘的相关操作》fdisk命令是Linux中用于管理磁盘分区的强大文本实用程序,这篇文章主要为大家详细介绍了如何使用fdisk进行磁盘的相关操作,需要的可以了解下... 目录简介基本语法示例用法列出所有分区查看指定磁盘的区分管理指定的磁盘进入交互式模式创建一个新的分区删除一个存