Machine Learning Kurs im Rahmen der Studierendentage im SS 2023
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
2.8 KiB

2 years ago
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "id": "8f9f0e7b",
  6. "metadata": {},
  7. "source": [
  8. "Display fashion_mnist dataset of clothes from Zalando"
  9. ]
  10. },
  11. {
  12. "cell_type": "code",
  13. "execution_count": null,
  14. "id": "cc829d9a",
  15. "metadata": {},
  16. "outputs": [],
  17. "source": [
  18. "import tensorflow as tf\n",
  19. "from tensorflow import keras\n",
  20. "import matplotlib.pyplot as plt\n",
  21. "import numpy as np"
  22. ]
  23. },
  24. {
  25. "cell_type": "code",
  26. "execution_count": null,
  27. "id": "63348efe",
  28. "metadata": {},
  29. "outputs": [],
  30. "source": [
  31. "# Load the MNIST Fashion dataset\n",
  32. "(x_train, y_train), (x_test, y_test) = keras.datasets.fashion_mnist.load_data()\n",
  33. "# Set the class names\n",
  34. "class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', \n",
  35. " 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']\n"
  36. ]
  37. },
  38. {
  39. "cell_type": "code",
  40. "execution_count": null,
  41. "id": "a6c86027",
  42. "metadata": {},
  43. "outputs": [],
  44. "source": [
  45. "# print the shape of the numpy arrays\n",
  46. "print ('Print shape of pixel data')\n",
  47. "print(x_train.shape)\n",
  48. "print ('Print shape of labels')\n",
  49. "print(y_train.shape)"
  50. ]
  51. },
  52. {
  53. "cell_type": "code",
  54. "execution_count": null,
  55. "id": "cc58b142",
  56. "metadata": {},
  57. "outputs": [],
  58. "source": [
  59. "# Normalize pixel values to between 0 and 1\n",
  60. "x_train = x_train.astype(\"float32\") / 255.0\n",
  61. "x_test = x_test.astype(\"float32\") / 255.0"
  62. ]
  63. },
  64. {
  65. "cell_type": "code",
  66. "execution_count": null,
  67. "id": "c7976111",
  68. "metadata": {},
  69. "outputs": [],
  70. "source": [
  71. "# choose an image num to print\n",
  72. "num = 20\n",
  73. "image = x_train[num]\n",
  74. "label = y_train[num]\n",
  75. "\n",
  76. "print ('Print normailzed pixel data of image ',num, ' :')\n",
  77. "print(x_train[num])\n",
  78. "print ('Print label of image ',num , ' :' )\n",
  79. "print(y_train[num])\n"
  80. ]
  81. },
  82. {
  83. "cell_type": "code",
  84. "execution_count": null,
  85. "id": "64a46625",
  86. "metadata": {},
  87. "outputs": [],
  88. "source": [
  89. "plt.figure(figsize=(10,10))\n",
  90. "for i in range(25):\n",
  91. " plt.subplot(5,5,i+1)\n",
  92. " plt.xticks([])\n",
  93. " plt.yticks([])\n",
  94. " plt.grid(False)\n",
  95. " plt.imshow(x_train[i], cmap=plt.cm.binary)\n",
  96. " plt.xlabel(class_names[y_train[i]])\n",
  97. "plt.show()"
  98. ]
  99. }
  100. ],
  101. "metadata": {
  102. "kernelspec": {
  103. "display_name": "Python 3 (ipykernel)",
  104. "language": "python",
  105. "name": "python3"
  106. },
  107. "language_info": {
  108. "codemirror_mode": {
  109. "name": "ipython",
  110. "version": 3
  111. },
  112. "file_extension": ".py",
  113. "mimetype": "text/x-python",
  114. "name": "python",
  115. "nbconvert_exporter": "python",
  116. "pygments_lexer": "ipython3",
  117. "version": "3.8.16"
  118. }
  119. },
  120. "nbformat": 4,
  121. "nbformat_minor": 5
  122. }