Advertisement
Guest User

Untitled

a guest
May 21st, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 11,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. "import tensorflow as tf"
  10. ]
  11. },
  12. {
  13. "cell_type": "code",
  14. "execution_count": 12,
  15. "metadata": {},
  16. "outputs": [
  17. {
  18. "name": "stdout",
  19. "output_type": "stream",
  20. "text": [
  21. "1.8.0\n"
  22. ]
  23. }
  24. ],
  25. "source": [
  26. "print(tf.__version__)"
  27. ]
  28. },
  29. {
  30. "cell_type": "code",
  31. "execution_count": 19,
  32. "metadata": {},
  33. "outputs": [
  34. {
  35. "name": "stdout",
  36. "output_type": "stream",
  37. "text": [
  38. "Epoch 1/5\n",
  39. "60000/60000 [==============================] - 16s 263us/step - loss: 14.5055\n",
  40. "Epoch 2/5\n",
  41. "60000/60000 [==============================] - 14s 241us/step - loss: 14.5063\n",
  42. "Epoch 3/5\n",
  43. "60000/60000 [==============================] - 15s 253us/step - loss: 14.5063\n",
  44. "Epoch 4/5\n",
  45. "60000/60000 [==============================] - 14s 237us/step - loss: 14.5063\n",
  46. "Epoch 5/5\n",
  47. "60000/60000 [==============================] - 14s 226us/step - loss: 14.5063\n"
  48. ]
  49. },
  50. {
  51. "data": {
  52. "text/plain": [
  53. "<tensorflow.python.keras._impl.keras.callbacks.History at 0x7f2ca0628cf8>"
  54. ]
  55. },
  56. "execution_count": 19,
  57. "metadata": {},
  58. "output_type": "execute_result"
  59. }
  60. ],
  61. "source": [
  62. "class myCallback(tf.keras.callbacks.Callback):\n",
  63. " def on_epoch_end(self, epoch, logs={}):\n",
  64. " if(logs.get('loss')<0.4):\n",
  65. " print(\"\\n Reached 60% accuracy so no cancelling traning!\")\n",
  66. " self.model.stop_training= True\n",
  67. " \n",
  68. "callbacks = myCallback() \n",
  69. "mnist=tf.keras.datasets.fashion_mnist\n",
  70. "(training_images, training_labels),(test_images, test_labels)= mnist.load_data()\n",
  71. "test_images=test_images/255.0\n",
  72. "model=tf.keras.models.Sequential([\n",
  73. " tf.keras.layers.Flatten(input_shape=(28,28)),\n",
  74. " tf.keras.layers.Dense(512, activation=tf.nn.relu),\n",
  75. " tf.keras.layers.Dense(10, activation=tf.nn.softmax)\n",
  76. "])\n",
  77. "model.compile(optimizer='adam', loss='sparse_categorical_crossentropy')\n",
  78. "model.fit(training_images, training_labels, epochs=5, callbacks=[callbacks])"
  79. ]
  80. },
  81. {
  82. "cell_type": "code",
  83. "execution_count": null,
  84. "metadata": {},
  85. "outputs": [],
  86. "source": []
  87. }
  88. ],
  89. "metadata": {
  90. "kernelspec": {
  91. "display_name": "Python 3",
  92. "language": "python",
  93. "name": "python3"
  94. },
  95. "language_info": {
  96. "codemirror_mode": {
  97. "name": "ipython",
  98. "version": 3
  99. },
  100. "file_extension": ".py",
  101. "mimetype": "text/x-python",
  102. "name": "python",
  103. "nbconvert_exporter": "python",
  104. "pygments_lexer": "ipython3",
  105. "version": "3.6.8"
  106. }
  107. },
  108. "nbformat": 4,
  109. "nbformat_minor": 2
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement