{
  "id": 170911,
  "title": "Use openCV functions for images read by decode_jpeg in TF?",
  "url": "/competitions/siim-isic-melanoma-classification/discussion/170911",
  "author_name": "",
  "post_date": "2020-07-29T13:45:23.115769200Z",
  "votes": null,
  "comment_count": 4,
  "views": 0,
  "content": "<p>Hi, </p>\n\n<p>I'm now reviewing my image preprocessing steps for aiming better score, but got some problem. </p>\n\n<p>Currently, I'm reading all the image data from TFRecord and using <code>tf.io.decode_jpeg</code> to read all the images. Now, I realized that I can do some extra image augmentation, which requires me to use openCV functions. However, when I simply pass loaded images to <code>cv2.cvtColor()</code>, I get this error: \n<code>TypeError: Expected Ptr&lt;cv::UMat&gt; for argument 'src'</code>. </p>\n\n<p>Are there any way to solve this problem? Also, not only this one, but I have several more operations using openCV functions, so it would be a great pleasure if you comment any good ways to make images decoded by<code>tf.io.decode_jpeg</code> compatible with openCV functions. </p>",
  "messages": [
    {
      "id": "950610",
      "postDate": "07/29/2020 13:45:23",
      "content": "<p>Hi, </p>\n\n<p>I'm now reviewing my image preprocessing steps for aiming better score, but got some problem. </p>\n\n<p>Currently, I'm reading all the image data from TFRecord and using <code>tf.io.decode_jpeg</code> to read all the images. Now, I realized that I can do some extra image augmentation, which requires me to use openCV functions. However, when I simply pass loaded images to <code>cv2.cvtColor()</code>, I get this error: \n<code>TypeError: Expected Ptr&lt;cv::UMat&gt; for argument 'src'</code>. </p>\n\n<p>Are there any way to solve this problem? Also, not only this one, but I have several more operations using openCV functions, so it would be a great pleasure if you comment any good ways to make images decoded by<code>tf.io.decode_jpeg</code> compatible with openCV functions. </p>",
      "rawMarkdown": "Hi, \n\nI'm now reviewing my image preprocessing steps for aiming better score, but got some problem. \n\nCurrently, I'm reading all the image data from TFRecord and using `tf.io.decode_jpeg` to read all the images. Now, I realized that I can do some extra image augmentation, which requires me to use openCV functions. However, when I simply pass loaded images to `cv2.cvtColor()`, I get this error: \n`TypeError: Expected Ptr",
      "votes": null
    },
    {
      "id": "950992",
      "postDate": "07/29/2020 19:29:42",
      "content": "<p>Yes, this is a problem, If you want to use TPU and TFRec then you should use only TF operations and we cannot use very convenient CV2 and albumentations.\nBut it is possible to apply these libraries for GPU or preprocess images, save them in TFRec format and use TPU (a little bit hard way)</p>",
      "rawMarkdown": "Yes, this is a problem, If you want to use TPU and TFRec then you should use only TF operations and we cannot use very convenient CV2 and albumentations.\nBut it is possible to apply these libraries for GPU or preprocess images, save them in TFRec format and use TPU (a little bit hard way)",
      "votes": null
    },
    {
      "id": "951172",
      "postDate": "07/30/2020 00:51:28",
      "content": "<p>I've done the preprocess method for \"cut\" and it was relatively easy. I made separate TFRecords with preprocessed \"Cut\" images. Uploaded them as their own dataset. If I want to use them, I just concatenate my regular training TFRecord list with the \"cut\" records and shuffle.</p>",
      "rawMarkdown": "I've done the preprocess method for \"cut\" and it was relatively easy. I made separate TFRecords with preprocessed \"Cut\" images. Uploaded them as their own dataset. If I want to use them, I just concatenate my regular training TFRecord list with the \"cut\" records and shuffle.",
      "votes": null
    },
    {
      "id": "951795",
      "postDate": "07/30/2020 12:19:02",
      "content": "<p>That's great idea! Thanks for your help!</p>",
      "rawMarkdown": "That's great idea! Thanks for your help!",
      "votes": null
    },
    {
      "id": "951798",
      "postDate": "07/30/2020 12:20:40",
      "content": "<p>Thanks! Seems like I have to preprocess BEFORE I create my TFRecord. </p>",
      "rawMarkdown": "Thanks! Seems like I have to preprocess BEFORE I create my TFRecord.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 950992,
      "author_name": "aybatov",
      "author_url": "",
      "post_date": "07/29/2020 19:29:42",
      "content": "<p>Yes, this is a problem, If you want to use TPU and TFRec then you should use only TF operations and we cannot use very convenient CV2 and albumentations.\nBut it is possible to apply these libraries for GPU or preprocess images, save them in TFRec format and use TPU (a little bit hard way)</p>",
      "votes": null,
      "replies": [
        {
          "id": 951798,
          "author_name": "harutot",
          "author_url": "",
          "post_date": "07/30/2020 12:20:40",
          "content": "<p>Thanks! Seems like I have to preprocess BEFORE I create my TFRecord. </p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 951172,
      "author_name": "richardepstein",
      "author_url": "",
      "post_date": "07/30/2020 00:51:28",
      "content": "<p>I've done the preprocess method for \"cut\" and it was relatively easy. I made separate TFRecords with preprocessed \"Cut\" images. Uploaded them as their own dataset. If I want to use them, I just concatenate my regular training TFRecord list with the \"cut\" records and shuffle.</p>",
      "votes": null,
      "replies": [
        {
          "id": 951795,
          "author_name": "harutot",
          "author_url": "",
          "post_date": "07/30/2020 12:19:02",
          "content": "<p>That's great idea! Thanks for your help!</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "950610": "Hi, \n\nI'm now reviewing my image preprocessing steps for aiming better score, but got some problem. \n\nCurrently, I'm reading all the image data from TFRecord and using `tf.io.decode_jpeg` to read all the images. Now, I realized that I can do some extra image augmentation, which requires me to use openCV functions. However, when I simply pass loaded images to `cv2.cvtColor()`, I get this error: \n`TypeError: Expected Ptr",
    "950992": "Yes, this is a problem, If you want to use TPU and TFRec then you should use only TF operations and we cannot use very convenient CV2 and albumentations.\nBut it is possible to apply these libraries for GPU or preprocess images, save them in TFRec format and use TPU (a little bit hard way)",
    "951172": "I've done the preprocess method for \"cut\" and it was relatively easy. I made separate TFRecords with preprocessed \"Cut\" images. Uploaded them as their own dataset. If I want to use them, I just concatenate my regular training TFRecord list with the \"cut\" records and shuffle.",
    "951795": "That's great idea! Thanks for your help!",
    "951798": "Thanks! Seems like I have to preprocess BEFORE I create my TFRecord."
  },
  "source": "meta"
}