{
  "id": 50500,
  "title": "Error when checking target: expected mixed10 to have shape (6, 6, 2048) but got array with shape (256, 256, 1)",
  "url": "/competitions/data-science-bowl-2018/discussion/50500",
  "author_name": "Saket Chaturvedi",
  "post_date": "2018-02-25T11:52:23.331000",
  "votes": 0,
  "comment_count": 0,
  "views": 0,
  "content": "<p>Hello Everyone,</p>\n\n<p>I am having trouble with the fitting model on training data. I tried to run the model with the following code, but unable to get the output. I tried changing the shape of input in the model using input shape but unable to resolve the problem. I am getting this error \" ValueError: Error when checking target: expected mixed10 to have shape (6, 6, 2048) but got array with shape (256, 256, 1) \"  while fitting through this code \"model.fit(train_img,train_mask,batch_size=16,epochs=epochs) \". Can any one please help to solve the problem? Also what can be the codes if I want to use pre-trained models for prediction. Thank you so much in advanvce. </p>\n\n<pre><code>def get_unet(IMG_WIDTH=224,IMG_HEIGHT=224,IMG_CHANNELS=3):\n    inputs = Input((IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS))\n    s = Lambda(lambda x: x / 255) (inputs)\n    model = Sequential()\n    model.add(ZeroPadding2D((1,1),input_shape=(3,224,224)))\n    model.add(Convolution2D(64, 3, 3, activation='relu'))\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(64, 3, 3, activation='relu'))\n    model.add(MaxPooling2D((2,2), strides=(2,2)))\n\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(128, 3, 3, activation='relu'))\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(128, 3, 3, activation='relu'))\n    model.add(MaxPooling2D((2,2), strides=(2,2)))\n\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(256, 3, 3, activation='relu'))\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(256, 3, 3, activation='relu'))\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(256, 3, 3, activation='relu'))\n    model.add(MaxPooling2D((2,2), strides=(2,2)))\n\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(512, 3, 3, activation='relu'))\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(512, 3, 3, activation='relu'))\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(512, 3, 3, activation='relu'))\n    model.add(MaxPooling2D((2,2), strides=(2,2)))\n\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(512, 3, 3, activation='relu'))\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(512, 3, 3, activation='relu'))\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(512, 3, 3, activation='relu'))\n    model.add(MaxPooling2D((2,2), strides=(2,2)))\n\n    model.add(Flatten())\n    model.add(Dense(4096, activation='relu'))\n    model.add(Dropout(0.5))\n    model.add(Dense(4096, activation='relu'))\n    model.add(Dropout(0.5))\n    model.add(Dense(1000, activation='softmax'))\n\n    if weights_path:\n        model.load_weights(weights_path)\n    outputs = Conv2D(1, (1, 1), activation='sigmoid') (c9)\n\n    model = Model(inputs=[inputs], outputs=[outputs])\n    model.compile(optimizer='adam',loss='binary_crossentropy', metrics=[dice_coef])\n    return model\n</code></pre>",
  "messages": [
    {
      "id": 287605,
      "postDate": "2018-02-25T11:52:23.330Z",
      "content": "<p>Hello Everyone,</p>\n\n<p>I am having trouble with the fitting model on training data. I tried to run the model with the following code, but unable to get the output. I tried changing the shape of input in the model using input shape but unable to resolve the problem. I am getting this error \" ValueError: Error when checking target: expected mixed10 to have shape (6, 6, 2048) but got array with shape (256, 256, 1) \"  while fitting through this code \"model.fit(train_img,train_mask,batch_size=16,epochs=epochs) \". Can any one please help to solve the problem? Also what can be the codes if I want to use pre-trained models for prediction. Thank you so much in advanvce. </p>\n\n<pre><code>def get_unet(IMG_WIDTH=224,IMG_HEIGHT=224,IMG_CHANNELS=3):\n    inputs = Input((IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS))\n    s = Lambda(lambda x: x / 255) (inputs)\n    model = Sequential()\n    model.add(ZeroPadding2D((1,1),input_shape=(3,224,224)))\n    model.add(Convolution2D(64, 3, 3, activation='relu'))\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(64, 3, 3, activation='relu'))\n    model.add(MaxPooling2D((2,2), strides=(2,2)))\n\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(128, 3, 3, activation='relu'))\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(128, 3, 3, activation='relu'))\n    model.add(MaxPooling2D((2,2), strides=(2,2)))\n\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(256, 3, 3, activation='relu'))\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(256, 3, 3, activation='relu'))\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(256, 3, 3, activation='relu'))\n    model.add(MaxPooling2D((2,2), strides=(2,2)))\n\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(512, 3, 3, activation='relu'))\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(512, 3, 3, activation='relu'))\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(512, 3, 3, activation='relu'))\n    model.add(MaxPooling2D((2,2), strides=(2,2)))\n\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(512, 3, 3, activation='relu'))\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(512, 3, 3, activation='relu'))\n    model.add(ZeroPadding2D((1,1)))\n    model.add(Convolution2D(512, 3, 3, activation='relu'))\n    model.add(MaxPooling2D((2,2), strides=(2,2)))\n\n    model.add(Flatten())\n    model.add(Dense(4096, activation='relu'))\n    model.add(Dropout(0.5))\n    model.add(Dense(4096, activation='relu'))\n    model.add(Dropout(0.5))\n    model.add(Dense(1000, activation='softmax'))\n\n    if weights_path:\n        model.load_weights(weights_path)\n    outputs = Conv2D(1, (1, 1), activation='sigmoid') (c9)\n\n    model = Model(inputs=[inputs], outputs=[outputs])\n    model.compile(optimizer='adam',loss='binary_crossentropy', metrics=[dice_coef])\n    return model\n</code></pre>",
      "rawMarkdown": "Hello Everyone,\n\nI am having trouble with the fitting model on training data. I tried to run the model with the following code, but unable to get the output. I tried changing the shape of input in the model using input shape but unable to resolve the problem. I am getting this error \" ValueError: Error when checking target: expected mixed10 to have shape (6, 6, 2048) but got array with shape (256, 256, 1) \"  while fitting through this code \"model.fit(train_img,train_mask,batch_size=16,epochs=epochs) \". Can any one please help to solve the problem? Also what can be the codes if I want to use pre-trained models for prediction. Thank you so much in advanvce. \n\n    def get_unet(IMG_WIDTH=224,IMG_HEIGHT=224,IMG_CHANNELS=3):\n        inputs = Input((IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS))\n        s = Lambda(lambda x: x / 255) (inputs)\n        model = Sequential()\n        model.add(ZeroPadding2D((1,1),input_shape=(3,224,224)))\n        model.add(Convolution2D(64, 3, 3, activation='relu'))\n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(64, 3, 3, activation='relu'))\n        model.add(MaxPooling2D((2,2), strides=(2,2)))\n    \n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(128, 3, 3, activation='relu'))\n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(128, 3, 3, activation='relu'))\n        model.add(MaxPooling2D((2,2), strides=(2,2)))\n    \n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(256, 3, 3, activation='relu'))\n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(256, 3, 3, activation='relu'))\n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(256, 3, 3, activation='relu'))\n        model.add(MaxPooling2D((2,2), strides=(2,2)))\n    \n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(512, 3, 3, activation='relu'))\n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(512, 3, 3, activation='relu'))\n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(512, 3, 3, activation='relu'))\n        model.add(MaxPooling2D((2,2), strides=(2,2)))\n    \n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(512, 3, 3, activation='relu'))\n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(512, 3, 3, activation='relu'))\n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(512, 3, 3, activation='relu'))\n        model.add(MaxPooling2D((2,2), strides=(2,2)))\n    \n        model.add(Flatten())\n        model.add(Dense(4096, activation='relu'))\n        model.add(Dropout(0.5))\n        model.add(Dense(4096, activation='relu'))\n        model.add(Dropout(0.5))\n        model.add(Dense(1000, activation='softmax'))\n    \n        if weights_path:\n            model.load_weights(weights_path)\n        outputs = Conv2D(1, (1, 1), activation='sigmoid') (c9)\n    \n        model = Model(inputs=[inputs], outputs=[outputs])\n        model.compile(optimizer='adam',loss='binary_crossentropy', metrics=[dice_coef])\n        return model"
    }
  ],
  "comments": [],
  "raw_markdown_by_id": {
    "287605": "Hello Everyone,\n\nI am having trouble with the fitting model on training data. I tried to run the model with the following code, but unable to get the output. I tried changing the shape of input in the model using input shape but unable to resolve the problem. I am getting this error \" ValueError: Error when checking target: expected mixed10 to have shape (6, 6, 2048) but got array with shape (256, 256, 1) \"  while fitting through this code \"model.fit(train_img,train_mask,batch_size=16,epochs=epochs) \". Can any one please help to solve the problem? Also what can be the codes if I want to use pre-trained models for prediction. Thank you so much in advanvce. \n\n    def get_unet(IMG_WIDTH=224,IMG_HEIGHT=224,IMG_CHANNELS=3):\n        inputs = Input((IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS))\n        s = Lambda(lambda x: x / 255) (inputs)\n        model = Sequential()\n        model.add(ZeroPadding2D((1,1),input_shape=(3,224,224)))\n        model.add(Convolution2D(64, 3, 3, activation='relu'))\n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(64, 3, 3, activation='relu'))\n        model.add(MaxPooling2D((2,2), strides=(2,2)))\n    \n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(128, 3, 3, activation='relu'))\n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(128, 3, 3, activation='relu'))\n        model.add(MaxPooling2D((2,2), strides=(2,2)))\n    \n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(256, 3, 3, activation='relu'))\n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(256, 3, 3, activation='relu'))\n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(256, 3, 3, activation='relu'))\n        model.add(MaxPooling2D((2,2), strides=(2,2)))\n    \n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(512, 3, 3, activation='relu'))\n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(512, 3, 3, activation='relu'))\n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(512, 3, 3, activation='relu'))\n        model.add(MaxPooling2D((2,2), strides=(2,2)))\n    \n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(512, 3, 3, activation='relu'))\n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(512, 3, 3, activation='relu'))\n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(512, 3, 3, activation='relu'))\n        model.add(MaxPooling2D((2,2), strides=(2,2)))\n    \n        model.add(Flatten())\n        model.add(Dense(4096, activation='relu'))\n        model.add(Dropout(0.5))\n        model.add(Dense(4096, activation='relu'))\n        model.add(Dropout(0.5))\n        model.add(Dense(1000, activation='softmax'))\n    \n        if weights_path:\n            model.load_weights(weights_path)\n        outputs = Conv2D(1, (1, 1), activation='sigmoid') (c9)\n    \n        model = Model(inputs=[inputs], outputs=[outputs])\n        model.compile(optimizer='adam',loss='binary_crossentropy', metrics=[dice_coef])\n        return model"
  }
}