{
  "id": 28587,
  "title": "How to copy and crop one Tensor in Keras?",
  "url": "/competitions/dstl-satellite-imagery-feature-detection/discussion/28587",
  "author_name": "",
  "post_date": "2017-02-08T12:06:15.459571100Z",
  "votes": null,
  "comment_count": 2,
  "views": 0,
  "content": "<p>In my U-net model, I want to implement the method used in  <a href=\"https://arxiv.org/abs/1505.04597\">U-Net: Convolutional Networks for Biomedical Image Segmentation</a> without zero padding. So I need to do copy and crop during upsampling. But I have problem to implement the copy and crop in Keras. Any help will be appreciated.</p>",
  "messages": [
    {
      "id": "160560",
      "postDate": "02/08/2017 12:06:15",
      "content": "<p>In my U-net model, I want to implement the method used in  <a href=\"https://arxiv.org/abs/1505.04597\">U-Net: Convolutional Networks for Biomedical Image Segmentation</a> without zero padding. So I need to do copy and crop during upsampling. But I have problem to implement the copy and crop in Keras. Any help will be appreciated.</p>",
      "rawMarkdown": "In my U-net model, I want to implement the method used in  [U-Net: Convolutional Networks for Biomedical Image Segmentation][1] without zero padding. So I need to do copy and crop during upsampling. But I have problem to implement the copy and crop in Keras. Any help will be appreciated.\n\n\n  [1]: https://arxiv.org/abs/1505.04597",
      "votes": null
    },
    {
      "id": "160730",
      "postDate": "02/09/2017 08:07:44",
      "content": "<p>Hi Hao,</p>\n\n<p>you should use functional API of Keras if not already.</p>\n\n<pre><code> conv1 = Convolution2D(32, 3, 3)(input)\n conv2 = Convolution2D(64, 3, 3)(conv1)\n\n cropped = Cropping2D(cropping=((2, 2), (4, 4))(conv1)\n</code></pre>\n\n<p>conv1 is the output of the (32,3,3) conv layer and is used as the input of the next conv layer and also of the cropping layer</p>\n\n<p>References :\n<a href=\"https://keras.io/getting-started/functional-api-guide/\">https://keras.io/getting-started/functional-api-guide/</a>\n<a href=\"https://keras.io/layers/convolutional/#cropping2d\">https://keras.io/layers/convolutional/#cropping2d</a></p>\n\n<p>interesting U-Net like with Keras :\n<a href=\"https://github.com/jocicmarko/ultrasound-nerve-segmentation/blob/master/train.py\">https://github.com/jocicmarko/ultrasound-nerve-segmentation/blob/master/train.py</a></p>\n\n<p>I hope it may help.</p>",
      "rawMarkdown": "Hi Hao,\n\nyou should use functional API of Keras if not already.\n\n\n     conv1 = Convolution2D(32, 3, 3)(input)\n     conv2 = Convolution2D(64, 3, 3)(conv1)\n    \n     cropped = Cropping2D(cropping=((2, 2), (4, 4))(conv1)\n\n\nconv1 is the output of the (32,3,3) conv layer and is used as the input of the next conv layer and also of the cropping layer\n\n\nReferences :\nhttps://keras.io/getting-started/functional-api-guide/\nhttps://keras.io/layers/convolutional/#cropping2d\n\ninteresting U-Net like with Keras :\nhttps://github.com/jocicmarko/ultrasound-nerve-segmentation/blob/master/train.py\n\nI hope it may help.",
      "votes": null
    },
    {
      "id": "160805",
      "postDate": "02/09/2017 16:06:50",
      "content": "<p>Thanks, Cogitae. It really helps me.</p>",
      "rawMarkdown": "Thanks, Cogitae. It really helps me.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 160730,
      "author_name": "cogitae",
      "author_url": "",
      "post_date": "02/09/2017 08:07:44",
      "content": "<p>Hi Hao,</p>\n\n<p>you should use functional API of Keras if not already.</p>\n\n<pre><code> conv1 = Convolution2D(32, 3, 3)(input)\n conv2 = Convolution2D(64, 3, 3)(conv1)\n\n cropped = Cropping2D(cropping=((2, 2), (4, 4))(conv1)\n</code></pre>\n\n<p>conv1 is the output of the (32,3,3) conv layer and is used as the input of the next conv layer and also of the cropping layer</p>\n\n<p>References :\n<a href=\"https://keras.io/getting-started/functional-api-guide/\">https://keras.io/getting-started/functional-api-guide/</a>\n<a href=\"https://keras.io/layers/convolutional/#cropping2d\">https://keras.io/layers/convolutional/#cropping2d</a></p>\n\n<p>interesting U-Net like with Keras :\n<a href=\"https://github.com/jocicmarko/ultrasound-nerve-segmentation/blob/master/train.py\">https://github.com/jocicmarko/ultrasound-nerve-segmentation/blob/master/train.py</a></p>\n\n<p>I hope it may help.</p>",
      "votes": null,
      "replies": [
        {
          "id": 160805,
          "author_name": "lihaorocky",
          "author_url": "",
          "post_date": "02/09/2017 16:06:50",
          "content": "<p>Thanks, Cogitae. It really helps me.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "160560": "In my U-net model, I want to implement the method used in  [U-Net: Convolutional Networks for Biomedical Image Segmentation][1] without zero padding. So I need to do copy and crop during upsampling. But I have problem to implement the copy and crop in Keras. Any help will be appreciated.\n\n\n  [1]: https://arxiv.org/abs/1505.04597",
    "160730": "Hi Hao,\n\nyou should use functional API of Keras if not already.\n\n\n     conv1 = Convolution2D(32, 3, 3)(input)\n     conv2 = Convolution2D(64, 3, 3)(conv1)\n    \n     cropped = Cropping2D(cropping=((2, 2), (4, 4))(conv1)\n\n\nconv1 is the output of the (32,3,3) conv layer and is used as the input of the next conv layer and also of the cropping layer\n\n\nReferences :\nhttps://keras.io/getting-started/functional-api-guide/\nhttps://keras.io/layers/convolutional/#cropping2d\n\ninteresting U-Net like with Keras :\nhttps://github.com/jocicmarko/ultrasound-nerve-segmentation/blob/master/train.py\n\nI hope it may help.",
    "160805": "Thanks, Cogitae. It really helps me."
  },
  "source": "meta"
}