{
  "id": 176951,
  "title": "Best way to use cv2.imread for imeges from Google Cloud Storage?",
  "url": "/competitions/landmark-recognition-2020/discussion/176951",
  "author_name": "",
  "post_date": "2020-08-24T08:03:06.340693800Z",
  "votes": 3,
  "comment_count": 2,
  "views": 0,
  "content": "<p>Hi to all! I wont to use tpu to traine my model in landmark-recognition-2020 competition, and<br>\nI'm trying to do something like this:<br>\nPATH=KaggleDatasets().get_gcs_path('landmark-recognition-2020')<br>\nTRAIN_ROOT_PATH = PATH+'/train/d/3/2/d3208a46b5c41259.jpg'<br>\nimg = cv2.imread(path, cv2.IMREAD_COLOR)<br>\nBut cv2.imread can't just read the file from Google Cloud Storage.<br>\nHow do I better read the image to process it with cv2?<br>\nThanks!</p>",
  "messages": [
    {
      "id": "983348",
      "postDate": "08/24/2020 08:03:06",
      "content": "<p>Hi to all! I wont to use tpu to traine my model in landmark-recognition-2020 competition, and<br>\nI'm trying to do something like this:<br>\nPATH=KaggleDatasets().get_gcs_path('landmark-recognition-2020')<br>\nTRAIN_ROOT_PATH = PATH+'/train/d/3/2/d3208a46b5c41259.jpg'<br>\nimg = cv2.imread(path, cv2.IMREAD_COLOR)<br>\nBut cv2.imread can't just read the file from Google Cloud Storage.<br>\nHow do I better read the image to process it with cv2?<br>\nThanks!</p>",
      "rawMarkdown": "Hi to all! I wont to use tpu to traine my model in landmark-recognition-2020 competition, and\nI'm trying to do something like this:\nPATH=KaggleDatasets().get_gcs_path('landmark-recognition-2020')\nTRAIN_ROOT_PATH = PATH+'/train/d/3/2/d3208a46b5c41259.jpg'\nimg = cv2.imread(path, cv2.IMREAD_COLOR)\nBut cv2.imread can't just read the file from Google Cloud Storage.\nHow do I better read the image to process it with cv2?\nThanks!",
      "votes": null
    },
    {
      "id": "983418",
      "postDate": "08/24/2020 09:42:13",
      "content": "<p>download it first and then read it</p>",
      "rawMarkdown": "download it first and then read it",
      "votes": null
    },
    {
      "id": "983819",
      "postDate": "08/24/2020 16:02:31",
      "content": "<p>I found the way to do this. <br>\nYou need to use tf.io.read_file, something like this:<br>\nPATH=KaggleDatasets().get_gcs_path('landmark-recognition-2020')<br>\nTRAIN_ROOT_PATH = PATH+'/train/d/3/2/d3208a46b5c41259.jpg'<br>\nimg = tf.io.read_file(TRAIN_ROOT_PATH )<br>\nimg = tf.image.decode_jpeg(img,channels=3)<br>\nimg = tf.image.resize(img, [im_size, im_size])<br>\nimg =tf.cast(img, tf.float32)<br>\nimg.set_shape([im_size, im_size, 3])</p>",
      "rawMarkdown": "I found the way to do this. \nYou need to use tf.io.read_file, something like this:\nPATH=KaggleDatasets().get_gcs_path('landmark-recognition-2020')\nTRAIN_ROOT_PATH = PATH+'/train/d/3/2/d3208a46b5c41259.jpg'\nimg = tf.io.read_file(TRAIN_ROOT_PATH )\nimg = tf.image.decode_jpeg(img,channels=3)\nimg = tf.image.resize(img, [im_size, im_size])\nimg =tf.cast(img, tf.float32)\nimg.set_shape([im_size, im_size, 3])",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 983418,
      "author_name": "philippsinger",
      "author_url": "",
      "post_date": "08/24/2020 09:42:13",
      "content": "<p>download it first and then read it</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 983819,
      "author_name": "aikhmelnytskyy",
      "author_url": "",
      "post_date": "08/24/2020 16:02:31",
      "content": "<p>I found the way to do this. <br>\nYou need to use tf.io.read_file, something like this:<br>\nPATH=KaggleDatasets().get_gcs_path('landmark-recognition-2020')<br>\nTRAIN_ROOT_PATH = PATH+'/train/d/3/2/d3208a46b5c41259.jpg'<br>\nimg = tf.io.read_file(TRAIN_ROOT_PATH )<br>\nimg = tf.image.decode_jpeg(img,channels=3)<br>\nimg = tf.image.resize(img, [im_size, im_size])<br>\nimg =tf.cast(img, tf.float32)<br>\nimg.set_shape([im_size, im_size, 3])</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "983348": "Hi to all! I wont to use tpu to traine my model in landmark-recognition-2020 competition, and\nI'm trying to do something like this:\nPATH=KaggleDatasets().get_gcs_path('landmark-recognition-2020')\nTRAIN_ROOT_PATH = PATH+'/train/d/3/2/d3208a46b5c41259.jpg'\nimg = cv2.imread(path, cv2.IMREAD_COLOR)\nBut cv2.imread can't just read the file from Google Cloud Storage.\nHow do I better read the image to process it with cv2?\nThanks!",
    "983418": "download it first and then read it",
    "983819": "I found the way to do this. \nYou need to use tf.io.read_file, something like this:\nPATH=KaggleDatasets().get_gcs_path('landmark-recognition-2020')\nTRAIN_ROOT_PATH = PATH+'/train/d/3/2/d3208a46b5c41259.jpg'\nimg = tf.io.read_file(TRAIN_ROOT_PATH )\nimg = tf.image.decode_jpeg(img,channels=3)\nimg = tf.image.resize(img, [im_size, im_size])\nimg =tf.cast(img, tf.float32)\nimg.set_shape([im_size, im_size, 3])"
  },
  "source": "meta"
}