Skip to content

Commit

Permalink
Load models from Kaggle Models' GCS buckets as these should be prefer…
Browse files Browse the repository at this point in the history
…red after tfhub.dev has been migrated to Kaggle Models in November 2023. (#1980)
  • Loading branch information
WGierke authored Oct 24, 2024
1 parent 6975926 commit b3dfa08
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
2 changes: 1 addition & 1 deletion examples/vision/cait.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ def get_config(
## Load a pretrained model
"""

model_gcs_path = "gs://tfhub-modules/sayakpaul/cait_xxs24_224/1/uncompressed"
model_gcs_path = "gs://kaggle-tfhub-models-uncompressed/tfhub-modules/sayakpaul/cait_xxs24_224/1/uncompressed"
pretrained_model = keras.Sequential(
[keras.layers.TFSMLayer(model_gcs_path, call_endpoint="serving_default")]
)
Expand Down
36 changes: 13 additions & 23 deletions examples/vision/ipynb/cait.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"Touvron et al. Depth scaling, i.e. increasing the model depth for obtaining better\n",
"performance and generalization has been quite successful for convolutional neural\n",
"networks ([Tan et al.](https://arxiv.org/abs/1905.11946),\n",
"[Doll\u00e1r et al.](https://arxiv.org/abs/2103.06877), for example). But applying\n",
"[Dollár et al.](https://arxiv.org/abs/2103.06877), for example). But applying\n",
"the same model scaling principles to\n",
"Vision Transformers ([Dosovitskiy et al.](https://arxiv.org/abs/2010.11929)) doesn't\n",
"translate equally well -- their performance gets saturated quickly with depth scaling.\n",
Expand Down Expand Up @@ -154,8 +154,7 @@
" )\n",
"\n",
" def call(self, x, training=False):\n",
" return x * self.gamma\n",
""
" return x * self.gamma\n"
]
},
{
Expand Down Expand Up @@ -203,8 +202,7 @@
" )\n",
" random_tensor = ops.floor(random_tensor)\n",
" return (x / keep_prob) * random_tensor\n",
" return x\n",
""
" return x\n"
]
},
{
Expand Down Expand Up @@ -326,8 +324,7 @@
" x_cls = self.proj(x_cls)\n",
" x_cls = self.proj_drop(x_cls, training=training)\n",
"\n",
" return x_cls, attn\n",
""
" return x_cls, attn\n"
]
},
{
Expand Down Expand Up @@ -430,8 +427,7 @@
" x = self.proj(x)\n",
" x = self.proj_drop(x, training=training)\n",
"\n",
" return x, attn\n",
""
" return x, attn\n"
]
},
{
Expand Down Expand Up @@ -464,8 +460,7 @@
" bias_initializer=keras.initializers.RandomNormal(stddev=1e-6),\n",
" )(x)\n",
" x = layers.Dropout(dropout_rate)(x)\n",
" return x\n",
""
" return x\n"
]
},
{
Expand Down Expand Up @@ -606,8 +601,7 @@
" x4 = StochasticDepth(sd_prob)(x4) if sd_prob else x4\n",
" outputs = layers.Add()([x2, x4])\n",
"\n",
" return keras.Model(encoded_patches, [outputs, attn_scores], name=name)\n",
""
" return keras.Model(encoded_patches, [outputs, attn_scores], name=name)\n"
]
},
{
Expand Down Expand Up @@ -798,8 +792,7 @@
" (x, sa_ffn_attn, ca_ffn_attn)\n",
" if self.pre_logits\n",
" else (self.head(x), sa_ffn_attn, ca_ffn_attn)\n",
" )\n",
""
" )\n"
]
},
{
Expand Down Expand Up @@ -889,8 +882,7 @@
" config[\"pre_logits\"] = pre_logits\n",
" config[\"num_classes\"] = num_classes\n",
"\n",
" return config\n",
""
" return config\n"
]
},
{
Expand Down Expand Up @@ -974,7 +966,7 @@
},
"outputs": [],
"source": [
"model_gcs_path = \"gs://tfhub-modules/sayakpaul/cait_xxs24_224/1/uncompressed\"\n",
"model_gcs_path = \"gs://kaggle-tfhub-models-uncompressed/tfhub-modules/sayakpaul/cait_xxs24_224/1/uncompressed\"\n",
"pretrained_model = keras.Sequential(\n",
" [keras.layers.TFSMLayer(model_gcs_path, call_endpoint=\"serving_default\")]\n",
")"
Expand Down Expand Up @@ -1024,8 +1016,7 @@
" image_bytes = io.BytesIO(urlopen(url).read())\n",
" image = PIL.Image.open(image_bytes)\n",
" preprocessed_image = preprocess_image(image)\n",
" return image, preprocessed_image\n",
""
" return image, preprocessed_image\n"
]
},
{
Expand Down Expand Up @@ -1225,8 +1216,7 @@
" interpolation=\"bicubic\",\n",
" )\n",
"\n",
" return attentions\n",
""
" return attentions\n"
]
},
{
Expand Down Expand Up @@ -1382,4 +1372,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
2 changes: 1 addition & 1 deletion examples/vision/md/cait.md
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ as well as


```python
model_gcs_path = "gs://tfhub-modules/sayakpaul/cait_xxs24_224/1/uncompressed"
model_gcs_path = "gs://kaggle-tfhub-models-uncompressed/tfhub-modules/sayakpaul/cait_xxs24_224/1/uncompressed"
pretrained_model = keras.Sequential(
[keras.layers.TFSMLayer(model_gcs_path, call_endpoint="serving_default")]
)
Expand Down

0 comments on commit b3dfa08

Please sign in to comment.