{"cells":[{"metadata":{},"cell_type":"markdown","source":"Hi, I'm Kaggler Kai. I adopted a dog recently from a shelter, and I am curious what kind of dog he might be. I found a great model for image classification and want to try it out. Can you help me?\n\n**Step One** Copy and Edit this notebook, to make your own version you can edit and run. Go ahead and look for that button and click it. \n\nGreat! You should now have your own editable version of this notebook. \n\n**Step Two** Now, run the code cell below to load the model and get access to all of the images from the shelter's website.\n\n(To run a block of code, click on it, then click the play button next to it.)"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import os\nimport pandas as pd\nimport numpy as np\nfrom os.path import join\nfrom tensorflow.keras.applications.resnet50 import preprocess_input\nfrom tensorflow.keras.preprocessing.image import load_img, img_to_array\nfrom tensorflow.keras.applications import ResNet50\nfrom IPython.display import Image, display\nfrom learntools.deep_learning.decode_predictions import decode_predictions\n\n# Get list of all images in the train/ folder\nimage_dir = '../input/dog-breed-identification/train/'\nimg_paths = [join(image_dir, filename) for filename in os.listdir(\"../input/dog-breed-identification/train\")]\n\n# Prepare image for machine learning model\ndef read_and_prep_image(img_path, img_height=224, img_width=224):\n    img = load_img(img_path, target_size=(img_height, img_width)) \n    output = preprocess_input(np.expand_dims(img_to_array(img), axis=0))\n    return output\n\n# Import a pre-trained model\nmodel = ResNet50(weights='../input/resnet50/resnet50_weights_tf_dim_ordering_tf_kernels.h5')\n\n# What does the model think the image contains?\ndef show_predictions(index):\n    preds = model.predict(read_and_prep_image(img_paths[index]))\n    most_likely_labels = decode_predictions(preds, top=3)[0]\n    df = pd.DataFrame([x[1:] for x in most_likely_labels], columns=[\"label\", \"probability\"])\n    display(df.head())\n    display(Image(img_paths[index])) \n    \nprint(\"Success! Model loaded.\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Alright! Now we're ready to feed the model an image. My dog's photo is number 112. Could you pass that number to the model in the next code cell and we'll see what breed he looks like?"},{"metadata":{"trusted":true},"cell_type":"code","source":"show_predictions(1)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**What do you think? Is the model correct?**\n\nAnd congratulations! You’ve copied, edited and run your first Kaggle notebook.\n\n**What do do next:**\nExplore the [dataset](http://) behind this demo\nLearn more about image classification in [Kaggle's Deep Learning micro-course](https://www.kaggle.com/learn/deep-learning)\nTry your hand at a [Kaggle competition](https://www.kaggle.com/competitions) that uses image classification"}],"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":4,"nbformat_minor":1}