{
  "id": 211058,
  "title": " TPU + kaggle dataset: Error executing an HTTP request: HTTP response code 403 with body",
  "url": "/competitions/cassava-leaf-disease-classification/discussion/211058",
  "author_name": "",
  "post_date": "2021-01-13T13:01:03.401525Z",
  "votes": 2,
  "comment_count": 2,
  "views": 0,
  "content": "<p>Hello everybody. I tried to use my own dataset with TPU, but I got an error:</p>\n<blockquote>\n  <p>InvalidArgumentError: Unsuccessful TensorSliceReader constructor: Failed to get matching files on gs://kds-c807dd8fdf3be5c96c8d3def09e6d089b02512e1a5782e252179db6c/nets/cropnet_feature_vector_cassava_disease_V1_1/variables/variables: Permission denied: Error executing an HTTP request: HTTP response code 403 with body '{<br>\n    \"error\": {<br>\n      \"code\": 403,<br>\n      \"message\": \"service-467472385656@cloud-tpu.iam.gserviceaccount.com does not have storage.objects.list access to the Google Cloud Storage bucket.\",<br>\n      \"errors\": [<br>\n        {<br>\n          \"message\": \"service-467472385656@cloud-tpu.iam.gserviceaccount.com does not have storage.objects.list access to the Google Cloud Storage bucket.\",<br>\n          \"domain\": \"global\",<br>\n          \"reason\": \"forbidden\"<br>\n        }<br>\n      ]<br>\n    }<br>\n  }<br>\n  '<br>\n       when reading gs://kds-c807dd8fdf3be5c96c8d3def09e6d089b02512e1a5782e252179db6c/nets/cropnet_feature_vector_cassava_disease_V1_1/variables&gt; </p>\n</blockquote>\n<p>Here is the <a href=\"https://www.kaggle.com/stahh007/tf-hub\" target=\"_blank\">dataset</a><br>\nAnd simple code for test:</p>\n<pre><code>import tensorflow as tf\nfrom kaggle_datasets import KaggleDatasets\nimport tensorflow_hub as hub\nfrom kaggle_secrets import UserSecretsClient\nuser_secrets = UserSecretsClient()\nuser_credential = user_secrets.get_gcloud_credential()\nprint(user_credential)\n\"\"\"{\"client_id\":\"32555940559.apps.googleusercontent.com\",\"client_secret\":\"Zm****2\",\"refresh_token\":\"1//05q*******SLU\",\"type\":\"authorized_user\"}\"\"\"\nuser_secrets.set_tensorflow_credential(user_credential)\nGCS_DS_PATH = KaggleDatasets().get_gcs_path('cassava-leaf-disease-classification')\nGCS_PATH_TO_SAVEDMODEL = KaggleDatasets().get_gcs_path('tf-hub')\n\ntry:\n    tpu = tf.distribute.cluster_resolver.TPUClusterResolver()  \n    print('Running on TPU ', tpu.master())\nexcept ValueError:\n    tpu = None\n\nif tpu:\n    tf.config.experimental_connect_to_cluster(tpu)\n    tf.tpu.experimental.initialize_tpu_system(tpu)\n    strategy = tf.distribute.experimental.TPUStrategy(tpu)\nelse:\n    strategy = tf.distribute.get_strategy() \nprint(\"REPLICAS: \", strategy.num_replicas_in_sync)\n\ntf.keras.backend.clear_session()\nmodels = [GCS_PATH_TO_SAVEDMODEL + '/nets/' + x for x in tf.io.gfile.listdir(GCS_PATH_TO_SAVEDMODEL + '/nets/')]\n\nwith strategy.scope():\n    for model in models:\n        if model.startswith('efficientnet'):\n            continue\n        print(f'Load model {model}')\n        loaded_model = tf.saved_model.load(model)\n        base_model = hub.KerasLayer(loaded_model, trainable=True)\n</code></pre>\n<p>I have a Google cloud account and I've already logged in:</p>\n<blockquote>\n  <p>ubscriber66@cloudshell:~$ gcloud auth list<br>\n      Credentialed Accounts<br>\n  ACTIVE  ACCOUNT</p>\n  <ul>\n  <li><a>subscriber66@gmail.com</a><br>\n  To set the active account, run:<br>\n  $ gcloud config set account <code>ACCOUNT</code>&gt; </li>\n  </ul>\n</blockquote>\n<p>And I linked Google account to kaggle<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F505153%2F52cbf1d04c5005b24066083505a7d3a0%2FTPU%20Kaggle.png?generation=1610542331030073&amp;alt=media\" alt=\"screen\"></p>\n<p>So, what I'm doing wrong and what do I need to do to make it all work?</p>",
  "messages": [
    {
      "id": "1151612",
      "postDate": "01/13/2021 13:01:03",
      "content": "<p>Hello everybody. I tried to use my own dataset with TPU, but I got an error:</p>\n<blockquote>\n  <p>InvalidArgumentError: Unsuccessful TensorSliceReader constructor: Failed to get matching files on gs://kds-c807dd8fdf3be5c96c8d3def09e6d089b02512e1a5782e252179db6c/nets/cropnet_feature_vector_cassava_disease_V1_1/variables/variables: Permission denied: Error executing an HTTP request: HTTP response code 403 with body '{<br>\n    \"error\": {<br>\n      \"code\": 403,<br>\n      \"message\": \"service-467472385656@cloud-tpu.iam.gserviceaccount.com does not have storage.objects.list access to the Google Cloud Storage bucket.\",<br>\n      \"errors\": [<br>\n        {<br>\n          \"message\": \"service-467472385656@cloud-tpu.iam.gserviceaccount.com does not have storage.objects.list access to the Google Cloud Storage bucket.\",<br>\n          \"domain\": \"global\",<br>\n          \"reason\": \"forbidden\"<br>\n        }<br>\n      ]<br>\n    }<br>\n  }<br>\n  '<br>\n       when reading gs://kds-c807dd8fdf3be5c96c8d3def09e6d089b02512e1a5782e252179db6c/nets/cropnet_feature_vector_cassava_disease_V1_1/variables&gt; </p>\n</blockquote>\n<p>Here is the <a href=\"https://www.kaggle.com/stahh007/tf-hub\" target=\"_blank\">dataset</a><br>\nAnd simple code for test:</p>\n<pre><code>import tensorflow as tf\nfrom kaggle_datasets import KaggleDatasets\nimport tensorflow_hub as hub\nfrom kaggle_secrets import UserSecretsClient\nuser_secrets = UserSecretsClient()\nuser_credential = user_secrets.get_gcloud_credential()\nprint(user_credential)\n\"\"\"{\"client_id\":\"32555940559.apps.googleusercontent.com\",\"client_secret\":\"Zm****2\",\"refresh_token\":\"1//05q*******SLU\",\"type\":\"authorized_user\"}\"\"\"\nuser_secrets.set_tensorflow_credential(user_credential)\nGCS_DS_PATH = KaggleDatasets().get_gcs_path('cassava-leaf-disease-classification')\nGCS_PATH_TO_SAVEDMODEL = KaggleDatasets().get_gcs_path('tf-hub')\n\ntry:\n    tpu = tf.distribute.cluster_resolver.TPUClusterResolver()  \n    print('Running on TPU ', tpu.master())\nexcept ValueError:\n    tpu = None\n\nif tpu:\n    tf.config.experimental_connect_to_cluster(tpu)\n    tf.tpu.experimental.initialize_tpu_system(tpu)\n    strategy = tf.distribute.experimental.TPUStrategy(tpu)\nelse:\n    strategy = tf.distribute.get_strategy() \nprint(\"REPLICAS: \", strategy.num_replicas_in_sync)\n\ntf.keras.backend.clear_session()\nmodels = [GCS_PATH_TO_SAVEDMODEL + '/nets/' + x for x in tf.io.gfile.listdir(GCS_PATH_TO_SAVEDMODEL + '/nets/')]\n\nwith strategy.scope():\n    for model in models:\n        if model.startswith('efficientnet'):\n            continue\n        print(f'Load model {model}')\n        loaded_model = tf.saved_model.load(model)\n        base_model = hub.KerasLayer(loaded_model, trainable=True)\n</code></pre>\n<p>I have a Google cloud account and I've already logged in:</p>\n<blockquote>\n  <p>ubscriber66@cloudshell:~$ gcloud auth list<br>\n      Credentialed Accounts<br>\n  ACTIVE  ACCOUNT</p>\n  <ul>\n  <li><a>subscriber66@gmail.com</a><br>\n  To set the active account, run:<br>\n  $ gcloud config set account <code>ACCOUNT</code>&gt; </li>\n  </ul>\n</blockquote>\n<p>And I linked Google account to kaggle<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F505153%2F52cbf1d04c5005b24066083505a7d3a0%2FTPU%20Kaggle.png?generation=1610542331030073&amp;alt=media\" alt=\"screen\"></p>\n<p>So, what I'm doing wrong and what do I need to do to make it all work?</p>",
      "rawMarkdown": "Hello everybody. I tried to use my own dataset with TPU, but I got an error:\n> InvalidArgumentError: Unsuccessful TensorSliceReader constructor: Failed to get matching files on gs://kds-c807dd8fdf3be5c96c8d3def09e6d089b02512e1a5782e252179db6c/nets/cropnet_feature_vector_cassava_disease_V1_1/variables/variables: Permission denied: Error executing an HTTP request: HTTP response code 403 with body '{\n  \"error\": {\n    \"code\": 403,\n    \"message\": \"service-467472385656@cloud-tpu.iam.gserviceaccount.com does not have storage.objects.list access to the Google Cloud Storage bucket.\",\n    \"errors\": [\n      {\n        \"message\": \"service-467472385656@cloud-tpu.iam.gserviceaccount.com does not have storage.objects.list access to the Google Cloud Storage bucket.\",\n        \"domain\": \"global\",\n        \"reason\": \"forbidden\"\n      }\n    ]\n  }\n}\n'\n\t when reading gs://kds-c807dd8fdf3be5c96c8d3def09e6d089b02512e1a5782e252179db6c/nets/cropnet_feature_vector_cassava_disease_V1_1/variables> \n\nHere is the [dataset](https://www.kaggle.com/stahh007/tf-hub)\nAnd simple code for test:\n```\nimport tensorflow as tf\nfrom kaggle_datasets import KaggleDatasets\nimport tensorflow_hub as hub\nfrom kaggle_secrets import UserSecretsClient\nuser_secrets = UserSecretsClient()\nuser_credential = user_secrets.get_gcloud_credential()\nprint(user_credential)\n\"\"\"{\"client_id\":\"32555940559.apps.googleusercontent.com\",\"client_secret\":\"Zm****2\",\"refresh_token\":\"1//05q*******SLU\",\"type\":\"authorized_user\"}\"\"\"\nuser_secrets.set_tensorflow_credential(user_credential)\nGCS_DS_PATH = KaggleDatasets().get_gcs_path('cassava-leaf-disease-classification')\nGCS_PATH_TO_SAVEDMODEL = KaggleDatasets().get_gcs_path('tf-hub')\n\ntry:\n    tpu = tf.distribute.cluster_resolver.TPUClusterResolver()  \n    print('Running on TPU ', tpu.master())\nexcept ValueError:\n    tpu = None\n\nif tpu:\n    tf.config.experimental_connect_to_cluster(tpu)\n    tf.tpu.experimental.initialize_tpu_system(tpu)\n    strategy = tf.distribute.experimental.TPUStrategy(tpu)\nelse:\n    strategy = tf.distribute.get_strategy() \nprint(\"REPLICAS: \", strategy.num_replicas_in_sync)\n\ntf.keras.backend.clear_session()\nmodels = [GCS_PATH_TO_SAVEDMODEL + '/nets/' + x for x in tf.io.gfile.listdir(GCS_PATH_TO_SAVEDMODEL + '/nets/')]\n\nwith strategy.scope():\n    for model in models:\n        if model.startswith('efficientnet'):\n            continue\n        print(f'Load model {model}')\n        loaded_model = tf.saved_model.load(model)\n        base_model = hub.KerasLayer(loaded_model, trainable=True)\n```\n\nI have a Google cloud account and I've already logged in:\n> ubscriber66@cloudshell:~$ gcloud auth list\n    Credentialed Accounts\nACTIVE  ACCOUNT\n*       subscriber66@gmail.com\nTo set the active account, run:\n    $ gcloud config set account `ACCOUNT`> \n\nAnd I linked Google account to kaggle\n![screen](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F505153%2F52cbf1d04c5005b24066083505a7d3a0%2FTPU%20Kaggle.png?generation=1610542331030073&alt=media)\n\nSo, what I'm doing wrong and what do I need to do to make it all work?",
      "votes": null
    },
    {
      "id": "1153493",
      "postDate": "01/14/2021 23:58:11",
      "content": "<p>Try to initialize the TPU before the user secrets. Just had a similar issue working with a private dataset and this worked for me.</p>",
      "rawMarkdown": "Try to initialize the TPU before the user secrets. Just had a similar issue working with a private dataset and this worked for me.",
      "votes": null
    },
    {
      "id": "1154065",
      "postDate": "01/15/2021 11:30:28",
      "content": "<p><a href=\"https://www.kaggle.com/morodertobias\" target=\"_blank\">@morodertobias</a> many thanks! It works. Later I will share a notebook with full code.</p>",
      "rawMarkdown": "morodertobias many thanks! It works. Later I will share a notebook with full code.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1153493,
      "author_name": "morodertobias",
      "author_url": "",
      "post_date": "01/14/2021 23:58:11",
      "content": "<p>Try to initialize the TPU before the user secrets. Just had a similar issue working with a private dataset and this worked for me.</p>",
      "votes": null,
      "replies": [
        {
          "id": 1154065,
          "author_name": "stahh007",
          "author_url": "",
          "post_date": "01/15/2021 11:30:28",
          "content": "<p><a href=\"https://www.kaggle.com/morodertobias\" target=\"_blank\">@morodertobias</a> many thanks! It works. Later I will share a notebook with full code.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1151612": "Hello everybody. I tried to use my own dataset with TPU, but I got an error:\n> InvalidArgumentError: Unsuccessful TensorSliceReader constructor: Failed to get matching files on gs://kds-c807dd8fdf3be5c96c8d3def09e6d089b02512e1a5782e252179db6c/nets/cropnet_feature_vector_cassava_disease_V1_1/variables/variables: Permission denied: Error executing an HTTP request: HTTP response code 403 with body '{\n  \"error\": {\n    \"code\": 403,\n    \"message\": \"service-467472385656@cloud-tpu.iam.gserviceaccount.com does not have storage.objects.list access to the Google Cloud Storage bucket.\",\n    \"errors\": [\n      {\n        \"message\": \"service-467472385656@cloud-tpu.iam.gserviceaccount.com does not have storage.objects.list access to the Google Cloud Storage bucket.\",\n        \"domain\": \"global\",\n        \"reason\": \"forbidden\"\n      }\n    ]\n  }\n}\n'\n\t when reading gs://kds-c807dd8fdf3be5c96c8d3def09e6d089b02512e1a5782e252179db6c/nets/cropnet_feature_vector_cassava_disease_V1_1/variables> \n\nHere is the [dataset](https://www.kaggle.com/stahh007/tf-hub)\nAnd simple code for test:\n```\nimport tensorflow as tf\nfrom kaggle_datasets import KaggleDatasets\nimport tensorflow_hub as hub\nfrom kaggle_secrets import UserSecretsClient\nuser_secrets = UserSecretsClient()\nuser_credential = user_secrets.get_gcloud_credential()\nprint(user_credential)\n\"\"\"{\"client_id\":\"32555940559.apps.googleusercontent.com\",\"client_secret\":\"Zm****2\",\"refresh_token\":\"1//05q*******SLU\",\"type\":\"authorized_user\"}\"\"\"\nuser_secrets.set_tensorflow_credential(user_credential)\nGCS_DS_PATH = KaggleDatasets().get_gcs_path('cassava-leaf-disease-classification')\nGCS_PATH_TO_SAVEDMODEL = KaggleDatasets().get_gcs_path('tf-hub')\n\ntry:\n    tpu = tf.distribute.cluster_resolver.TPUClusterResolver()  \n    print('Running on TPU ', tpu.master())\nexcept ValueError:\n    tpu = None\n\nif tpu:\n    tf.config.experimental_connect_to_cluster(tpu)\n    tf.tpu.experimental.initialize_tpu_system(tpu)\n    strategy = tf.distribute.experimental.TPUStrategy(tpu)\nelse:\n    strategy = tf.distribute.get_strategy() \nprint(\"REPLICAS: \", strategy.num_replicas_in_sync)\n\ntf.keras.backend.clear_session()\nmodels = [GCS_PATH_TO_SAVEDMODEL + '/nets/' + x for x in tf.io.gfile.listdir(GCS_PATH_TO_SAVEDMODEL + '/nets/')]\n\nwith strategy.scope():\n    for model in models:\n        if model.startswith('efficientnet'):\n            continue\n        print(f'Load model {model}')\n        loaded_model = tf.saved_model.load(model)\n        base_model = hub.KerasLayer(loaded_model, trainable=True)\n```\n\nI have a Google cloud account and I've already logged in:\n> ubscriber66@cloudshell:~$ gcloud auth list\n    Credentialed Accounts\nACTIVE  ACCOUNT\n*       subscriber66@gmail.com\nTo set the active account, run:\n    $ gcloud config set account `ACCOUNT`> \n\nAnd I linked Google account to kaggle\n![screen](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F505153%2F52cbf1d04c5005b24066083505a7d3a0%2FTPU%20Kaggle.png?generation=1610542331030073&alt=media)\n\nSo, what I'm doing wrong and what do I need to do to make it all work?",
    "1153493": "Try to initialize the TPU before the user secrets. Just had a similar issue working with a private dataset and this worked for me.",
    "1154065": "morodertobias many thanks! It works. Later I will share a notebook with full code."
  },
  "source": "meta"
}