-
-
Save ia35/cfe64164b85cf617a4f4fc373d9f3e28 to your computer and use it in GitHub Desktop.
Tf dataset.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "Tf dataset.ipynb", | |
"version": "0.3.2", | |
"provenance": [], | |
"collapsed_sections": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"accelerator": "GPU" | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/ia35/cfe64164b85cf617a4f4fc373d9f3e28/tf-dataset.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "lW8d0ezZU799", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 114 | |
}, | |
"outputId": "a8f97437-9409-4b10-c852-0868b765f6bc" | |
}, | |
"source": [ | |
"!pip install -q tensorflow==2.0.0-alpha0\n", | |
"import tensorflow as tf" | |
], | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"\u001b[K |████████████████████████████████| 79.9MB 1.3MB/s \n", | |
"\u001b[K |████████████████████████████████| 3.0MB 42.7MB/s \n", | |
"\u001b[K |████████████████████████████████| 419kB 44.3MB/s \n", | |
"\u001b[K |████████████████████████████████| 61kB 21.1MB/s \n", | |
"\u001b[?25h" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "RcmhUWFsc005", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"Exemple fortement inspiré de la doc ce [TensorFlow](https://www.tensorflow.org/datasets/overview) " | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "8TfDW6rXbrsX", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"Dorénavant, les exemples utiliseront TensorFlow 2.0" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "S7CY4z_Sb0B8", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"On importe TensorFlow DataSet Library. \n", | |
"\n", | |
"Il n'est pas utile de l'installer si on utilise tf > 2.0" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "ZiofaIeXVRmB", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"import tensorflow_datasets as tfds" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "okrFlDGUVfnQ", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 287 | |
}, | |
"outputId": "6906becd-b201-4516-ba66-87eead0e03b8" | |
}, | |
"source": [ | |
"dataset = tfds.load(name=\"mnist\")" | |
], | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"\u001b[1mDownloading and preparing dataset mnist (11.06 MiB) to /root/tensorflow_datasets/mnist/1.0.0...\u001b[0m\n" | |
], | |
"name": "stdout" | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "23b44e74dd204410aae70b11abcaf3c3", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=1, bar_style='info', description='Dl Completed...', max=1, style=ProgressStyl…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "894c3e8b70184d89bca8439f7a6f5406", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=1, bar_style='info', description='Dl Size...', max=1, style=ProgressStyle(des…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "814056b46aaa48619ee19b59a67dc16b", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=1, bar_style='info', description='Extraction completed...', max=1, style=Prog…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"\n", | |
"\n", | |
"\n" | |
], | |
"name": "stdout" | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "2d7775b5e277444bae1419b88e79f95c", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=1, bar_style='info', max=1), HTML(value='')))" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "stream", | |
"text": [ | |
"\r" | |
], | |
"name": "stdout" | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "bd8e74682e1a4ad38f1f2d5dd9b218e7", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=0, description='Shuffling...', max=10, style=ProgressStyle(description_width=…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "stream", | |
"text": [ | |
"WARNING: Logging before flag parsing goes to stderr.\n", | |
"W0521 07:41:38.557350 140118336792448 deprecation.py:323] From /usr/local/lib/python3.6/dist-packages/tensorflow_datasets/core/file_format_adapter.py:247: tf_record_iterator (from tensorflow.python.lib.io.tf_record) is deprecated and will be removed in a future version.\n", | |
"Instructions for updating:\n", | |
"Use eager execution and: \n", | |
"`tf.data.TFRecordDataset(path)`\n" | |
], | |
"name": "stderr" | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "b4894c8a4e4f452389ef29b5e69ae9e5", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=1, bar_style='info', description='Reading...', max=1, style=ProgressStyle(des…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "4fdd49510ffe485f9fedec623e9a50af", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=0, description='Writing...', max=6000, style=ProgressStyle(description_width=…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "ebb7b559b2604f76af7d6a5f7bcefa36", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=1, bar_style='info', description='Reading...', max=1, style=ProgressStyle(des…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "5257fd1a62004dfd8c489ed91cdd7343", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=0, description='Writing...', max=6000, style=ProgressStyle(description_width=…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "7e4b7eba85ce4aff8828f108aee9ccef", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=1, bar_style='info', description='Reading...', max=1, style=ProgressStyle(des…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "a6f9c21bdc3c47c7a1b61765e4bf22f8", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=0, description='Writing...', max=6000, style=ProgressStyle(description_width=…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "d3f603a26b654094a1510aa615ed0011", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=1, bar_style='info', description='Reading...', max=1, style=ProgressStyle(des…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "b3b18a99c05a4e999674c9cd922e4532", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=0, description='Writing...', max=6000, style=ProgressStyle(description_width=…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "a2d30004330b41ea80ca4fafee45a1db", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=1, bar_style='info', description='Reading...', max=1, style=ProgressStyle(des…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "e94ea2f4dd5f44949653b8dabf2a99e1", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=0, description='Writing...', max=6000, style=ProgressStyle(description_width=…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "d696cdb55128456cb63b1d2d11899e40", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=1, bar_style='info', description='Reading...', max=1, style=ProgressStyle(des…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "d7d748191ef84feba0eb63bfb4a65069", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=0, description='Writing...', max=6000, style=ProgressStyle(description_width=…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "4f2921db169442a6905618f3ba7494d0", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=1, bar_style='info', description='Reading...', max=1, style=ProgressStyle(des…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "98e16150b70544ce90402e60948e7f8e", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=0, description='Writing...', max=6000, style=ProgressStyle(description_width=…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "aecbe7f3399d4b7eb4fa563c8c0b682a", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=1, bar_style='info', description='Reading...', max=1, style=ProgressStyle(des…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "96201e292e274beeb490707f05563787", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=0, description='Writing...', max=6000, style=ProgressStyle(description_width=…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "c5a9b45ca2f549e8acec213613ffdc64", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=1, bar_style='info', description='Reading...', max=1, style=ProgressStyle(des…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "8cfc000dd41d4823bbc0c803081b5c54", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=0, description='Writing...', max=6000, style=ProgressStyle(description_width=…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "c26ceeed8ee44100b4faacaa98f66f5c", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=1, bar_style='info', description='Reading...', max=1, style=ProgressStyle(des…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "f66358fc3dda495a9772648a72bb0fcd", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=0, description='Writing...', max=6000, style=ProgressStyle(description_width=…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "stream", | |
"text": [ | |
"\r" | |
], | |
"name": "stdout" | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "53b2e4cee5804d1ba69482f2cb07ad07", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=1, bar_style='info', max=1), HTML(value='')))" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "stream", | |
"text": [ | |
"\r" | |
], | |
"name": "stdout" | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "c423853bae944f9abb4f6e30834f0fba", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=0, description='Shuffling...', max=1, style=ProgressStyle(description_width='…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "19cfea481e814edabebf01979204bb2b", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=1, bar_style='info', description='Reading...', max=1, style=ProgressStyle(des…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "ef66a7467ada45b8a3e0e84612aab50d", | |
"version_minor": 0, | |
"version_major": 2 | |
}, | |
"text/plain": [ | |
"HBox(children=(IntProgress(value=0, description='Writing...', max=10000, style=ProgressStyle(description_width…" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "stream", | |
"text": [ | |
"\r\u001b[1mDataset mnist downloaded and prepared to /root/tensorflow_datasets/mnist/1.0.0. Subsequent calls will reuse this data.\u001b[0m\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "W7yNdIaBVlWx", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"dataset??" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "RvsrHljlWCOO", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
}, | |
"outputId": "1e9572d5-6f6d-4e54-d074-af6e5123ffd6" | |
}, | |
"source": [ | |
"dataset[\"test\"]" | |
], | |
"execution_count": 34, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"<_OptionsDataset shapes: {image: (28, 28, 1), label: ()}, types: {image: tf.uint8, label: tf.int64}>" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 34 | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "f09BYfkFcEYj", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"La liste des jeux de données disponibles :" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "8d6W0wTSXxng", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 1190 | |
}, | |
"outputId": "2b836c4f-0d29-4eb2-8872-b60bae78a57c" | |
}, | |
"source": [ | |
"tfds.list_builders()" | |
], | |
"execution_count": 15, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"['abstract_reasoning',\n", | |
" 'bair_robot_pushing_small',\n", | |
" 'caltech101',\n", | |
" 'cats_vs_dogs',\n", | |
" 'celeb_a',\n", | |
" 'celeb_a_hq',\n", | |
" 'chexpert',\n", | |
" 'cifar10',\n", | |
" 'cifar100',\n", | |
" 'cifar10_corrupted',\n", | |
" 'clevr',\n", | |
" 'cnn_dailymail',\n", | |
" 'coco2014',\n", | |
" 'colorectal_histology',\n", | |
" 'colorectal_histology_large',\n", | |
" 'cycle_gan',\n", | |
" 'diabetic_retinopathy_detection',\n", | |
" 'dsprites',\n", | |
" 'dtd',\n", | |
" 'dummy_dataset_shared_generator',\n", | |
" 'dummy_mnist',\n", | |
" 'emnist',\n", | |
" 'fashion_mnist',\n", | |
" 'flores',\n", | |
" 'glue',\n", | |
" 'groove',\n", | |
" 'higgs',\n", | |
" 'horses_or_humans',\n", | |
" 'image_label_folder',\n", | |
" 'imagenet2012',\n", | |
" 'imagenet2012_corrupted',\n", | |
" 'imdb_reviews',\n", | |
" 'iris',\n", | |
" 'kmnist',\n", | |
" 'lm1b',\n", | |
" 'lsun',\n", | |
" 'mnist',\n", | |
" 'moving_mnist',\n", | |
" 'multi_nli',\n", | |
" 'nsynth',\n", | |
" 'omniglot',\n", | |
" 'open_images_v4',\n", | |
" 'oxford_flowers102',\n", | |
" 'oxford_iiit_pet',\n", | |
" 'para_crawl',\n", | |
" 'quickdraw_bitmap',\n", | |
" 'rock_paper_scissors',\n", | |
" 'shapes3d',\n", | |
" 'smallnorb',\n", | |
" 'squad',\n", | |
" 'starcraft_video',\n", | |
" 'sun397',\n", | |
" 'svhn_cropped',\n", | |
" 'ted_hrlr_translate',\n", | |
" 'ted_multi_translate',\n", | |
" 'tf_flowers',\n", | |
" 'titanic',\n", | |
" 'ucf101',\n", | |
" 'voc2007',\n", | |
" 'wikipedia',\n", | |
" 'wmt14_translate',\n", | |
" 'wmt15_translate',\n", | |
" 'wmt16_translate',\n", | |
" 'wmt17_translate',\n", | |
" 'wmt18_translate',\n", | |
" 'wmt19_translate',\n", | |
" 'wmt_t2t_translate',\n", | |
" 'wmt_translate',\n", | |
" 'xnli']" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 15 | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "JauGJQiZcP51", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"On a vu précédemment que le dataset est un dictionary : 'test', 'train'" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "jkYEwG1AYRFq", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"mnist_train, mnist_test = dataset[\"train\"], dataset[\"test\"]" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "1UHGjix3hU4X", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
}, | |
"outputId": "5657165c-27e2-4a1e-b237-58246b161c56" | |
}, | |
"source": [ | |
"type(mnist_train)" | |
], | |
"execution_count": 63, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"tensorflow.python.data.ops.dataset_ops._OptionsDataset" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 63 | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "5uwwlSL1jYU8", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"take(https://www.tensorflow.org/api_docs/python/tf/data/Dataset)count)\n", | |
"\n", | |
"Creates a Dataset with at most count elements from this dataset." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "jJsuQWe9YxH5", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"mnist_example, = mnist_train.take(1)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "WWZ5rnnWYyTx", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
}, | |
"outputId": "25773f4a-6a23-4f93-e639-6a2fb4f90166" | |
}, | |
"source": [ | |
"type(mnist_example)" | |
], | |
"execution_count": 69, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"dict" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 69 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "TO9kVFRpftvU", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
}, | |
"outputId": "37ecb590-e3f7-4498-f579-cd7b8a89881a" | |
}, | |
"source": [ | |
"len(mnist_example[\"image\"])" | |
], | |
"execution_count": 70, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"28" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 70 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "lSjsvNora8Xk", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"image, label = mnist_example[\"image\"], mnist_example[\"label\"]" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "2QdTvuYIgFBK", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 34 | |
}, | |
"outputId": "aff9f60d-efc3-4123-943b-4bf2e2b8d7b6" | |
}, | |
"source": [ | |
"image.shape" | |
], | |
"execution_count": 72, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"TensorShape([28, 28, 1])" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 72 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "L2RsNA6NbcbD", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"import matplotlib.pyplot as plt\n", | |
"import numpy as np" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "uBFIfv7QlkMN", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"Pour afficher l'image, on la convertit avec numpy" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "yY5Txetbbh4M", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 286 | |
}, | |
"outputId": "a8f4e7ea-55d8-4463-dfa2-c07e7225ca4a" | |
}, | |
"source": [ | |
"plt.imshow(image.numpy()[:, :, 0].astype(np.float32), cmap=plt.get_cmap(\"gray\"))\n", | |
"print(\"Label: %d\" % label.numpy())" | |
], | |
"execution_count": 33, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Label: 1\n" | |
], | |
"name": "stdout" | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAADGhJREFUeJzt3W+IHPUdx/HPp6mCeEL8Q8/gn8YG\nrQZDNRyhqBSrNagoiU+CAUtKQ88HChWKVMyDClIQqZY+EiIGY7FGxYghlCYaaq1SxERMjEn1rCQk\nISb+gyiCqZdvH9xcOfV2dp3d2dnL9/2C5Xbnt/ubL0M++c3szM7PESEA+Xyn6QIANIPwA0kRfiAp\nwg8kRfiBpAg/kBThB5Ii/EBShB9I6rv9XJltLicEahYR7uR9XY38tq+1/bbtd23f1U1fAPrLVa/t\ntz1L0juSrpG0X9JrkpZHxK6SzzDyAzXrx8i/SNK7EfFeRByVtE7Ski76A9BH3YT/LEn7przeXyz7\nCtujtrfa3trFugD0WO1f+EXEakmrJXb7gUHSzch/QNI5U16fXSwDMAN0E/7XJJ1v+zz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WZLekXSNpP2SXpO0PCJ29bWQFmzvkTQSEY2fE7b9E0mf\nSXpscjYk2/dL+jgi7iv+4zw1In47ILXdo285c3NNtbWaWfoXanDb9XLG615oYuRfJOndiHgvIo5K\nWidpSQN1DLyIeEnSx19bvETS2uL5Wk384+m7FrUNhIg4GBGvF88/lTQ5s3Sj266krkY0Ef6zJO2b\n8nq/BmvK75C02fY226NNFzON4SkzI70vabjJYqbRdubmfvrazNIDs+2qzHjda3zh901XRMRCSddJ\nuq3YvR1IMXHMNkinax6SNE8T07gdlPRAk8UUM0s/I+mOiDgyta3JbTdNXY1stybCf0DSOVNen10s\nGwgRcaD4e1jSs5o4TBkkhyYnSS3+Hm64nv+LiEMRMR4RxyQ9rAa3XTGz9DOSHo+I9cXixrfddHU1\ntd2aCP9rks63fZ7tEyXdLGlDA3V8g+2Tiy9iZPtkSYs1eLMPb5C0oni+QtJzDdbyFYMyc3OrmaXV\n8LYbuBmvI6LvD0nXa+Ib//9IWtVEDS3q+oGk7cXjraZrk/SEJnYD/6uJ70ZWSjpd0hZJY5JekHTa\nANX2Z03M5rxDE0Gb01BtV2hil36HpDeKx/VNb7uSuhrZblzhByTFF35AUoQfSIrwA0kRfiApwg8k\nRfiBpAg/kBThB5L6H0cU9DTfPY2mAAAAAElFTkSuQmCC\n", | |
"text/plain": [ | |
"<Figure size 432x288 with 1 Axes>" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "boDSmVsMbk1L", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"mnist_train = mnist_train.repeat(5).batch(32)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "TXONi9HkqmnT", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"dataset = tfds.load(name=\"mnist\", batch_size=32, as_supervised=True)\n", | |
"mnist_train = dataset[\"train\"].repeat().prefetch(1)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "bTH3ILb9rYOc", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "dyl044KBrar2", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment