|
13 | 13 | "cell_type": "code", |
14 | 14 | "execution_count": null, |
15 | 15 | "metadata": { |
| 16 | + "cellView": "form", |
16 | 17 | "id": "_fEE8rM9BUfS" |
17 | 18 | }, |
18 | 19 | "outputs": [], |
|
38 | 39 | "source": [ |
39 | 40 | "# Fine-tune PaliGemma with JAX and Flax\n", |
40 | 41 | "\n", |
41 | | - "\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n", |
42 | | - "\u003ctd\u003e\n", |
43 | | - "\u003ca target=\"_blank\" href=\"https://ai.google.dev/gemma/docs/paligemma/fine-tuning-paligemma\"\u003e\u003cimg src=\"https://ai.google.dev/static/site-assets/images/docs/notebook-site-button.png\" height=\"32\" width=\"32\" /\u003eView on ai.google.dev\u003c/a\u003e\n", |
44 | | - "\u003c/td\u003e\n", |
45 | | - "\u003ctd\u003e\n", |
46 | | - "\u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/google/generative-ai-docs/blob/main/site/en/gemma/docs/paligemma/fine-tuning-paligemma.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003eRun in Google Colab\u003c/a\u003e\n", |
47 | | - "\u003c/td\u003e\n", |
48 | | - "\u003ctd\u003e\n", |
49 | | - "\u003ca target=\"_blank\" href=\"https://github.com/google/generative-ai-docs/blob/main/site/en/gemma/docs/paligemma/fine-tuning-paligemma.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003eView source on GitHub\u003c/a\u003e\n", |
50 | | - "\u003c/td\u003e\n", |
51 | | - "\u003c/table\u003e\n" |
| 42 | + "<table class=\"tfo-notebook-buttons\" align=\"left\">\n", |
| 43 | + "<td>\n", |
| 44 | + "<a target=\"_blank\" href=\"https://ai.google.dev/gemma/docs/paligemma/fine-tuning-paligemma\"><img src=\"https://ai.google.dev/static/site-assets/images/docs/notebook-site-button.png\" height=\"32\" width=\"32\" />View on ai.google.dev</a>\n", |
| 45 | + "</td>\n", |
| 46 | + "<td>\n", |
| 47 | + "<a target=\"_blank\" href=\"https://colab.research.google.com/github/google/generative-ai-docs/blob/main/site/en/gemma/docs/paligemma/fine-tuning-paligemma.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n", |
| 48 | + "</td>\n", |
| 49 | + "<td>\n", |
| 50 | + "<a target=\"_blank\" href=\"https://github.com/google/generative-ai-docs/blob/main/site/en/gemma/docs/paligemma/fine-tuning-paligemma.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n", |
| 51 | + "</td>\n", |
| 52 | + "</table>\n" |
52 | 53 | ] |
53 | 54 | }, |
54 | 55 | { |
|
117 | 118 | "\n", |
118 | 119 | "To generate a Kaggle API key, open your [**Settings** page in Kaggle](https://www.kaggle.com/settings) and click **Create New Token**. This triggers the download of a `kaggle.json` file containing your API credentials.\n", |
119 | 120 | "\n", |
120 | | - "Then, in Colab, select **Secrets** (🔑) in the left pane and add your Kaggle username and Kaggle API key. Store your username under the name `KAGGLE_USERNAME` and your API key under the name `KAGGLE_KEY`.\n", |
121 | | - "\n" |
| 121 | + "Then, in Colab, select **Secrets** (🔑) in the left pane and add your Kaggle username and Kaggle API key. Store your username under the name `KAGGLE_USERNAME` and your API key under the name `KAGGLE_KEY`.\n" |
122 | 122 | ] |
123 | 123 | }, |
124 | 124 | { |
|
482 | 482 | "\n", |
483 | 483 | " image = tf.constant(image)\n", |
484 | 484 | " image = tf.image.resize(image, (size, size), method='bilinear', antialias=True)\n", |
485 | | - " return image.numpy() / 127.5 - 1.0 # [0, 255]-\u003e[-1,1]\n", |
| 485 | + " return image.numpy() / 127.5 - 1.0 # [0, 255]->[-1,1]\n", |
486 | 486 | "\n", |
487 | 487 | "def preprocess_tokens(prefix, suffix=None, seqlen=None):\n", |
488 | 488 | " # Model has been trained to handle tokenized text composed of a prefix with\n", |
|
622 | 622 | " return f\"data:image/jpeg;base64,{image_b64}\"\n", |
623 | 623 | "\n", |
624 | 624 | "def render_example(image, caption):\n", |
625 | | - " image = ((image + 1)/2 * 255).astype(np.uint8) # [-1,1] -\u003e [0, 255]\n", |
| 625 | + " image = ((image + 1)/2 * 255).astype(np.uint8) # [-1,1] -> [0, 255]\n", |
626 | 626 | " return f\"\"\"\n", |
627 | | - " \u003cdiv style=\"display: inline-flex; align-items: center; justify-content: center;\"\u003e\n", |
628 | | - " \u003cimg style=\"width:128px; height:128px;\" src=\"{render_inline(image, resize=(64,64))}\" /\u003e\n", |
629 | | - " \u003cp style=\"width:256px; margin:10px; font-size:small;\"\u003e{html.escape(caption)}\u003c/p\u003e\n", |
630 | | - " \u003c/div\u003e\n", |
| 627 | + " <div style=\"display: inline-flex; align-items: center; justify-content: center;\">\n", |
| 628 | + " <img style=\"width:128px; height:128px;\" src=\"{render_inline(image, resize=(64,64))}\" />\n", |
| 629 | + " <p style=\"width:256px; margin:10px; font-size:small;\">{html.escape(caption)}</p>\n", |
| 630 | + " </div>\n", |
631 | 631 | " \"\"\"\n", |
632 | 632 | "\n", |
633 | 633 | "html_out = \"\"\n", |
|
744 | 744 | " # Append to html output.\n", |
745 | 745 | " for example, response in zip(examples, responses):\n", |
746 | 746 | " outputs.append((example[\"image\"], response))\n", |
747 | | - " if num_examples and len(outputs) \u003e= num_examples:\n", |
| 747 | + " if num_examples and len(outputs) >= num_examples:\n", |
748 | 748 | " return outputs" |
749 | 749 | ] |
750 | 750 | }, |
|
852 | 852 | ], |
853 | 853 | "metadata": { |
854 | 854 | "colab": { |
855 | | - "gpuType": "T4", |
856 | | - "last_runtime": { |
857 | | - "build_target": "//learning/grp/tools/ml_python:ml_notebook", |
858 | | - "kind": "private" |
859 | | - }, |
860 | | - "private_outputs": true, |
861 | | - "provenance": [ |
862 | | - { |
863 | | - "file_id": "17AiK8gRY7oiquQGkBH0d08PFQo3Kyx1I", |
864 | | - "timestamp": 1715287187925 |
865 | | - }, |
866 | | - { |
867 | | - "file_id": "1qZlJfPyfKRrNcz2shxQ93HnnE5Ge1LLn", |
868 | | - "timestamp": 1715019972450 |
869 | | - }, |
870 | | - { |
871 | | - "file_id": "1JFnlD2kSiTNexdPw_NYRtuW6uuSTI0kD", |
872 | | - "timestamp": 1714585741026 |
873 | | - } |
874 | | - ], |
| 855 | + "name": "fine-tuning-paligemma.ipynb", |
875 | 856 | "toc_visible": true |
876 | 857 | }, |
877 | 858 | "kernelspec": { |
878 | 859 | "display_name": "Python 3", |
879 | 860 | "name": "python3" |
880 | | - }, |
881 | | - "language_info": { |
882 | | - "name": "python" |
883 | 861 | } |
884 | 862 | }, |
885 | 863 | "nbformat": 4, |
|
0 commit comments