The following error occurred while running the Keras code:
Traceback (most recent):
File "segnet_train.py", line 254, in <module>
Train (args)
File "segnet_train.py", line-up, 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, on 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 Inpu T shapes: [?, 1,128,128].
The picture processing document in Keras gives:
Dim_ordering:one of {"th", "TF"}. "TF" mode means that the images should has shape (samples, height, width, channels), "th" mode means that the images Shou LD has 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'll be "TF".
That
There are two types of dimension order for pictures, namely "th" and "TF", and their differences are as follows:
Picture dimension order type is th (dim_ordering= ' th '): Input data format is [Samples][channels][rows][cols];
When the picture dimension sequence type is TF (dim_ordering= ' TF '): The input data format is [samples][rows][cols][channels];
In Keras, the default is "TF" order, if you want to change the "th" order, you need to manually precede the following code:
From Keras import backend as K
k.set_image_dim_ordering (' th ')
Keras Error in dimension