Keras ValueError:检查模型输入时出错:预期输入\节点有4个维度,但得到了形状为(0,1)的数组

Keras ValueError:检查模型输入时出错:预期输入\节点有4个维度,但得到了形状为(0,1)的数组,keras,Keras,使用Keras并在运行model.fit时出错,这会导致值错误。但不完全确定在使用fit时检查模型是如何失败的 ValueError: Error when checking model input: expected input_node to have 4 dimensions, but got array with shape (0, 1) 以下是来自堆栈跟踪的更多详细信息: history = st_model.fit(X, y, batch_size=args.batch_size,

使用Keras并在运行model.fit时出错,这会导致值错误。但不完全确定在使用fit时检查模型是如何失败的

ValueError: Error when checking model input: expected input_node to have 4 dimensions, but got array with shape (0, 1)
以下是来自堆栈跟踪的更多详细信息:

history = st_model.fit(X, y, batch_size=args.batch_size,  nb_epoch=args.nb_epoch, verbose=2, validation_data=(X_cv, y_cv), initial_epoch=0)
File "/usr/local/lib/python2.7/site-packages/keras/engine/training.py", line 1116, in fit
batch_size=batch_size)
File "/usr/local/lib/python2.7/site-packages/keras/engine/training.py", line 1029, in _standardize_user_data
exception_prefix='model input')
File "/usr/local/lib/python2.7/site-packages/keras/engine/training.py", line 112, in standardize_input_data
str(array.shape))
此外,这里还有一些关于模型的上下文

st_model = st_convt(input_shape, mode=2, nb_res_layer=args.nb_res_layer)
history = st_model.fit(X, y, batch_size=args.batch_size, nb_epoch=args.nb_epoch, verbose=2, validation_data=(X_cv, y_cv), initial_epoch=0)
然后

  # inputs th ordering, BGR
  def st_convt(input_shape, weights_path=None, mode=0, nb_res_layer=5):
      if K.image_dim_ordering() == 'tf':
          channel_axis = 3
      else:
          channel_axis = 1

      input = Input(shape=input_shape, name='input_node', dtype=K.floatx())
      # Downsampling
      c11 = Convolution2D(32, 9, 9, dim_ordering=K.image_dim_ordering(),
          init='he_normal', subsample=(1, 1), border_mode='same', activation='linear')(input)
      bn11 = BatchNormalization(mode=mode, axis=channel_axis, momentum=0.1, gamma_init='he_normal')(c11)
      a11 = Activation('relu')(bn11)

      c12 = Convolution2D(64, 3, 3, dim_ordering=K.image_dim_ordering(),
          init='he_normal', subsample=(2, 2),  border_mode='same', activation='linear')(a11)
      bn12 = BatchNormalization(mode=mode, axis=channel_axis, momentum=0.1, gamma_init='he_normal')(c12)
      a12 = Activation('relu')(bn12)

      c13 = Convolution2D(128, 3, 3, dim_ordering=K.image_dim_ordering(),
          init='he_normal', subsample=(2, 2), border_mode='same', activation='linear')(a12)
      bn13 = BatchNormalization(mode=mode, axis=channel_axis, momentum=0.1, gamma_init='he_normal')(c13)
      last_out = Activation('relu')(bn13)

      for i in range(nb_res_layer):
          c = Convolution2D(128, 3, 3, dim_ordering=K.image_dim_ordering(),
              init='he_normal', subsample=(1, 1), border_mode='same', activation='linear')(last_out)
          bn = BatchNormalization(mode=mode, axis=channel_axis, momentum=0.1, gamma_init='he_normal')(c)
          a = Activation('relu')(bn)
          c = Convolution2D(128, 3, 3, dim_ordering=K.image_dim_ordering(),
              init='he_normal', subsample=(1, 1), border_mode='same', activation='linear')(a)
          bn = BatchNormalization(mode=mode, axis=channel_axis, momentum=0.1, gamma_init='he_normal')(c)
          # a = Activation('relu')(bn)
          last_out = merge([last_out, bn], mode='sum')
          # last_out = a

      ct71 = ConvolutionTranspose2D(64, 3, 3, dim_ordering=K.image_dim_ordering(),
          init='he_normal', subsample=(2, 2), border_mode='same', activation='linear')(last_out)
      bn71 = BatchNormalization(mode=mode, axis=channel_axis, momentum=0.1, gamma_init='he_normal')(ct71)
      a71 = Activation('relu')(bn71)

      ct81 = ConvolutionTranspose2D(32, 3, 3, dim_ordering=K.image_dim_ordering(),
          init='he_normal', subsample=(2, 2), border_mode='same', activation='linear')(a71)
      bn81 = BatchNormalization(mode=mode, axis=channel_axis, momentum=0.1, gamma_init='he_normal')(ct81)
      a81 = Activation('relu')(bn81)

      c91 = Convolution2D(3, 9, 9, dim_ordering=K.image_dim_ordering(),
          init='he_normal', subsample=(1, 1), border_mode='same', activation='linear')(a81)
      out = ScaledSigmoid(scaling=255., name="output_node")(c91)

      model = Model(input=[input], output=[out])

      if weights_path:
          model.load_weights(weights_path)

      return model
您还可以通过以下方式克隆此项目: