{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# AI 5 Assignment - Dog Breed Training and Evaluation\n\n# Name: Furqaan Thakur\n# Email: thakurfurqaan@gmail.com","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from os.path import join\n\nimage_dir = '../input/dog-breed-identification/train/'\nimg_paths = [join(image_dir, filename) for filename in \n                           ['0c8fe33bd89646b678f6b2891df8a1c6.jpg',\n                            '0c3b282ecbed1ca9eb17de4cb1b6e326.jpg',\n                            '04fb4d719e9fe2b6ffe32d9ae7be8a22.jpg',\n                            '0e79be614f12deb4f7cae18614b7391b.jpg']]\n\nimport numpy as np\nimport tensorflow as tf\nfrom tensorflow.keras.applications.resnet50 import preprocess_input\nfrom tensorflow.keras.preprocessing.image import load_img, img_to_array\n\nimage_size = 224\n\ndef read_and_prep_images(img_paths, img_height=image_size, img_width=image_size):\n    imgs = [load_img(img_path, target_size=(img_height, img_width)) for img_path in img_paths]\n    img_array = np.array([img_to_array(img) for img in imgs])\n    output = preprocess_input(img_array)\n    return(output)\n\nfrom tensorflow.keras.applications import ResNet50\n\nmy_model = ResNet50(weights='../input/resnet50/resnet50_weights_tf_dim_ordering_tf_kernels.h5')\ntest_data = read_and_prep_images(img_paths)\npreds = my_model.predict(test_data)\n\nfrom learntools.deep_learning.decode_predictions import decode_predictions\nfrom IPython.display import Image, display\n\nmost_likely_labels = decode_predictions(preds, top=3, class_list_path='../input/resnet50/imagenet_class_index.json')\n\nfor i, img_path in enumerate(img_paths):\n    display(Image(img_path))\n    print(most_likely_labels[i])","metadata":{"execution":{"iopub.status.busy":"2022-05-16T11:09:52.493411Z","iopub.execute_input":"2022-05-16T11:09:52.493752Z","iopub.status.idle":"2022-05-16T11:09:57.138069Z","shell.execute_reply.started":"2022-05-16T11:09:52.493718Z","shell.execute_reply":"2022-05-16T11:09:57.136725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Load the TensorBoard notebook extension\n%load_ext tensorboard\n\nimport tensorflow as tf\nimport datetime\n\nmnist = tf.keras.datasets.mnist\n\n(x_train, y_train),(x_test, y_test) = mnist.load_data()\nx_train, x_test = x_train / 255.0, x_test / 255.0\n\ndef create_model():\n  return tf.keras.models.Sequential([\n    tf.keras.layers.Flatten(input_shape=(28, 28)),\n    tf.keras.layers.Dense(512, activation='relu'),\n    tf.keras.layers.Dropout(0.2),\n    tf.keras.layers.Dense(10, activation='softmax')\n  ])\n\nmodel = create_model()\nmodel.compile(optimizer='adam',\n              loss='sparse_categorical_crossentropy',\n              metrics=['accuracy'])\n\nlog_dir = \"logs/fit/\" + datetime.datetime.now().strftime(\"%Y%m%d-%H%M%S\")\ntensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)\n\nmodel.fit(x=x_train, \n          y=y_train, \n          epochs=5, \n          validation_data=(x_test, y_test), \n          callbacks=[tensorboard_callback])\n\n%tensorboard --logdir logs/fit","metadata":{"execution":{"iopub.status.busy":"2022-05-17T09:58:58.796764Z","iopub.execute_input":"2022-05-17T09:58:58.797123Z","iopub.status.idle":"2022-05-17T09:59:41.726364Z","shell.execute_reply.started":"2022-05-17T09:58:58.797029Z","shell.execute_reply":"2022-05-17T09:59:41.725541Z"},"trusted":true},"execution_count":null,"outputs":[]}]}