{
  "id": 168466,
  "title": "How to get shape of image in tf.dataset?",
  "url": "/competitions/siim-isic-melanoma-classification/discussion/168466",
  "author_name": "",
  "post_date": "2020-07-20T18:29:05.379236600Z",
  "votes": null,
  "comment_count": 2,
  "views": 0,
  "content": "<p>Passing preprocessing function to tf.data.Dataset.map method, but img.shape in preprocessing function return [None, None, 3], how can I get tensor shape in tf.data.Dataset? Has anyone encountered the same problem?\n<code>img = tf.io.read_file(path)\n    img = tf.image.decode_jpeg(img, channels=3)\n    w = img.shape[1]\n    h = img.shape[0]\n    if augment:\n        img = transform(img, cfg)\n        img = tf.image.random_flip_left_right(img)\n        img = tf.image.random_hue(img, 0.01)\n        img = tf.image.random_saturation(img, 0.7, 1.3)\n        img = tf.image.random_contrast(img, 0.8, 1.2)\n        img = tf.image.random_brightness(img, 0.1)\n    else:\n        if h &gt; w:\n            img = tf.image.crop_to_bounding_box(img, (h - w) // 2, 0, w, w)\n        else:\n            img = tf.image.crop_to_bounding_box(img, 0, (w - h) // 2, h, h)</code></p>",
  "messages": [
    {
      "id": "937124",
      "postDate": "07/20/2020 18:29:05",
      "content": "<p>Passing preprocessing function to tf.data.Dataset.map method, but img.shape in preprocessing function return [None, None, 3], how can I get tensor shape in tf.data.Dataset? Has anyone encountered the same problem?\n<code>img = tf.io.read_file(path)\n    img = tf.image.decode_jpeg(img, channels=3)\n    w = img.shape[1]\n    h = img.shape[0]\n    if augment:\n        img = transform(img, cfg)\n        img = tf.image.random_flip_left_right(img)\n        img = tf.image.random_hue(img, 0.01)\n        img = tf.image.random_saturation(img, 0.7, 1.3)\n        img = tf.image.random_contrast(img, 0.8, 1.2)\n        img = tf.image.random_brightness(img, 0.1)\n    else:\n        if h &gt; w:\n            img = tf.image.crop_to_bounding_box(img, (h - w) // 2, 0, w, w)\n        else:\n            img = tf.image.crop_to_bounding_box(img, 0, (w - h) // 2, h, h)</code></p>",
      "rawMarkdown": "Passing preprocessing function to tf.data.Dataset.map method, but img.shape in preprocessing function return [None, None, 3], how can I get tensor shape in tf.data.Dataset? Has anyone encountered the same problem?\n`img = tf.io.read_file(path)\n    img = tf.image.decode_jpeg(img, channels=3)\n    w = img.shape[1]\n    h = img.shape[0]\n    if augment:\n        img = transform(img, cfg)\n        img = tf.image.random_flip_left_right(img)\n        img = tf.image.random_hue(img, 0.01)\n        img = tf.image.random_saturation(img, 0.7, 1.3)\n        img = tf.image.random_contrast(img, 0.8, 1.2)\n        img = tf.image.random_brightness(img, 0.1)\n    else:\n        if h &gt; w:\n            img = tf.image.crop_to_bounding_box(img, (h - w) // 2, 0, w, w)\n        else:\n            img = tf.image.crop_to_bounding_box(img, 0, (w - h) // 2, h, h)`",
      "votes": null
    },
    {
      "id": "937138",
      "postDate": "07/20/2020 18:49:02",
      "content": "<p>I think you should use <code>tf.shape</code>. See: <a href=\"https://www.tensorflow.org/api_docs/python/tf/shape\">https://www.tensorflow.org/api_docs/python/tf/shape</a></p>",
      "rawMarkdown": "I think you should use `tf.shape`. See: https://www.tensorflow.org/api_docs/python/tf/shape",
      "votes": null
    },
    {
      "id": "937164",
      "postDate": "07/20/2020 19:16:55",
      "content": "<p>Thanks, it does work.👍 </p>",
      "rawMarkdown": "Thanks, it does work.👍",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 937138,
      "author_name": "graf10a",
      "author_url": "",
      "post_date": "07/20/2020 18:49:02",
      "content": "<p>I think you should use <code>tf.shape</code>. See: <a href=\"https://www.tensorflow.org/api_docs/python/tf/shape\">https://www.tensorflow.org/api_docs/python/tf/shape</a></p>",
      "votes": null,
      "replies": [
        {
          "id": 937164,
          "author_name": "anthonymarcz",
          "author_url": "",
          "post_date": "07/20/2020 19:16:55",
          "content": "<p>Thanks, it does work.👍 </p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "937124": "Passing preprocessing function to tf.data.Dataset.map method, but img.shape in preprocessing function return [None, None, 3], how can I get tensor shape in tf.data.Dataset? Has anyone encountered the same problem?\n`img = tf.io.read_file(path)\n    img = tf.image.decode_jpeg(img, channels=3)\n    w = img.shape[1]\n    h = img.shape[0]\n    if augment:\n        img = transform(img, cfg)\n        img = tf.image.random_flip_left_right(img)\n        img = tf.image.random_hue(img, 0.01)\n        img = tf.image.random_saturation(img, 0.7, 1.3)\n        img = tf.image.random_contrast(img, 0.8, 1.2)\n        img = tf.image.random_brightness(img, 0.1)\n    else:\n        if h &gt; w:\n            img = tf.image.crop_to_bounding_box(img, (h - w) // 2, 0, w, w)\n        else:\n            img = tf.image.crop_to_bounding_box(img, 0, (w - h) // 2, h, h)`",
    "937138": "I think you should use `tf.shape`. See: https://www.tensorflow.org/api_docs/python/tf/shape",
    "937164": "Thanks, it does work.👍"
  },
  "source": "meta"
}