ValueError: "concat" mode can only merge layers with matching output shapes except for the concat
2017-11-08 19:33
936 查看
在keras中merge([x1, x2], mode=’concat’, concat_axis=channel_axis)时报了如下一个错
在这个问题主要是3维输入数组结构造成的,知乎专栏有一篇也是讲这个,地址是https://zhuanlan.zhihu.com/p/29673286,但事实上他的解决方法是比较表面的,下面就分析一下原因。
首先keras以tensorflow为后端时channel_axis要赋值为-1,以theano为后端时要赋值为1。这两个后端处理时数组的顺序是不一样的,tensorflow里就是正常逻辑299*299*3,相当于3通道,尺寸是299*299的图像数据,而在theano里则是3*299*299。
配置文件里的属于后端顺序,如果后端为tensorflow,前端输入成3*299*299,又强行把后端改成first,这样虽然也能跑通,但是只是为了看结果,没分析到本质。事实上也不用在json文件里修改,调用keras.backend.image_data_format()即可。
造成这个问题的根本原因其实是在输入3维数据时,必须输入特定形式的数据结构。
比如现在要求的输入矩阵是299*299*3的,那numpy array的形状应该是这样的一个二维数组[[x1,x2,x3],[x4,x5,6]…….],我只写出一行,相当于一共299行,每一行的长度是299。
而当传入这样的数据时就会报错[[(299*299)], [299*299], [299*299]],(299*299)代表里面是长宽都是299的矩阵。
Traceback (most recent call last): File "F:/visual/SSsearch/ineptionV4.py", line 215, in <module> model = create_model(5) File "F:/visual/SSsearch/ineptionV4.py", line 140, in create_model x = stem(input) File "F:/visual/SSsearch/ineptionV4.py", line 28, in stem x = merge([x1, x2], mode='concat', concat_axis=channel_axis) File "C:\Program Files\Anaconda3\lib\site-packages\keras\legacy\layers.py", line 458, in merge name=name) File "C:\Program Files\Anaconda3\lib\site-packages\keras\legacy\layers.py", line 110, in __init__ node_indices, tensor_indices) File "C:\Program Files\Anaconda3\lib\site-packages\keras\legacy\layers.py", line 190, in _arguments_validation 'Layer shapes: %s' % (input_shapes)) ValueError: "concat" mode can only merge layers with matching output shapes except for the concat axis. Layer shapes: [(None, 73, 73, 64), (None, 73, 73, 96)]
在这个问题主要是3维输入数组结构造成的,知乎专栏有一篇也是讲这个,地址是https://zhuanlan.zhihu.com/p/29673286,但事实上他的解决方法是比较表面的,下面就分析一下原因。
首先keras以tensorflow为后端时channel_axis要赋值为-1,以theano为后端时要赋值为1。这两个后端处理时数组的顺序是不一样的,tensorflow里就是正常逻辑299*299*3,相当于3通道,尺寸是299*299的图像数据,而在theano里则是3*299*299。
配置文件里的属于后端顺序,如果后端为tensorflow,前端输入成3*299*299,又强行把后端改成first,这样虽然也能跑通,但是只是为了看结果,没分析到本质。事实上也不用在json文件里修改,调用keras.backend.image_data_format()即可。
造成这个问题的根本原因其实是在输入3维数据时,必须输入特定形式的数据结构。
比如现在要求的输入矩阵是299*299*3的,那numpy array的形状应该是这样的一个二维数组[[x1,x2,x3],[x4,x5,6]…….],我只写出一行,相当于一共299行,每一行的长度是299。
而当传入这样的数据时就会报错[[(299*299)], [299*299], [299*299]],(299*299)代表里面是长宽都是299的矩阵。
相关文章推荐
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element
- 20100811 学习记录2:Webservice error, "The test form is only available for requests from the local machine"
- Kettle解析JSON错误,We MUST have the same number of values for all paths,We can not find and data with path [$.
- Can not find the tag library descriptor for "/struts-tags"问题
- How can I capture the audio output with GStreamer?
- Caused by: java.sql.SQLException: The MySQL server is running with the --read-only option so it cann
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element
- Loadrunner连接负载机失败,提示"Failed to connect to the load generator.Check the output window for more detail
- Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"(使用forEach时出错)
- Sharepoint Service Error: A deployment or retraction is already under way for the solution "xxx.wsp" , and only one deployment or retraction at a time
- 【406错误】 The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.
- MonkeyKing canOpenURL: failed for URL: "weixin://" - error: "The operation couldn’t be completed. (O
- Can not find the tag library descriptor for "http://www.springframework.org/tags"
- PostMessage出现1159错误:“The message can be used only with synchronous operations”
- The prefix "p" for attribute "p:myservice-ref" associated with an element type "bean" is not bound.
- WinServer 之 发布WebService后调用出现" The test form is only available for requests from the local machine. "
- Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
- wireshark:no interface can be used for capturing in this system with the current configuration
- <merge /> can be used only with a valid ViewGroup root and attachToRoot=true
- Can not find the tag library descriptor for "/struts-tags"问题