Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [],
- "source": [
- "import tensorflow as tf"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "1.8.0\n"
- ]
- }
- ],
- "source": [
- "print(tf.__version__)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 19,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Epoch 1/5\n",
- "60000/60000 [==============================] - 16s 263us/step - loss: 14.5055\n",
- "Epoch 2/5\n",
- "60000/60000 [==============================] - 14s 241us/step - loss: 14.5063\n",
- "Epoch 3/5\n",
- "60000/60000 [==============================] - 15s 253us/step - loss: 14.5063\n",
- "Epoch 4/5\n",
- "60000/60000 [==============================] - 14s 237us/step - loss: 14.5063\n",
- "Epoch 5/5\n",
- "60000/60000 [==============================] - 14s 226us/step - loss: 14.5063\n"
- ]
- },
- {
- "data": {
- "text/plain": [
- "<tensorflow.python.keras._impl.keras.callbacks.History at 0x7f2ca0628cf8>"
- ]
- },
- "execution_count": 19,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "class myCallback(tf.keras.callbacks.Callback):\n",
- " def on_epoch_end(self, epoch, logs={}):\n",
- " if(logs.get('loss')<0.4):\n",
- " print(\"\\n Reached 60% accuracy so no cancelling traning!\")\n",
- " self.model.stop_training= True\n",
- " \n",
- "callbacks = myCallback() \n",
- "mnist=tf.keras.datasets.fashion_mnist\n",
- "(training_images, training_labels),(test_images, test_labels)= mnist.load_data()\n",
- "test_images=test_images/255.0\n",
- "model=tf.keras.models.Sequential([\n",
- " tf.keras.layers.Flatten(input_shape=(28,28)),\n",
- " tf.keras.layers.Dense(512, activation=tf.nn.relu),\n",
- " tf.keras.layers.Dense(10, activation=tf.nn.softmax)\n",
- "])\n",
- "model.compile(optimizer='adam', loss='sparse_categorical_crossentropy')\n",
- "model.fit(training_images, training_labels, epochs=5, callbacks=[callbacks])"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.6.8"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement