Keras中维度报错

在运行keras代码的时候,出现了以下的错误:

Traceback (most recent call last):
  File "segnet_train.py", line 254, in <module>
    train(args)  
  File "segnet_train.py", line 210, in train
    model = SegNet()  
  File "segnet_train.py", line 134, in SegNet
    model.add(MaxPooling2D(pool_size=(2,2)))  
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/sequential.py", line 181, in add
    output_tensor = layer(self.outputs[0])
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/base_layer.py", line 457, in __call__
    output = self.call(inputs, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/keras/layers/pooling.py", line 205, in call
    data_format=self.data_format)
  File "/usr/local/lib/python2.7/dist-packages/keras/layers/pooling.py", line 268, in _pooling_function
    pool_mode=‘max‘)
  File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 3978, in pool2d
    data_format=tf_data_format)
  File "/home/ys/.local/lib/python2.7/site-packages/tensorflow/python/ops/nn_ops.py", line 2154, in max_pool
    name=name)
  File "/home/ys/.local/lib/python2.7/site-packages/tensorflow/python/ops/gen_nn_ops.py", line 4640, in max_pool
    data_format=data_format, name=name)
  File "/home/ys/.local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/ys/.local/lib/python2.7/site-packages/tensorflow/python/util/deprecation.py", line 454, in new_func
    return func(*args, **kwargs)
  File "/home/ys/.local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3155, in create_op
    op_def=op_def)
  File "/home/ys/.local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1731, in __init__
    control_input_ops)
  File "/home/ys/.local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1579, in _create_c_op
    raise ValueError(str(e))
ValueError: Negative dimension size caused by subtracting 2 from 1 for ‘max_pooling2d_2/MaxPool‘ (op: ‘MaxPool‘) with input shapes: [?,1,128,128].

Keras的图片处理文档中给出:
dim_ordering: One of {“th”, “tf”}. “tf” mode means that the images should have shape (samples, height, width, channels), “th” mode means that the images should have shape (samples, channels, height, width). It defaults to the image_dim_ordering value found in your Keras config file at ~/.keras/keras.json. If you never set it, then it will be “tf”.

即:

关于图片的维度顺序有两种类型,分别是“th”和”tf“,它们的差别如下:

图片维序类型为 th 时(dim_ordering=‘th‘): 输入数据格式为[samples][channels][rows][cols];

图片维序类型为 tf 时(dim_ordering=‘tf‘):输入数据格式为[samples][rows][cols][channels];

在Keras里默认的是“tf”顺序,如果想要改为“th”顺序,需要手动在前面加上如下代码:

  from keras import backend as K
  K.set_image_dim_ordering(‘th‘)

原文地址:https://www.cnblogs.com/yanshuai0922/p/9800329.html

时间: 2024-11-13 14:06:10

Keras中维度报错的相关文章

IE对象最后一个属性后不要加逗号,否则在IE7及以下版本中会报错

某函数返回一个对象,如果在最后一个属性后加逗号,IE7及以下版本中会报错 正确代码: return{ top:rect.top-top, bottom:rect.bottom-top, left:rect.left-left, right:rect.right-left } 错误代码(IE8以上都不会报错) return{ top:rect.top-top, bottom:rect.bottom-top, left:rect.left-left, right:rect.right-left, }

maven web 项目中启动报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener

本篇文章主要介绍了"maven web 项目中启动报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener ",主要涉及到maven web 项目中启动报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener 方面的内容,对于maven web 项目中启动报错jav

VC中编译报错:error C2011: &#39;fd_set&#39; : &#39;struct&#39; type redefinition

这是头文件包含顺序的问题,原因与解决办法见下面代码的注释. /* 包含下面这两个头文件时,必须把winsock2.h放在前面 否则编译报错,N多的重定义错误:例如 error C2011: 'fd_set' : 'struct' type redefinition */ #include <WinSock2.h> #include <Windows.h> int main(int argc, _TCHAR* argv[]) { Sleep(1); return 0; } 其实可以不

node 中 npm报错 Error: ENOENT, stat &#39;C:\Users\Administrator\AppData\Roaming\npm&#39;

今天在看node书本时,安装express,看看里面的包.没想到出现这样一种情况. 报错了.后来思考了一下,可能是修改了node的默认安装路径.于是准备在出错的路径下建一个npm文件夹. 注意,有个时候会出现找不到AppData文件夹.看图: 看到这张图时大家应该明白了.因为这张图是隐藏起来的.大家要把他显示出来.至于如何在win7下显示文件夹,就不在这罗嗦了. 完成npm文件夹的创建后: 安装express试试: 看到下面那么一大坨东西,相信大家已经知道express暗转成功了. 在看看有没有

安卓中运行报错Error:Execution failed for task &#39;:app:transformClassesWithDexForDebug&#39;解决

安卓中运行报错Error:Execution failed for task ':app:transformClassesWithDexForDebug'解决 安卓中运行报错Error:Execution failed for task ':app:transformClassesWithDexForDebug'解决

C# String.Format格式化json字符串中包含"{" "}"报错问题

json.Append(String.Format("{\"total\":{0},\"row\":{1}}", lineCount, strJSON));直接会报错 字符串中包含{或者},则需要用{{ 来代替字符 {,用}} 代替 }如:json.Append(String.Format("{{\"total\":{0},\"row\":{1}}}", lineCount, strJS

SVN 使用过程中的报错

SVN 使用过程中的报错 1.Error while creating module:org.apache.subversion.javahl.ClientException:Authorization failed svn:认证失败 出现情景:启动 svn 服务后,首次提交项目时 解决方案:修改仓储目录下的配置文件 svnserve.conf.passwd.authz 第一种:打开匿名访问.修改 svnserve.conf 文件,将 anon-access 的值改为 write 第二种:设置授

定时器setTimeout/setInterval中变量报错:not defined 的解决方法

首先声明本人资质尚浅,如有错误,欢迎指正.共同提高. ----------------------------------------------------------------------------------- 首先声明:本文不重点讨论this作用域,而是讨论普通变量在定时器中容易报错的情况: setTimeout的基本用法不再重述, 详见:http://www.w3school.com.cn/htmldom/met_win_settimeout.asp bug: setTimeout

基于Postman中的报错

Postman中的报错: Could not get any response 错误 Could not get any response There was an error connecting to http://127.0.0.1:8888/api/private/v1/login. Why this might have happened: The server couldn't send a response: Ensure that the backend is working p