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

相关文章

Ilya-AI分享的他在OpenAI学习到的15个提示工程技巧

Ilya(不是本人,claude AI)在社交媒体上分享了他在OpenAI学习到的15个Prompt撰写技巧。 以下是详细的内容: 提示精确化:在编写提示时,力求表达清晰准确。清楚地阐述任务需求和概念定义至关重要。例:不用"分析文本",而用"判断这段话的情感倾向:积极、消极还是中性"。 快速迭代:善于快速连续调整提示。熟练的提示工程师能够灵活地进行多轮优化。例:从"总结文章"到"用

python: 多模块(.py)中全局变量的导入

文章目录 global关键字可变类型和不可变类型数据的内存地址单模块(单个py文件)的全局变量示例总结 多模块(多个py文件)的全局变量from x import x导入全局变量示例 import x导入全局变量示例 总结 global关键字 global 的作用范围是模块(.py)级别: 当你在一个模块(文件)中使用 global 声明变量时,这个变量只在该模块的全局命名空

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

【Prometheus】PromQL向量匹配实现不同标签的向量数据进行运算

✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,阿里云开发者社区专家博主,CSDN全栈领域优质创作者,掘金优秀博主,51CTO博客专家等。 🏆《博客》:Python全栈,前后端开发,小程序开发,人工智能,js逆向,App逆向,网络系统安全,数据分析,Django,fastapi

如何在页面调用utility bar并传递参数至lwc组件

1.在app的utility item中添加lwc组件: 2.调用utility bar api的方式有两种: 方法一,通过lwc调用: import {LightningElement,api ,wire } from 'lwc';import { publish, MessageContext } from 'lightning/messageService';import Ca

【Python编程】Linux创建虚拟环境并配置与notebook相连接

1.创建 使用 venv 创建虚拟环境。例如,在当前目录下创建一个名为 myenv 的虚拟环境: python3 -m venv myenv 2.激活 激活虚拟环境使其成为当前终端会话的活动环境。运行: source myenv/bin/activate 3.与notebook连接 在虚拟环境中,使用 pip 安装 Jupyter 和 ipykernel: pip instal

如何解决线上平台抽佣高 线下门店客流少的痛点!

目前,许多传统零售店铺正遭遇客源下降的难题。尽管广告推广能带来一定的客流,但其费用昂贵。鉴于此,众多零售商纷纷选择加入像美团、饿了么和抖音这样的大型在线平台,但这些平台的高佣金率导致了利润的大幅缩水。在这样的市场环境下,商家之间的合作网络逐渐成为一种有效的解决方案,通过资源和客户基础的共享,实现共同的利益增长。 以最近在上海兴起的一个跨行业合作平台为例,该平台融合了环保消费积分系统,在短

浅谈主机加固,六种有效的主机加固方法

在数字化时代,数据的价值不言而喻,但随之而来的安全威胁也日益严峻。从勒索病毒到内部泄露,企业的数据安全面临着前所未有的挑战。为了应对这些挑战,一种全新的主机加固解决方案应运而生。 MCK主机加固解决方案,采用先进的安全容器中间件技术,构建起一套内核级的纵深立体防护体系。这一体系突破了传统安全防护的局限,即使在管理员权限被恶意利用的情况下,也能确保服务器的安全稳定运行。 普适主机加固措施:

webm怎么转换成mp4?这几种方法超多人在用!

webm怎么转换成mp4?WebM作为一种新兴的视频编码格式,近年来逐渐进入大众视野,其背后承载着诸多优势,但同时也伴随着不容忽视的局限性,首要挑战在于其兼容性边界,尽管WebM已广泛适应于众多网站与软件平台,但在特定应用环境或老旧设备上,其兼容难题依旧凸显,为用户体验带来不便,再者,WebM格式的非普适性也体现在编辑流程上,由于它并非行业内的通用标准,编辑过程中可能会遭遇格式不兼容的障碍,导致操

【机器学习】高斯过程的基本概念和应用领域以及在python中的实例

引言 高斯过程(Gaussian Process,简称GP)是一种概率模型,用于描述一组随机变量的联合概率分布,其中任何一个有限维度的子集都具有高斯分布 文章目录 引言一、高斯过程1.1 基本定义1.1.1 随机过程1.1.2 高斯分布 1.2 高斯过程的特性1.2.1 联合高斯性1.2.2 均值函数1.2.3 协方差函数(或核函数) 1.3 核函数1.4 高斯过程回归(Gauss