ValueError: Negative dimension size caused by subtracting 2 from 1 for 'MaxPool_1' (op: 'MaxPool') w
来源:互联网 发布:淘宝高硼硅玻璃有毒吗 编辑:程序博客网 时间:2024/06/12 20:12
我在运行keras代码的时候,出现了以下的错误:
Traceback (most recent call last): File "vgg_feature.py", line 85, in <module> model = VGG_16('vgg16_weights_th_dim_ordering_th_kernels_notop.h5') File "vgg_feature.py", line 41, in VGG_16 model.add(MaxPooling2D((2, 2), strides=(2, 2))) File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 332, in add output_tensor = layer(self.outputs[0]) File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 572, in __call__ self.add_inbound_node(inbound_layers, node_indices, tensor_indices) File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 635, in add_inbound_node Node.create_node(self, inbound_layers, node_indices, tensor_indices) File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 166, in create_node output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0])) File "/usr/local/lib/python2.7/dist-packages/keras/layers/pooling.py", line 160, in call dim_ordering=self.dim_ordering) File "/usr/local/lib/python2.7/dist-packages/keras/layers/pooling.py", line 210, in _pooling_function pool_mode='max') File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 2866, in pool2d x = tf.nn.max_pool(x, pool_size, strides, padding=padding) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/nn_ops.py", line 1958, in max_pool name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_nn_ops.py", line 2806, in _max_pool data_format=data_format, name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2958, in create_op set_shapes_for_outputs(ret) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2209, in set_shapes_for_outputs shapes = shape_func(op) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2159, in call_with_requiring return call_cpp_shape_fn(op, require_shape_fn=True) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/common_shapes.py", line 627, in call_cpp_shape_fn require_shape_fn) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/common_shapes.py", line 691, in _call_cpp_shape_fn_impl raise ValueError(err.message)ValueError: Negative dimension size caused by subtracting 2 from 1 for 'MaxPool_1' (op: 'MaxPool') with input shapes: [?,1,112,128].idc@idc-Hi-Fi-Z77X:~/Downloads/Experiments/IJCAI2017$ rzidc@idc-Hi-Fi-Z77X:~/Downloads/Experiments/IJCAI2017$ python vgg_feature.py ../ijcai2017_multimodal_hashtag_data/test.txt Train_feat.h error_log data/testUsing TensorFlow backend.../ijcai2017_multimodal_hashtag_data/test.txtTrain_feat.hTraceback (most recent call last): File "vgg_feature.py", line 85, in <module> model = VGG_16('vgg16_weights_th_dim_ordering_th_kernels_notop.h5') File "vgg_feature.py", line 41, in VGG_16 model.add(MaxPooling2D((2, 2), strides=(2, 2))) File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 332, in add output_tensor = layer(self.outputs[0]) File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 572, in __call__ self.add_inbound_node(inbound_layers, node_indices, tensor_indices) File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 635, in add_inbound_node Node.create_node(self, inbound_layers, node_indices, tensor_indices) File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 166, in create_node output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0])) File "/usr/local/lib/python2.7/dist-packages/keras/layers/pooling.py", line 160, in call dim_ordering=self.dim_ordering) File "/usr/local/lib/python2.7/dist-packages/keras/layers/pooling.py", line 210, in _pooling_function pool_mode='max') File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 2866, in pool2d x = tf.nn.max_pool(x, pool_size, strides, padding=padding) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/nn_ops.py", line 1958, in max_pool name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_nn_ops.py", line 2806, in _max_pool data_format=data_format, name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2958, in create_op set_shapes_for_outputs(ret) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2209, in set_shapes_for_outputs shapes = shape_func(op) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2159, in call_with_requiring return call_cpp_shape_fn(op, require_shape_fn=True) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/common_shapes.py", line 627, in call_cpp_shape_fn require_shape_fn) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/common_shapes.py", line 691, in _call_cpp_shape_fn_impl raise ValueError(err.message)ValueError: Negative dimension size caused by subtracting 2 from 1 for 'MaxPool_1' (op: 'MaxPool') with input shapes: [?,1,112,128].
我的keras版本是keras 1.2.2, theano
解决办法是直接在python代码里面加入:
from keras import backend as KK.set_image_dim_ordering('th')
然后就不报错了。
参考文献
[1].Keras MaxPooling2D gives ValueError: Negative dimension size caused by subtracting 2 from 1 for 'MaxPool_x'.https://github.com/fchollet/keras/issues/3945
阅读全文
0 0
- ValueError: Negative dimension size caused by subtracting 2 from 1 for 'MaxPool_1' (op: 'MaxPool') w
- Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 2
- ValueError: Shape must be rank 0 but is rank 1 for 'train_data/ReadFile' (op: 'ReadFile') with input
- [R] creating matrices from vectors by adding a dimension attribute
- Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12
- Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1
- Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1
- Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1
- Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 75 to dimension
- Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1
- Caused by: java.net.NoRouteToHostException: No Route to Host from slave2/192.168.10.242 to master:1
- Caused by: java.lang.VerifyError: Cannot inherit from final class
- get dimension from sps
- Caused by: java.sql.SQLException: No value specified for parameter 2
- Caused by: java.sql.BatchUpdateException: Data truncation: Data too long for column 'cont' at row 1
- Caused by: java.sql.BatchUpdateException: Data truncation: Data too long for column 'JLFSM' at row 1
- Caused by: org.apache.ibatis.reflection.ReflectionException: Error instantiating class entity.User w
- Caused by: java.sql.SQLException: Invalid value for getInt()
- Kotlin的委托属性和区间
- Unity Shaders and Effects Cookbook 中的Packing and blending textures
- Java提高之HashMap
- BZOJ3876 [Ahoi2014&Jsoi2014]支线剧情
- 游标的作用
- ValueError: Negative dimension size caused by subtracting 2 from 1 for 'MaxPool_1' (op: 'MaxPool') w
- 12、Android开发基础之数据存储
- windows小知识
- python列表生成式
- 关于STM32L152 运行时程序卡在B.处的解决方法
- Python 安装和使用
- 【论文阅读笔记】A Multi-Task Learning Formulation for Predicting Disease Progression
- java导出Excel表格
- android ndk与sdk